ryanheise / just_audio

Audio Player
1.01k stars 616 forks source link

Audio playback from internet stops abruptly on some Android devices #1045

Open tronizx opened 10 months ago

tronizx commented 10 months ago

I don't know how to put things in a comprehensive way so please try to understand and ignore some mistake 😊 Which API doesn't behave as documented, and how does it misbehave? When using API AudioPlayer() to play music from internet using method .setUrl, Everything is fine when i run this in emulator in PC(Android 11) but when run the same application in Real Physical Device(Android 12) it suddenly and Randomly stopped from playing music.

Minimal reproduction project The example

To Reproduce (i.e., user steps, not code) Steps to reproduce the behavior: I just ran the basic app with play and pause buttons and basic logic to play music from internet with fixed set of URLs I have (working fine with emulator all of them same code, played almost more then 5-6 songs in emulator and got no interruptions).

Error messages Getting this message when using same just_audio app on android while playing. why posting when app is working? - cause these logs are not showing when i am using this app on emulator, in emulator it just shows the information of how much buffer is getting or whatever it is for but not this type of continuous message.

.
.
.
I/CCodecBufferChannel( 1509): pipelineRoom(1) is <= numClientBuffers(1). Not signalling any more buffers to client
I/CCodecBufferChannel( 1509): pipelineRoom(1) is <= numClientBuffers(2). Not signalling any more buffers to client
3
I/CCodecBufferChannel( 1509): pipelineRoom(1) is <= numClientBuffers(1). Not signalling any more buffers to client
I/CCodecBufferChannel( 1509): pipelineRoom(1) is <= numClientBuffers(2). Not signalling any more buffers to client
.
.
.

And giving this in terminal when it suddenly stopped from playing-

.
.
.
D/CCodecBufferChannel( 1509): [c2.android.aac.decoder#899] start: updating output delay 2
4
D/CCodecBufferChannel( 1509): [c2.android.aac.decoder#899] MediaCodec discarded an unknown buffer
2
D/MediaCodec( 1509): flushMediametrics
I/hw-BpHwBinder( 1509): onLastStrongRef automatically unlinking death recipients
D/BufferPoolAccessor2.0( 1509): bufferpool2 0xb400007cde104078 : 0(0 size) total buffers - 0(0 size) used buffers - 6763/6768 (recycle/alloc) - 30/6763 (fetch/transfer)
D/BufferPoolAccessor2.0( 1509): evictor expired: 1, evicted: 1

Expected behavior it shouldn't stop from playing until unless the audio file completes or paused/stopped manually using methods like .pause() or .stop() .

Smartphone (please complete the following information):

Flutter SDK version

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.13.0, on Microsoft Windows [Version 10.0.19045.3208], locale en-IN)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.3.5)
[√] Android Studio (version 2022.3)
[√] VS Code (version 1.81.1)
[√] Connected device (3 available)
[√] Network resources

Additional context When it stops playing in physical device there is one thing i noticed that when it stopped from playing suddenly without any manual interruption in that position there is no buffer is loaded in progress bar.

ryanheise commented 10 months ago

Minimal reproduction project Provide a link here using one of two options: I used the default example from Just_audio documentation. After that I only do play songs in sequence using basic logic that if playerstate is completed then load next url from list and play another , It mostly occur in 3rd audio/Music file, yes!! it is very unusual that it dosen't stop suddenly in 1st or second music which is about 3 or 4 min long but it randomly stop playing in middle of 3rd song(dunno why??).

Please try to make the bug report easy to process by following the instructions given. i.e. use one of the two options. (If you are using the unmodified example, just say that. If you have modified the example, link your fork.)

tronizx commented 10 months ago

Minimal reproduction project Provide a link here using one of two options: I used the default example from Just_audio documentation. After that I only do play songs in sequence using basic logic that if playerstate is completed then load next url from list and play another , It mostly occur in 3rd audio/Music file, yes!! it is very unusual that it dosen't stop suddenly in 1st or second music which is about 3 or 4 min long but it randomly stop playing in middle of 3rd song(dunno why??).

Please try to make the bug report easy to process by following the instructions given. i.e. use one of the two options. (If you are using the unmodified example, just say that. If you have modified the example, link your fork.)

it is a same example from documentation!!

ryanheise commented 10 months ago

You shouldn't need to write a wall of text under "Minimal reproduction project" when it should be a single line - either write "The example" or write the link to your fork. Please follow the instructions, thanks.

vladbalan commented 5 months ago

Hi @tronizx were you able to figure out what was going on?

tronizx commented 5 months ago

Hi @tronizx were you able to figure out what was going on?

NO!! but yes there is a random workaround for that is after going to setting of apps in android phone we have to switch the app from battery optimized mode (default in android for every app) to unrestricted mode. For personal usage this is not a problem but in production build it is serious problem because we can't ask the user to change the mode it will give the user hint that it is going to use sooo much battery even if not. So, the proper solution still I am searching.

arodriguezgb commented 5 months ago

I am currently facing this same issue, when on foreground the audio pauses after a bit, the lenght in which it pauses varies, i need to go to the app again for it to continue playing.

tronizx commented 4 months ago

I am currently facing this same issue, when on foreground the audio pauses after a bit, the lenght in which it pauses varies, i need to go to the app again for it to continue playing.

I guess till then you can try with switching battery mode!!

vladbalan commented 1 week ago

Quick update: Not a real solution, just what we encountered: After creating a new Flutter app and rewriting the audio player feature to also implement background audio, the problem doesn't manifest anymore for us. Not sure if it was related to the battery optimized mode or not, but maybe this insight can help others, especially if you're planning on having background play, I would just implement it that way from the get go.