-1

可能重复:
当我退出应用程序时,声音在后台运行

当我单击主页按钮或返回按钮时,音频/声音仍在运行,音频的来源是 swf(flash),那么我该如何解决?

4

2 回答 2

1

您必须覆盖 onPause 方法并在那里停止音频。

player.pause();
于 2012-09-29T14:00:47.217 回答
1

您应该在or中暂停并释放播放器并在onPauseor中onStop初始化。Android 开发者网站对此进行了培训。您应该在您的活动中添加此代码onStartonResume

    @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
    }
}
于 2012-09-29T14:04:26.107 回答