I am using the media player in my app for some short sounds. Though I do not find any problem / crash in my app, I could see some of the following error messages.. Please help me to resolve this.
我在我的应用中使用媒体播放器来做一些简短的声音。虽然我在我的应用程序中没有发现任何问题/崩溃,但是我可以看到下面的一些错误消息。请帮我解决这个问题。
03-23 22:53:16.229: E/MediaPlayer(19185): pause called in state 8
03-23 22:53:16.229: E/MediaPlayer(19185): error (-38, 0)
03-23 22:53:16.449: E/MediaPlayer(19185): Error (-38,0)
03-23 22:53:16.449: D/OpenGLRenderer(19185): Flushing caches (mode 0)
03-23 22:53:16.459: D/OpenGLRenderer(19185): Flushing caches (mode 0)
03-23 22:53:17.759: D/OpenGLRenderer(19185): Flushing caches (mode 0)
03-23 22:53:17.809: W/MediaPlayer-JNI(19185): MediaPlayer finalized without being released
03-23 22:53:17.809: W/MediaPlayer-JNI(19185): MediaPlayer finalized without being released
03-23 22:53:17.809: W/MediaPlayer-JNI(19185): MediaPlayer finalized without being released
3 个解决方案
#1
5
You could use simple if-check to handle the pausing. Try this:
您可以使用简单的if-check来处理暂停。试试这个:
MediaPlayer mp = MediaPlayer.create(this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/jaihind.mp3"));
if(mp.isPlaying()) {
mp.pause();
} else {
mp.start();
}
Note:
注意:
mp = MediaPlayer.create(...);
is already preparing the MediaPlayer returned, so you cannot call prepare
(or its variants) again (and there is no need for onPreparedListener as well).
已经在准备返回的MediaPlayer,因此您不能再次调用准备(或它的变体)(也不需要onPreparedListener)。
#2
1
I think you have to use this
我认为你必须用这个。
public class Sound extends Activity{
MediaPlayer mp;
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
mp.release();
}
}
#3
0
mp.release();
does the trick. [ instead of mp.pause();
]
mp.release();就可以了。(而不是mp.pause();]
#1
5
You could use simple if-check to handle the pausing. Try this:
您可以使用简单的if-check来处理暂停。试试这个:
MediaPlayer mp = MediaPlayer.create(this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/jaihind.mp3"));
if(mp.isPlaying()) {
mp.pause();
} else {
mp.start();
}
Note:
注意:
mp = MediaPlayer.create(...);
is already preparing the MediaPlayer returned, so you cannot call prepare
(or its variants) again (and there is no need for onPreparedListener as well).
已经在准备返回的MediaPlayer,因此您不能再次调用准备(或它的变体)(也不需要onPreparedListener)。
#2
1
I think you have to use this
我认为你必须用这个。
public class Sound extends Activity{
MediaPlayer mp;
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
mp.release();
}
}
#3
0
mp.release();
does the trick. [ instead of mp.pause();
]
mp.release();就可以了。(而不是mp.pause();]