audioplayers icon indicating copy to clipboard operation
audioplayers copied to clipboard

A simple question: AudioPlayerState.COMPLETED, STOPPED, and null?

Open fzyzcjy opened this issue 3 years ago • 3 comments

Hi thanks for this wonderful lib! When using AudioPlayerState I am confused about AudioPlayerState.COMPLETED vs STOPPED. The comments beside it says it is "self-explanatory", but I am not sure about it.

So I guess the following from some observations, is it correct? By the way, it will also greatly help if there is a state diagram (like, "what action will cause state A change to state B")!

  • null: Not started playing? (Not sure, I would appreciate it if could be explained)
  • STOPPED: Hit stop()? (Not sure as well)
  • COMPLETED: When I play the whole audio and it reaches its end, instead of when people call stop? (Not sure as well)

P.S. I do know the following:

  • PLAYING: of course, audio is playing
  • PAUSED : of course, when hit pause(). The resource is NOT released, and the position is kept.

Thanks very much!

Full Description N/A

Code to Reproduce N/A

Log Errors N/A

Files/URLs/Sources N/A

Screenshots N/A

Platforms N/A

fzyzcjy avatar Oct 11 '20 00:10 fzyzcjy

That is a good question. Looking at the code I believe all your observations are correct. The only thing to add is that STOPPED is also set if there is an error preventing it to reach the end.

I updated the doc with some more comments: https://github.com/luanpotter/audioplayers/pull/650

But let me tag @renancaraujo as I believe he built this. I agree the state diagram would be cool.

Some edge cases to think about:

  • should it start with null? we could have IDLE, LOADED states
  • if it's on LOOP mode, does it ever COMPLETED? or stays PLAYING forever?
  • should we have a RELEASED state?
  • should we have a different state for errors or is STOPPED ok?
  • comparing L118 and L637 (on my PR), is this inconsistency a bug?

luanpotter avatar Oct 13 '20 12:10 luanpotter

@luanpotter Thanks! By the way I also found a misleading edge case: When I am playing and directly call dispose, it does not throw exception, and the audio is still playing (in Android). Naively thinking, it should stop it automatically.

fzyzcjy avatar Oct 14 '20 06:10 fzyzcjy

Yeah that sounds like a bug, but unrelated. Feel free to open another issue for that one with more details so we can investigate (there is a template on gh)

luanpotter avatar Oct 15 '20 02:10 luanpotter