Error playing media files

I use MediaPlayer to play some sound files that sometimes overlap. I noticed that in the LogCat window, I get the following message:

instances of the android max component of OMX.TI.ACC. Decoding has already been created.

This does not seem to affect my application as sounds continue to play just fine. Does anyone know what this message means and I need to worry about it?

+3
source share
1 answer

SoundPool may be the best 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 the sound by calling the user-defined function.

Play 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
source

Source: https://habr.com/ru/post/1769060/


All Articles