可能重复:
When I exit an application the sound runs on the background
当我点击主页按钮或后退按钮时,音频/声音仍在运行,音频源是swf(闪光灯),那我该如何解决?
答案 0 :(得分:1)
你必须覆盖onPause方法并在那里停止音频。
player.pause();
答案 1 :(得分:1)
您应暂停并释放onPause
或onStop
中的播放器以及onStart
或onResume
中的初始播放器。有关此问题,Android开发者网站有training。您应该在活动中添加此代码
@Override
public void onPause() {
super.onPause(); // Always call the superclass method first
// Release the mPlayer because we don't need it when paused
// and other activities might need to use it.
// You change this part to your implement. Stop your player
if (mPlayer != null) {
mPlayer .release()
mPlayer = null;
}
//
}
再次在onResume
@Override
public void onResume() {
super.onResume(); // Always call the superclass method first
// Get the mPlayer instance as the activity achieves full user focus
if (mPlayer == null) {
initializePlayer (); // Local method to handle mPlayer init
}
}