有的时候音乐不会停止机器人 [英] Some time music does not stop android
本文介绍了有的时候音乐不会停止机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有被称为在播放音乐的onCreate方法的功能...
There is an function which is called on onCreate method of playing music...
public void playBeep() {
try {
if (m.isPlaying()) {
m.stop();
m.release();
m = new MediaPlayer();
}
AssetFileDescriptor descriptor = getAssets().openFd("beep.mp3");
m.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
descriptor.close();
m.prepare();
m.setVolume(1f, 1f);
m.setLooping(true);
m.start();
} catch (Exception e) {
e.printStackTrace();
}
}
和有关的onPause方法我已经写了一站式音乐的,所以当用户离开活动音乐应该自动停止......
and on onPause method i have written code of stop music so when user leaves activity music should automatically stops...
@Override
protected void onPause() {
isBeeping = false;
if (m != null) {
if (m.isPlaying()) {
m.stop();
m.release();
}
}
super.onPause();
}
但有时它工作正常,但有时音乐不会停止!
but sometime it is working fine but sometime music does not stop!!!
可有人建议我怎么离开活动时,要停止音乐:)
can anybody suggest me how to stop music when leaving activity :)
推荐答案
试试这个:
@Override
protected void onPause() {
super.onPause();
isBeeping = false;
if (m != null)
m.release();
}
感谢。
这篇关于有的时候音乐不会停止机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文