Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the right way to disconnect a MediaController?

Tags:

android

What's the right way to shut down a MediaController with an attached MediaPlayer?

You can't do mediaController.setMediaPlayer(null) - that immediately calls updatePausePlay, which dereferences the null.

You can't call mediaPlayer.release(), since MediaController is going to call MediaPlayer#getCurrentPosition, and that throws an IllegalStateException after release() has been called.

like image 469
James Moore Avatar asked Oct 09 '22 17:10

James Moore


1 Answers

try the below snippet, in this order

mediaController.hide();
mediaPlayer.stop();
mediaPlayer.release();
like image 129
jp36 Avatar answered Oct 12 '22 10:10

jp36