spotify / android-sdk

Spotify SDK for Android
https://developer.spotify.com/documentation/android/
Apache License 2.0
462 stars 119 forks source link

Same Player State is emitted multiple times on subscription #237

Open sinan-kalkan opened 4 years ago

sinan-kalkan commented 4 years ago

Player state subscription always emits same events multiple times to my app. Please see the logs:

2020-04-19 22:23:30.361 14515-14515/com.app.sini.sinify D/SPOTIFY_APP_REMOTE: Message from Spotify: [36,10,43,{},[],{"context_uri":"spotify:playlist:37i9dQZF1DX2sUQwD7tbmL","track":{"artist":{"name":"Still Woozy","type":"artist","uri":"spotify:artist:4iMO20EPodreIaEl8qW66y"},"artists":[{"name":"Still Woozy","type":"artist","uri":"spotify:artist:4iMO20EPodreIaEl8qW66y"}],"album":{"name":"Goodie Bag","type":"album","uri":"spotify:album:31u58iuxrUOJeKJj4SKqOl"},"saved":false,"duration_ms":146390,"name":"Goodie Bag","uri":"spotify:track:297rZsBEjFw9d0Gl3iBLnd","image_id":"spotify:image:ab67616d0000b2735ddbd61ea4a6dab213cc97af","is_episode":false,"is_podcast":false},"is_paused":false,"playback_speed":1.0,"playback_position":53,"playback_options":{"shuffle":false,"repeat":0},"playback_restrictions":{"can_skip_next":true,"can_skip_prev":true,"can_repeat_track":true,"can_repeat_context":true,"can_toggle_shuffle":true,"can_seek":true}}] 2020-04-19 22:23:30.362 14515-14515/com.app.sini.sinify D/SPOTIFY_APP_REMOTE: Message from Spotify: [36,10,44,{},[],{"context_uri":"spotify:playlist:37i9dQZF1DX2sUQwD7tbmL","track":{"artist":{"name":"Still Woozy","type":"artist","uri":"spotify:artist:4iMO20EPodreIaEl8qW66y"},"artists":[{"name":"Still Woozy","type":"artist","uri":"spotify:artist:4iMO20EPodreIaEl8qW66y"}],"album":{"name":"Goodie Bag","type":"album","uri":"spotify:album:31u58iuxrUOJeKJj4SKqOl"},"saved":false,"duration_ms":146390,"name":"Goodie Bag","uri":"spotify:track:297rZsBEjFw9d0Gl3iBLnd","image_id":"spotify:image:ab67616d0000b2735ddbd61ea4a6dab213cc97af","is_episode":false,"is_podcast":false},"is_paused":false,"playback_speed":1.0,"playback_position":53,"playback_options":{"shuffle":false,"repeat":0},"playback_restrictions":{"can_skip_next":true,"can_skip_prev":true,"can_repeat_track":true,"can_repeat_context":true,"can_toggle_shuffle":true,"can_seek":true}}] 2020-04-19 22:23:30.371 14515-14515/com.app.sini.sinify D/SPOTIFY_APP_REMOTE: Message from Spotify: [36,10,45,{},[],{"context_uri":"spotify:playlist:37i9dQZF1DX2sUQwD7tbmL","track":{"artist":{"name":"Still Woozy","type":"artist","uri":"spotify:artist:4iMO20EPodreIaEl8qW66y"},"artists":[{"name":"Still Woozy","type":"artist","uri":"spotify:artist:4iMO20EPodreIaEl8qW66y"}],"album":{"name":"Goodie Bag","type":"album","uri":"spotify:album:31u58iuxrUOJeKJj4SKqOl"},"saved":false,"duration_ms":146390,"name":"Goodie Bag","uri":"spotify:track:297rZsBEjFw9d0Gl3iBLnd","image_id":"spotify:image:ab67616d0000b2735ddbd61ea4a6dab213cc97af","is_episode":false,"is_podcast":false},"is_paused":false,"playback_speed":1.0,"playback_position":71,"playback_options":{"shuffle":false,"repeat":0},"playback_restrictions":{"can_skip_next":true,"can_skip_prev":true,"can_repeat_track":true,"can_repeat_context":true,"can_toggle_shuffle":true,"can_seek":true}}] 2020-04-19 22:23:30.459 14515-14515/com.app.sini.sinify D/SPOTIFY_APP_REMOTE: Message from Spotify: [36,10,46,{},[],{"context_uri":"spotify:playlist:37i9dQZF1DX2sUQwD7tbmL","track":{"artist":{"name":"Still Woozy","type":"artist","uri":"spotify:artist:4iMO20EPodreIaEl8qW66y"},"artists":[{"name":"Still Woozy","type":"artist","uri":"spotify:artist:4iMO20EPodreIaEl8qW66y"}],"album":{"name":"Goodie Bag","type":"album","uri":"spotify:album:31u58iuxrUOJeKJj4SKqOl"},"saved":false,"duration_ms":146390,"name":"Goodie Bag","uri":"spotify:track:297rZsBEjFw9d0Gl3iBLnd","image_id":"spotify:image:ab67616d0000b2735ddbd61ea4a6dab213cc97af","is_episode":false,"is_podcast":false},"is_paused":false,"playback_speed":1.0,"playback_position":159,"playback_options":{"shuffle":false,"repeat":0},"playback_restrictions":{"can_skip_next":true,"can_skip_prev":true,"can_repeat_track":true,"can_repeat_context":true,"can_toggle_shuffle":true,"can_seek":true}}]

Issue found on 04/19/20.

SDK Version: 0.7.0

OS Version: 10

Scope(s): app-remote-control

Steps to reproduce:

  1. Subscribe to player state withsubscribeToPlayerState()
  2. Open Spotify app and click next track

Expected behaviour:

Player state is emitted once on next clicked in Spotify app

Actual behaviour:

Player state event is emitted multiple times for the same player state / track (pls see logs)

aleksandar-vuckovic commented 4 years ago

I can confirm I also have this issue. More specifically, when changing songs, a new PlayerState is emitted exactly 4 times, every time in my case. As the behaviour is this preditable, one can work around it with a simple counter in combination with Thread.sleep(long). When pausing and resuming songs, the PlayerState is emitted once (as expected).

EDIT: I was wrong, as I assumed that the events are processed in parallel, although they are in fact processed consecutively. This does make it harder to find a workaround, I haven't been able to find one that is adequate for my app.

uptotec commented 4 years ago

I have the same problem any solutions ?