[GH-ISSUE #15] librespot-android crashes if i stop playback from spotify app by changing device #11

Closed
opened 2026-02-28 14:24:02 +03:00 by kerem · 1 comment
Owner

Originally created by @vhaudiquet on GitHub (Jan 6, 2022).
Original GitHub issue: https://github.com/devgianlu/librespot-android/issues/15

If i start playing a song on librespot-android, and then go to my spotify app to change the source of the song, librespot-android crashes :

2022-01-06 23:23:07.091 20210-20258/xyz.gianlu.librespot.android E/AndroidRuntime: FATAL EXCEPTION: player-audio-sink
    Process: xyz.gianlu.librespot.android, PID: 20210
    java.lang.IllegalStateException: Unable to retrieve AudioTrack pointer for stop()
        at android.media.AudioTrack.native_stop(Native Method)
        at android.media.AudioTrack.stop(AudioTrack.java:2881)
        at xyz.gianlu.librespot.android.sink.AndroidSinkOutput.stop(AndroidSinkOutput.java:99)
        at xyz.gianlu.librespot.player.mixing.AudioSink.run(AudioSink.java:160)
        at java.lang.Thread.run(Thread.java:920)

This is caused by the line :
if (track != null) track.stop(); (AndroidSinkOutput.java:99)

I tried to fix the issue, and i have a bizarre behavior ; this code :

if (track != null)
{
    System.out.println("STATE:" + track.getPlayState());
    track.stop();
}

does not crash the player. Maybe i was lucky, or maybe getPlayState() actualizes something inside the AudioTrack ?

Anyway, the state here prints '1' in this case, i.e. AudioTrack.PLAYSTATE_STOPPED ; so a correct fix should be :

if (track != null && track.getPlayState() != AudioTrack.PLAYSTATE_STOPPED)
    track.stop();

I'm not sure if it is the "good way" though...

Originally created by @vhaudiquet on GitHub (Jan 6, 2022). Original GitHub issue: https://github.com/devgianlu/librespot-android/issues/15 If i start playing a song on librespot-android, and then go to my spotify app to change the source of the song, librespot-android crashes : ``` 2022-01-06 23:23:07.091 20210-20258/xyz.gianlu.librespot.android E/AndroidRuntime: FATAL EXCEPTION: player-audio-sink Process: xyz.gianlu.librespot.android, PID: 20210 java.lang.IllegalStateException: Unable to retrieve AudioTrack pointer for stop() at android.media.AudioTrack.native_stop(Native Method) at android.media.AudioTrack.stop(AudioTrack.java:2881) at xyz.gianlu.librespot.android.sink.AndroidSinkOutput.stop(AndroidSinkOutput.java:99) at xyz.gianlu.librespot.player.mixing.AudioSink.run(AudioSink.java:160) at java.lang.Thread.run(Thread.java:920) ``` This is caused by the line : ` if (track != null) track.stop();` [(AndroidSinkOutput.java:99)](https://github.com/devgianlu/librespot-android/blob/master/librespot-android-sink/src/main/java/xyz/gianlu/librespot/android/sink/AndroidSinkOutput.java#L99) I tried to fix the issue, and i have a bizarre behavior ; this code : ``` if (track != null) { System.out.println("STATE:" + track.getPlayState()); track.stop(); } ``` does not crash the player. Maybe i was lucky, or maybe getPlayState() actualizes something inside the AudioTrack ? Anyway, the state here prints '1' in this case, i.e. `AudioTrack.PLAYSTATE_STOPPED` ; so a correct fix should be : ``` if (track != null && track.getPlayState() != AudioTrack.PLAYSTATE_STOPPED) track.stop(); ``` I'm not sure if it is the "good way" though...
kerem closed this issue 2026-02-28 14:24:02 +03:00
Author
Owner

@mitschwimmer commented on GitHub (Jan 8, 2022):

Thanks for reporting @vhaudiquet. I will look into this as soon as I find the time.

<!-- gh-comment-id:1007902581 --> @mitschwimmer commented on GitHub (Jan 8, 2022): Thanks for reporting @vhaudiquet. I will look into this as soon as I find the time.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot-android#11
No description provided.