I am working on an Android application which does lots of concurrencies and RxJava treading in the background and it is possible to not want to play a music which is in the async preparation phase for some reason:
player.prepareAsync()
and
override fun onPrepared(mp: MediaPlayer?) {
isPreparing = false
if (playAfterPreparing) {
//start playback
mp?.start()
} else {
// don't play and keep it prepare for later!!!
}
updateNotification()
}
but the problem is after preparation you should play(!) because: Media Player called in state 0, error (-38,0)
I even tried to start and pause one after another in preparation:
override fun onPrepared(mp: MediaPlayer?) {
Timber.i("onPrepared")
Timber.i("playAfterPreparing: $playAfterPreparing")
isPreparing = false
//start playback
mp?.start()
if (!playAfterPreparing) {
mp?.pause()
}
updateNotification()
}
but it didn't work cause it rendered to the same issue.
I also know how MediaPlayer state machine is working, but don't see anything in this situation in documents: https://developer.android.com/reference/android/media/MediaPlayer.html
any solution for such a situation?