Piasy / RxAndroidAudio

Maybe the most robust Android Audio encapsulation library, with partial Rx support.
http://blog.piasy.com/2016/02/24/Robust-Android-Audio-encapsulation/
MIT License
1.57k stars 235 forks source link

dealying 50 ms onCompletion #40

Closed Marchuck closed 7 years ago

Marchuck commented 7 years ago

just curious about the 50ms delay before releasing the MediaPlayer did you discovered something regarding this topic?

https://github.com/Piasy/RxAndroidAudio/blob/master/rxandroidaudio/src/main/java/com/github/piasy/rxandroidaudio/RxAudioPlayer.java#L231

Piasy commented 7 years ago

I've added comments about that, but the root cause is still unknown :(

Marchuck commented 7 years ago

ok, after some debugging I found that there is some bugs in the code. Running mediaPlayer throws IllegalStateException

I think clearner way is simple check if ( mediaPlayer.isPlaying() ) { mediaPlayer.stop(); }

when disposing MediaPlayer sometimes I got IllegalStateException during mediaPlayer.reset() execution. This leads to skipping the mediaPlayer.release() which leads to leak.

I made some snippet for my use case

https://gist.github.com/Marchuck/743785962b98db1522ed4ab338d664c0

hope it helps somebody

Piasy commented 7 years ago

Cool, could you please submit a PR?