簡體   English   中英

播放媒體文件時出錯

[英]Error when playing Media Files

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

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

它似乎對我的應用程序沒有影響,因為聲音繼續發揮得很好。 有誰知道這個消息的含義,我需要擔心嗎?

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);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM