2011-04-22 128 views
0

我在定時器上播放最後5秒鐘的嗶聲。控制音頻文件聲音

我想用移動設備的音量鍵調節音頻文件的音量。

我目前使用android.media.SoundPool類來播放定時器使用的兩個音頻文件。

我使用下面的方法來播放聲音:

public static void playSound(int index, float speed) { 
     float streamVolume = mAudioManager 
       .getStreamVolume(AudioManager.STREAM_MUSIC); 
     streamVolume = streamVolume 
       /mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); 
     mSoundPool.play(mSoundPoolMap.get(index), 1, 1, 
       1, 0, speed); 
    } 

目前我能玩上的音頻文件,但要與移動設備的音量鍵來控制。

請提供您的輸入/示例代碼。

在此先感謝。

回答

0
+0

請不要自己處理的音量鍵 - 這幾乎是不可能的保證你不會打破音量鍵的行爲。 (): 在onCreate()中調用此API: setVolumeControlStream(AudioManager.STREAM_MUSIC); 這告訴AudioManager,當你的應用程序有焦點時,音量鍵應該調整音樂音量 – 2011-04-22 19:47:16