KRTirtho / spotube

🎧 Open source Spotify client that doesn't require Premium nor uses Electron! Available for both desktop & mobile!
https://spotube.krtirtho.dev/
Other
30.65k stars 1.27k forks source link

Music periodically stutters #1382

Open doubleddav opened 7 months ago

doubleddav commented 7 months ago

Is there an existing issue for this?

Current Behavior

Any and every song plays an intermittent micro "skip" every few seconds. It sounds like when a CD would skip back in the olden days.

It does this on the latest stable and nightly versions. I don't have this issue on version 3.4.1 build 28, which is what I use now to avoid it.

Expected Behavior

Songs play without interruption.

Steps to reproduce

  1. Open the app
  2. Play any song
  3. Listen for a few seconds

Operating System

Android 13

Spotube version

< v3.4.1 build 28

Installation source

GitHub Releases (Binary), GitHub Actions (Nightly Binary), F-Droid (Android)

Additional information

No response

Self grab

doubleddav commented 7 months ago

Just tried latest nightly build, version 3.5.0 nightly, build 235. Unfortunately seeing the same stutter issue.

KRTirtho commented 7 months ago

Are you talking about the Sponsor Block skips? In that case, go to "Settings" > "Playback" section > "Skip Non-Music segments" and turn that off. But you'll have to listen to non-music parts too

doubleddav commented 7 months ago

I don't think it's that, its every song from start to finish has a kind of stutter every few seconds. Unless it's happening as a result of this?

KRTirtho commented 7 months ago

I haven't found anything like that. @olivier2 isn't this the issue your fixed already with a PR. Is it the same problem?

Btw @doubleddav you can now select audio output device from Spotube's Devices page. Try changing the devices and see which one it happens with. There should be 3 options (Auto, opensles and audiotrack)

doubleddav commented 6 months ago

@KRTirtho I just tried all 3 options you referred to in version 3.6.0 build 30. Unfortunately same behaviour

KRTirtho commented 6 months ago

If it's possible please, submit a short screen-recording (with audio). This will help understand the issue. Thanks

doubleddav commented 6 months ago

https://github.com/KRTirtho/spotube/assets/26053051/7a9bcd7f-d962-49a5-95a7-a865b0ad811d

Here you go, using latest nightly,

Thanks

olivier2 commented 6 months ago

Hello, I looked into this, but couldn't find anything obvious. @doubleddav what device are you using? Maybe I'd have better luck testing on the same phone if I can find one.

The only other thing I see that might be worth investigating for performance is these log messages that are written multiple times per second:

