just_audio
just_audio copied to clipboard
[iOS] Sometimes while playing, seeking causes the player to play on with no sound and the wrong progress reporting (works again after pause/play)
Which API doesn't behave as documented, and how does it misbehave?
When the player is already playing, the seek
method sometimes (esp. under bad network conditions) causes the player to not detect the buffering state correctly. After seeking, the players shows processing ready
state when it's actually buffering and there is no sound. The position stream also moves on during this period. After a while, the sound comes back but the position stream is still offset-ed with the silence duration. After clicking "pause" and "play" again, the position is then correctly reported.
Minimal reproduction project The example.
To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:
- In order to reproduce this easily, use the network conditioner on iOS and set it to 3G or Edge.
- Go to the example player, click on "Play".
- Wait until it's playing, drag the progress bar around to seek.
- At some point the player will be shown as "playing" with the progress bar moving on but there is no sound.
- After a while, the sound comes back but the position is still "ahead" because it counted the soundless part.
- After pausing & playing again, the position is now correct (it goes back).
Error messages There is no error messages. The processing status seems to be wrong when there is no sound, as it should be buffering instead of ready.
Expected behavior The player should show "buffering" processing state when this happens and should not show the "ready" state with no sound.
Screenshots Video reproducing the issue Note: at around 0:14 seconds after I hit pause, the position stream is "fixed".
Smartphone (please complete the following information):
- Device: iPhone6, iPhone 13
- OS: iOS 15.7.6 & iOS 16.6.1
Flutter SDK version
Flutter (Channel stable, 3.13.5, on macOS 12.6 21G115 darwin-arm64, locale en-CH)
• Flutter version 3.13.5 on channel stable at /Users/**/fvm/versions/3.13.5
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 12fccda598 (3 weeks ago), 2023-09-19 13:56:11 -0700
• Engine revision bd986c5ed2
• Dart version 3.1.2
• DevTools version 2.25.0
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
• Android SDK at /Users/**/Library/Android/sdk
• Platform android-33, build-tools 32.1.0-rc1
• ANDROID_HOME = /Users/**/Library/Android/sdk
• ANDROID_SDK_ROOT = /Users/**/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14C18
• CocoaPods version 1.12.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
[✓] VS Code (version 1.82.3)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.74.0
[✓] Connected device (4 available)
• ***
[✓] Network resources
• All expected network resources are available.
Potential workaround
It seems like by not calling self->_player.rate = self->_speed;
immediately in the seek:position completionHandler
and instead use a flag and call it when observing playbackLikelyToKeepUp
makes it better, i.e. it buffers and only shows ready
& moves the position after it's really playing. But this is still a bit unreliable at times.
Adding on top of what @snipd-min commented, we have made the following observations on the native side:
- When the issue is happening, the
timeControlStatus
is reported to beAVPlayerTimeControlStatusPlaying
. However, I would expect it to beAVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate
since nothing is being played - If we enable the
addPeriodicTimeObserverForInterval
andcheckForDiscontinuity
is called, once the audio is playing the current position is corrected - If we check wether the
currentTime
of theplayerItem
is buffered, by observing and checkingloadedTimeRanges
, we noticed that sometimes when thetimeControlStatus
isAVPlayerTimeControlStatusPlaying
, thecurrentTime
is not buffered yet (it’s not contained in any of theloadedTimeRanges
)
I have got same error when seek to on Android device. Progress bar still going with no sound
I have the same issue with both iOS and Android.
@snipd-min @mohammad-adk @ryanheise @snipd-mikel any update on a solution for ios? I have been facing recently with flutter version 3.19.5
@ryanheise I am still facing issue more frequently as of now, could you please help me with what can be done and which flutter version is best for this library?