2

当我将音频设置为静音时遇到问题,onPause()onResume()尝试取消静音但没有成功。

代码:

    protected void onPause() {
            super.onPause();
            Log.d(TAG, "onPause");
            setStreamMute(true);        
         }

    protected void onResume() {
            super.onResume();
            Log.d(TAG, "onResume");
            setStreamMute(false);
        }

    public void setStreamMute (boolean state){
            Log.d(TAG,"SetMute: "+state);
            myAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
            myAudioManager.setStreamMute(AudioManager.STREAM_MUSIC, state);
      }

欢迎任何帮助,谢谢。

4

1 回答 1

0
MediaPlayer ourSong;
int length; // To save the last seconds where the music has paused

在你的OnCreate

ourSong = MediaPlayer.create(yourActivity.this, YourSong);
        ourSong.setLooping(true);
ourSong.start();

在你暂停功能

ourSong.pause();
length = ourSong.getCurrentPosition();

在你恢复功能

ourSong.seekTo(length);
ourSong.start();

笔记:

你应该做一个文件夹row,然后YourSong必须是这样的R.raw.yoursong

于 2013-02-15T19:31:53.120 回答