logcat ``` 20:38:31.935 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:32.200 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=57251, buffered position=0, speed=1.0, updated=3184636214, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:32.203 V trySendMediaUpdate(): Metadata has been updated for oss.krtirtho.spotube 20:38:32.422 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=57501, buffered position=0, speed=1.0, updated=3184636461, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:32.423 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:32.695 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=57751, buffered position=0, speed=1.0, updated=3184636714, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:32.696 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:32.729 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=57801, buffered position=0, speed=1.0, updated=3184636760, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:32.732 V trySendMediaUpdate(): Metadata has been updated for oss.krtirtho.spotube 20:38:32.939 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=58001, buffered position=0, speed=1.0, updated=3184636962, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:32.940 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:32.977 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=58051, buffered position=0, speed=1.0, updated=3184637008, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:32.977 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:33.184 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=58251, buffered position=0, speed=1.0, updated=3184637214, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:33.185 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:33.429 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=58501, buffered position=0, speed=1.0, updated=3184637464, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:33.431 V trySendMediaUpdate(): Metadata has been updated for oss.krtirtho.spotube 20:38:33.688 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=58751, buffered position=0, speed=1.0, updated=3184637714, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:33.689 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:33.934 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=59001, buffered position=0, speed=1.0, updated=3184637963, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:33.934 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:34.190 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=59251, buffered position=0, speed=1.0, updated=3184638214, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:34.195 V trySendMediaUpdate(): Metadata has been updated for oss.krtirtho.spotube 20:38:34.232 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=59301, buffered position=0, speed=1.0, updated=3184638263, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:34.233 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:34.429 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=59501, buffered position=0, speed=1.0, updated=3184638462, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:34.429 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:34.477 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=59551, buffered position=0, speed=1.0, updated=3184638508, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:34.478 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:34.678 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=59751, buffered position=0, speed=1.0, updated=3184638711, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:34.678 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:34.927 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=60001, buffered position=0, speed=1.0, updated=3184638962, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:34.930 V trySendMediaUpdate(): Metadata has been updated for oss.krtirtho.spotube 20:38:35.189 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=60251, buffered position=0, speed=1.0, updated=3184639213, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:35.189 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:35.431 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=60501, buffered position=0, speed=1.0, updated=3184639466, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:35.431 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:35.690 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=60751, buffered position=0, speed=1.0, updated=3184639714, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:35.697 V trySendMediaUpdate(): Metadata has been updated for oss.krtirtho.spotube 20:38:35.727 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=60801, buffered position=0, speed=1.0, updated=3184639759, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:35.728 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:35.954 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=61001, buffered position=0, speed=1.0, updated=3184639965, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:35.955 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:35.999 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=61051, buffered position=0, speed=1.0, updated=3184640011, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:36.000 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:36.199 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=61251, buffered position=0, speed=1.0, updated=3184640213, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:36.200 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:36.430 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=61501, buffered position=0, speed=1.0, updated=3184640458, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:36.432 V trySendMediaUpdate(): Metadata has been updated for oss.krtirtho.spotube 20:38:36.684 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=61751, buffered position=0, speed=1.0, updated=3184640714, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} 20:38:36.685 W onPlaybackStateChanged(): oss.krtirtho.spotube tried to update with no new data 20:38:36.935 V onPlaybackStateChanged(): oss.krtirtho.spotube : PlaybackState {state=PLAYING(3), position=62001, buffered position=0, speed=1.0, updated=3184640966, actions=3670015, custom actions=[Action:mName='Stop, mIcon=2131165279, mExtras=null], active item id=-1, error=null} ```

This can be fixed by removing the following lines. I don't know if it affects other platforms/players, but the audio_service documentation mentions the position should not be broadcasted continuously (search for 'updatePosition' on this page)

--- a/lib/services/audio_services/mobile_audio_service.dart
+++ b/lib/services/audio_services/mobile_audio_service.dart
@@ -58,9 +58,6 @@ class MobileAudioService extends BaseAudioHandler {
       playbackState.add(await _transformEvent());
     });

-    audioPlayer.positionStream.listen((pos) async {
-      playbackState.add(await _transformEvent());
-    });
     audioPlayer.bufferedPositionStream.listen((pos) async {
       playbackState.add(await _transformEvent());
     });

Again, it's a long shot as it doesn't appear to affect performance on my phone, but I don't see anything else beside specific conditions like network or cpu throttling.

KRTirtho commented 6 months ago
      // The current position as of this update. You should not broadcast
      // position changes continuously because listeners will be able to
      // project the current position after any elapsed time based on the
      // current speed and whether audio is playing and ready. Instead, only
      // broadcast position updates when they are different from expected (e.g.
      // buffering, or seeking).
      updatePosition: Duration(milliseconds: 54321),

Yeah, looks like we don't need to update the position every 500ms now. Thanks for letting me know

doubleddav commented 6 months ago

I have a Sony Xperia 10 III if that helps. Sorry I can't really read code, but it started after version v3.4.1, so I'm assuming something might have changed after that?

GStudiosX2 commented 6 months ago

I use a Moto G8 I do get stutters sometimes but it's rare I'm using Bluetooth to a device though so that might be why

jola5 commented 6 months ago

screen-20240422-200356.mp4

Here you go, using latest nightly,

Thanks

Exactly the same for me. I first experienced it a couple of weeks ago connected to the car via bluetooth. But the issue persists either via BT or directly on the phone's speakers - and other players don't have the issue.

Spottube version 3.6.0 (Build 30). Sony Xperia 10 IV XQ-CC54.

olivier2 commented 6 months ago

I tested on Galaxy S7 (released in 2016) and Galaxy A01 (budget phone released in 2020) without issues so I think we can rule out the hardware as the source.

