librespot icon indicating copy to clipboard operation
librespot copied to clipboard

Can't play songs from Android app

Open Johannesd3 opened this issue 6 years ago • 8 comments

Playing a song with librespot from my Android Spotify app doesn't work. After playing a song in the app and switching to the librespot client, the Android app and the web client still show the song as playing, but librespot produces no sound. When I press pause (or do any other action like increasing volume) on my phone, the playback appears as stopped. In the Web Client everything works fine.

Here's the log of librespot. The command=stop in the second last line seems quite suspicious to me and might be the cause:

[2020-06-18T14:43:47Z DEBUG librespot_connect::spirc] kMessageTypeNotify "My Android phone" 02aebb2e36129b4fb125042cb4746ee29f3085b2 1206045774 1592491428201
[2020-06-18T14:43:52Z DEBUG librespot_connect::spirc] kMessageTypeNotify "My Android phone" 02aebb2e36129b4fb125042cb4746ee29f3085b2 1206051183 1592491433610
[2020-06-18T14:43:57Z DEBUG librespot_connect::spirc] kMessageTypeNotify "My Android phone" 02aebb2e36129b4fb125042cb4746ee29f3085b2 1206055368 1592491437795
[2020-06-18T14:44:00Z DEBUG librespot_connect::spirc] kMessageTypeNotify "My Android phone" 02aebb2e36129b4fb125042cb4746ee29f3085b2 1206058649 1592491441076
[2020-06-18T14:44:05Z DEBUG librespot_connect::spirc] kMessageTypeLoad "My Android phone" 02aebb2e36129b4fb125042cb4746ee29f3085b2 1206063633 1592491441076
[2020-06-18T14:44:05Z DEBUG librespot_connect::spirc] State: context_uri: "spotify:album:7fYlJ1HNLfs6JIvJCJ2rqq" index: 0 position_ms: 86485 status: kPlayStatusPlay position_measured_at: 1592491446088 context_description: "" shuffle: false repeat: false playing_from_fallback: true row: 0 playing_track_index: 0 track {gid: "|A!\026\321\222O\252\222\245\240\371\211\327\343\020"} track {gid: "n\227`\315x\352K\335\216\016\000\302L_1$"} track {gid: "\337UY\305Q\306L\236\252\367\022\347\353\244T\360"} track {gid: "\373\210rq\213\271@G\274\340\276\216\270\005\333\311"} track {gid: "\205K\253\235#XK\305\211\205\223H\221\241e\243"} track {gid: "\020\225\2458\001\264BC\250\203\315g\247{\177\002"} track {gid: "\316\361yC\343\366H\335\277\177\007\241\375\327[u"} track {gid: ":U+J\326\004I\320\250H\361O\310\343\310\257"} track {gid: "\000\231)\n\3232BB\275\356 7\271Ooj"} track {gid: "\017\245ir\370\315C\317\245\315\371~\374,#\250"} track {gid: "\361\031\223\006x\302J\200\230tc\231\266b;\320"} track {gid: "Z\227w@\031:L$\224\025\\\3749]\033s"} track {gid: "\033\303?x\232LC\265\217j\213\231\236\367\207\370"}
[2020-06-18T14:44:05Z DEBUG librespot_connect::spirc] Frame has 13 tracks
[2020-06-18T14:44:05Z DEBUG librespot_connect::spirc] Loading context: <spotify:album:7fYlJ1HNLfs6JIvJCJ2rqq> index: [0] of 13
[2020-06-18T14:44:05Z DEBUG librespot_playback::player] command=Load(SpotifyId { id: 165162441900530074290656498603318043408, audio_type: Track }, true, 86485)
[2020-06-18T14:44:05Z DEBUG librespot_connect::spirc] kMessageTypeNotify "My Android phone" 02aebb2e36129b4fb125042cb4746ee29f3085b2 1206063683 1592491446110
[2020-06-18T14:44:05Z INFO  librespot_playback::player] Loading <The Color Purple: Main Title> with Spotify URI <spotify:track:3MsOo0SIZYib9mfalJvKSc>
[2020-06-18T14:44:05Z DEBUG librespot_core::audio_key] new AudioKeyManager
[2020-06-18T14:44:05Z DEBUG librespot_audio::fetch] Downloading file b44263f5a17f01e81fe73c8651e73d78590286cc
[2020-06-18T14:44:05Z DEBUG librespot_core::channel] new ChannelManager
[2020-06-18T14:44:05Z WARN  librespot_playback::player] Reducing normalisation factor to prevent clipping. Please add negative pregain to avoid.
[2020-06-18T14:44:05Z DEBUG librespot_playback::player] Normalisation Data: NormalisationData { track_gain_db: 1.9099998, track_peak: 0.96435523, album_gain_db: 2.579998, album_peak: 1.0188758 }
[2020-06-18T14:44:05Z DEBUG librespot_playback::player] Applied normalisation factor: 1.0369623
[2020-06-18T14:44:05Z DEBUG librespot_connect::spirc] kMessageTypeNotify "My Android phone" 02aebb2e36129b4fb125042cb4746ee29f3085b2 1206063914 1592491446341
[2020-06-18T14:44:06Z INFO  librespot_playback::player] <The Color Purple: Main Title> loaded
[2020-06-18T14:44:06Z DEBUG librespot_playback::player] command=Stop
[2020-06-18T14:44:25Z DEBUG librespot_connect::spirc] kMessageTypePause "My Android phone" 02aebb2e36129b4fb125042cb4746ee29f3085b2 1206083669 1592491446341

Johannesd3 avatar Jun 18 '20 15:06 Johannesd3

Same here, except by skipping to next track I get sound from both phone and librespot at the same time. Web client seems to work for me as well.

malaakso avatar Jun 22 '20 12:06 malaakso

Same for me Was working with Android App v8.5.40.195, not working with App version v8.5.42.812 (same behavior as described above). Installed old version from here as temporary fix: https://spotify.de.uptodown.com/android/download/2168218

pejobo avatar Jun 28 '20 08:06 pejobo

I did a little further research and think I figured it out: When selecting librespot in the Android App, the app sends a command to librespot to load the track. However, shortly after this command, the app sends some kind of status update (kMessageTypeNotify), claiming still to be active. But when Librespot receives this status update it immediately stops playing, believing the Android app is currently playing. This happens in spirc.rs, line 793.

I also found a possible fix/workaround. The device state contains the information of when it became active. One could compare them in line 793 to check which client became most recently active: if self.device.get_is_active() && frame.get_device_state().get_is_active() && self.device.get_became_active_at() <= frame.get_device_state().get_became_active_at() { At least for me it works. But since I do not know much about Spotify and this project, someone else should also take a look.

Johannesd3 avatar Jul 03 '20 00:07 Johannesd3

Same here as well

jaisor avatar Jul 12 '20 23:07 jaisor

https://github.com/librespot-org/librespot/issues/497#issuecomment-653270238 fix solves the problem for me

Mitschmaster avatar Jul 17 '20 15:07 Mitschmaster

Feel free to create a PR for the fix

sashahilton00 avatar Jul 22 '20 14:07 sashahilton00

Closed by #501

sashahilton00 avatar Jul 22 '20 14:07 sashahilton00

Thanks everyone for fixing this, finally the Android app just works!

ah- avatar Aug 31 '20 21:08 ah-