我在我的应用中使用媒体播放器发出一些短促的声音。虽然我的应用程序中没有发现任何问题/崩溃,但我可以看到以下一些错误消息..请帮我解决此问题。
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
答案 0 :(得分:6)
您可以使用简单的if-check来处理暂停。试试这个:
MediaPlayer mp = MediaPlayer.create(this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/jaihind.mp3"));
if(mp.isPlaying()) {
mp.pause();
} else {
mp.start();
}
注意:强>
mp = MediaPlayer.create(...);
已经准备好返回的MediaPlayer,因此您无法再次调用prepare
(或其变体)(并且也不需要onPreparedListener)。
答案 1 :(得分:1)
我认为你必须使用这个
public class Sound extends Activity{
MediaPlayer mp;
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
mp.release();
}
}
答案 2 :(得分:0)
mp.release();
可以解决问题。 [而不是mp.pause();
]