florent37 / Flutter-AssetsAudioPlayer

Play simultaneously music/audio from assets/network/file directly from Flutter, compatible with android / ios / web / macos, displays notifications
https://pub.dartlang.org/packages/assets_audio_player
Apache License 2.0
739 stars 336 forks source link

player crashes in buffer sign when app goes offline in the middle of online playing music. #187

Closed sumitkakshapati closed 4 years ago

sumitkakshapati commented 4 years ago

Flutter Version

My version : 1.17.2 Lib Version 2.0.1 My version :

Platform (Android / iOS / web) + version

Platform : Android

Describe the bug

When we play music online than app goes offline it stuck in buffer sign and sometime crash the app.

Log: E/ExoPlayerImplInternal(30959): Source error E/ExoPlayerImplInternal(30959): UnknownHostException (no network) I/ACodec (30959): [OMX.SEC.mp3.dec] signalFlush I/ACodec (30959): [OMX.SEC.mp3.dec] ExecutingState flushing now (codec owns 0/10 input, 5/5 output). I/ACodec (30959): [OMX.SEC.mp3.dec] Now Flushing I/ACodec (30959): [OMX.SEC.mp3.dec] FlushingState onOMXEvent(0,1,0) I/ACodec (30959): [OMX.SEC.mp3.dec] FlushingState onOMXEvent(0,1,1) I/ACodec (30959): [OMX.SEC.mp3.dec] Now Executing I/ACodec (30959): [OMX.SEC.mp3.dec] Now Executing->Idle I/ACodec (30959): [OMX.SEC.mp3.dec] Now Idle->Loaded I/ACodec (30959): [OMX.SEC.mp3.dec] Now Loaded I/ACodec (30959): [OMX.SEC.mp3.dec] Now kWhatShutdownCompleted event : 8492 I/ACodec (30959): [OMX.SEC.mp3.dec] Now uninitialized I/ACodec (30959): [] Now kWhatShutdownCompleted event : 8492 I/MediaCodec(30959): Codec shutdown complete

Is there any way so that we can stop the player when player is out of buffer instead of showing that error?

pro100svitlo commented 4 years ago

In my case, if I am trying to play next Network file and there is no internet, I am facing PlatformException, which I am not able to catch...

So, it would be nice to have some kind of callback with the error code (or enum) for different cases...

sumitkakshapati commented 4 years ago

In my case, if I am trying to play next Network file and there is no internet, I am facing PlatformException, which I am not able to catch...

So, it would be nice to have some kind of callback with the error code (or enum) for different cases...

try{ //Do in this way. await player.open( Audio.network(url) ); } on PlatformException catch(e){ //perform some action }

I think this will catch the exception.

florent37 commented 4 years ago

yes surround your open method with try catch !

try{
       await player.open(Audio.network(url));
}  catch(e){
       //on error
}
florent37 commented 4 years ago

@Timus23 for UnknownHostException it does not throw an exception to Flutter ? catchable ?

maybe it's related to #199 ? an error inside exoplayer not catched ?

sumitkakshapati commented 4 years ago

i have used try catch while opening the player but when wifi goes off and it become offline in middle. no exception is catched by flutter. it also indicate the same error at last i.e mediaplayer.stop() crash like in previous issue #199

florent37 commented 4 years ago

can you try with 2.0.2+6 ?

maybe it fixed that, if no tell me :)

sumitkakshapati commented 4 years ago

yea i used this build.

it stop crashing the app but if app goes offline in the middle of playing music than isPlaying stream will still be true and is buffering is also true. and in the case of invalid track also i guess player state is paused and buffering is still true.

i guess in invalid track we can send playerStatus to PlayerStatus.Error and stop the buffer sign automatically.

and when music goes offline than play until the buffer is remaining and when buffer is finished & if internet is off than player should go to pause state with buffering sign off.

and when app is online again user can simple press play button and track will be played from that same moment.

i think it would be an ideal behaviour..

florent37 commented 4 years ago

You can surround your play/pause button with the buffering listener

I don't think i can set it as paused when it's buffering, because the real player is not in pause mode AND the player can be buffering and playing (buffeing the next seconds)