[英]mediaplayer how to stop playing
我正在播放一些wav文件,之后我想停止它。
我正在使用单身人士
private static playSound instance = null;
public static synchronized playSound getInstance(Context context) {
if(null == instance) {
instance = new playSound(context, "", 1);
}
return instance;
}
而我在打电话
public void stopAudio() {
try{
myplayer.stop();
myplayer.release();
} catch(Exception e){
Log.e(TAG, "Exception caught:\n" + e.getMessage() +"\n" + e.getStackTrace());
}
}
instance
不是null所以我认为这应该工作因为是同一个实例...
但我得到:
MediaPlayer: stop called in state 1
你需要首先检查它是否正在播放? 如果它正在播放你的停止方法应该工作。
例如:
if ( media_player != null
&& media_player.isPlaying() == true) {
try {
media_player.stop();
media_player.release()
} catch (Exception e) {
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.