该应用程序听起来媒体在后台运行如何解决它?

时间:2012-09-29 13:52:13

标签: android flash audio

  

可能重复:
  When I exit an application the sound runs on the background

当我点击主页按钮或后退按钮时,音频/声音仍在运行,音频源是swf(闪光灯),那我该如何解决?

2 个答案:

答案 0 :(得分:1)

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

player.pause();

答案 1 :(得分:1)

您应暂停并释放onPauseonStop中的播放器以及onStartonResume中的初始播放器。有关此问题,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
    }
}