So I started testing using Network Link Conditioner on macos. I kind of was able to reproduce the stuttering with a 2mbps downlink (DSL profile) and high audio quality (youtube source). Definitely something to investigate there.

@jola5 , @doubleddav, @GStudiosX2 are you on wifi or cell network? What's your bandwidth and latency (from fast.com ?). Are you using Low,Medium or High audio quality in Spotube's settings? When the audio is stuttering, is the "playback" position (green below) reaching the end of the "buffered" position (red below)?

Screenshot_20240503-111703_Spotube

jola5 commented 6 months ago

Downlink is around the same with my current provider (wifi via mobile access point):

Direct mobile connection on my phone is:

For the stutter there is no difference between wifi or cell. It's the same.

I also tested the three quality settings. Again stutter is the same. The buffer indicator fills for the whole song in the first couple of seconds. Thanks for looking into this. If there is anything else I can do to support in terms of testing or log files or anything let me know.

GStudiosX2 commented 6 months ago

I tested on Galaxy S7 (released in 2016) and Galaxy A01 (budget phone released in 2020) without issues so I think we can rule out the hardware as the source.

So I started testing using Network Link Conditioner on macos. I kind of was able to reproduce the stuttering with a 2mbps downlink (DSL profile) and high audio quality (youtube source). Definitely something to investigate there.

@jola5 , @doubleddav, @GStudiosX2 are you on wifi or cell network? What's your bandwidth and latency (from fast.com ?). Are you using Low,Medium or High audio quality in Spotube's settings? When the audio is stuttering, is the "playback" position (green below) reaching the end of the "buffered" position (red below)?

Screenshot_20240503-111703_Spotube

Why is my buffered position the entire song ? By the way I had a few stutters today when playing a song but it might just be a Bluetooth thing

KRTirtho commented 6 months ago

Why is my buffered position the entire song ? By the way I had a few stutters today when playing a song but it might just be a Bluetooth thing

That means the entire song has completed the buffering process, that means there should be no stopping/waiting for loading more music.

KRTirtho commented 6 months ago

So I started testing using Network Link Conditioner on macos. I kind of was able to reproduce the stuttering with a 2mbps downlink (DSL profile) and high audio quality (youtube source). Definitely something to investigate there.

I guess, in that case, switching to lower audio bitrate in poor network conditions should make the experience better. But, I doubt that's not why the issue is happening. From the video, it seems like it's just glitches for couple Milliseconds.

doubleddav commented 5 months ago

Sorry for late response. I've tried all audio qualities, on both mobile and wifi. The issue is definitely not badwidth or latency.

Everything was OK until after vedsion 3.4.1, so not sure what might have changed.

iamrajeshwarraj commented 4 months ago

Same issue is happening with me 😔

Porrumentzio commented 2 months ago

I face the same problem on Android Spotube v3.8.0, Pixel 5 phone with /e/OS (no Google services, in case it could have something to do)

JacobNussbaum commented 2 months ago

Bumping with the same issue, same issue with an Xperia 5 iv running 3.8.0 fromF-droid Happens at every level of streaming quality Non-music skip on or off Bluetooth on or off On data or on wifi From all music sources. let me know if there's any other info I can provide.

Edit: I just Installed version 3.4.0 per another users suggestion and so far the issue has disappeared.

DusBan0 commented 1 month ago

Same issue with skipping, but it only happens for me when I'm connected via bluetooth to my truck head unit or Bose speaker. If I connect via bluetooth to my wireless earbuds, the skipping doesn't occur. This leads me to believe it's a codec or similar issue.

OnePlus Open Android 14.0 running Spotube build 34.

Porrumentzio commented 3 weeks ago

It just happened again: connected via Bluetooth to a Ultimate Ears Megaboom 3, music stuttered constantly. Worked it around by rebooting the phone and the speaker. Then it works well again.

Squidlabs2 commented 1 week ago

One plus 10 android 14 here.

I've always had the same problem. I changed my audio source to Jiosaavn after reading these comments. The issues is gone changing the audio source. Still there using YouTube as the audio source.