Skip to content Skip to sidebar Skip to footer

While Playing Sound Using Media Player In Loop There Is Some Pause In The Loop Which Is Annoying For Our User

We are playing the small audio clip in infinity loop using MediaPlayer in android but there is very small around (200 ms) pause between a loop in the sound which is very annoying b

Solution 1:

    SoundPool soundPool;
    int soundID;
    boolean plays = false, loaded = false;
    float actVolume, maxVolume, volume;
    AudioManager audioManager;       

    audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    actVolume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    maxVolume = (float) audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    volume = actVolume / maxVolume;

    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
    soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {

        }
    });
    soundID = soundPool.load(this, R.raw.audiofile, 1);


    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            soundPool.play(soundID, volume, volume, 1, -1, 1f);
        }
    },1000);

Instead of media player use SoundPool to play continue sound file.


Post a Comment for "While Playing Sound Using Media Player In Loop There Is Some Pause In The Loop Which Is Annoying For Our User"