I am learning how to play audio using MediaPlayer from this tutorial, which suggests using release() instead of stop() to STOP the audio. His explanation makes sense to me (free up the system resource as soon as you don't need it) and from a user perspective it works as expected, but I still feel like a bit weird that what's the point of using stop()? (https://stackoverflow.com/a/20580149/3466808)
fun stopPlayer1() = mediaPlayer?.stop()
fun stopPlayer2() {
mediaPlayer?.release()
mediaPlayer = null
}
So, which approach is better? Release as soon as user stops the audio? Or release only when the screen is no longer visible (onStop() called)?
take a look at the diagram in DOCS
MediaPlayerafterrelease()is not "usable" anymore, you cannullify it safely. afteronStopyou still can call e.g.prepareAsync()and start playing again using single instanceedit: to comment