2010-10-11 101 views
3

我使用MediaPlayer播放一些有時重疊的聲音文件。我注意到,在LogCat窗口中,我不斷收到此消息:播放媒體文件時出錯

組件OMX.TI.ACC的最大實例。解碼已經創建。

它似乎對我的應用程序沒有影響,因爲聲音繼續播放就好了。有人知道這個信息的含義,我需要擔心嗎?

回答

0

SoundPool可能是播放多個短音的更好選擇。

創建的Soundpool

public static final int SOUND_1 = 1; 
public static final int SOUND_2 = 2; 

SoundPool mSoundPool; 
HashMap<Integer, Integer> mHashMap; 

@Override 
public void onCreate(Bundle savedInstanceState){ 
    mSoundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 100); 
    mSoundMap = new HashMap<Integer, Integer>(); 

    if(mSoundPool != null){ 
     mSoundMap.put(SOUND_1, mSoundPool.load(this, R.raw.sound1, 1)); 
     mSoundMap.put(SOUND_2, mSoundPool.load(this, R.raw.sound2, 1)); 
    } 
} 

然後通過調用自定義函數播放聲音。

播放聲音

/* 
*Call this function from code with the sound you want e.g. playSound(SOUND_1); 
*/ 
public void playSound(int sound) { 
    AudioManager mgr = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); 
    float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC); 
    float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC); 
    float volume = streamVolumeCurrent/streamVolumeMax; 

    if(mSoundPool != null){ 
     mSoundPool.play(mSoundMap.get(sound), volume, volume, 1, 0, 1.0f); 
    } 
}