for some reason my Activity crash when I finish that specified activity. Before when I have only the onDestroy everything works fine except when i minimize the application (HOME button), the music still plays.
From what I gathered, I end up using onDestroy()
, onResume()
and onPause()
to manipulate the MediaPlayer
... but for some reason, when the activity finished, An Alert Dialog stating that Unforunately, ProgramX has stopped.
ALTHOUGH, it continues on to the next startActivity(intent) like it should.
MediaPlayerAssets gls; // custom MediaPlayer Assets to fetch MediaPlayer objects
@Override
protected void onPause()
{
super.onPause();
gls.glbgm.pause(); // my logCat demands that the error occurs here.
resumeToPosition = gls.glbgm.getCurrentPosition();
}
@Override
protected void onRestart()
{
super.onRestart();
if(gls.glbgm != null && !gls.glbgm.isPlaying())
{
gls.glbgm.seekTo(resumeToPosition);
gls.glbgm.start();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
gls.glbgm.release();
gls.score.release();
gls.loser.release();
}
如果尚未启动MediaPlayer
则无法暂停它( 状态图 ),这就是为什么您收到java.lang.IllegalStateException
的原因
What logcat says about the error? You only mention about the line error occured.
Have you ever tried this:
@Override
protected void onPause()
{
super.onPause();
if(gls.glbgm != null && gls.glbgm.isPlaying())
{
gls.glbgm.pause(); // my logCat demands that the error occurs here.
resumeToPosition = gls.glbgm.getCurrentPosition();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.