开发者

Error when playing Media Files

I'm using MediaPlayer to play some sounds files, which at times overlap. I notice that in the LogCat window I keep getting this message:

android max instances of component OMX.TI.ACC. Decode already created.

It seems to have no effect on my application as the sounds continue to play just fine. Does anyone k开发者_如何学编程now what this message means, and do I need to worry about it?


SoundPool may be a better option for playing multiple, short sounds.

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

Then play a sound by calling a custom function.

Playing Sound

/*
*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);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