Audio flow stops after 5 seconds

In my onCreate () method, I do the following:

mSound = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); AudioManager mAudioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); soundID = mSound.load(this, R.raw.sample, 1); streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); setVolumeControlStream(AudioManager.STREAM_MUSIC); 

Then I want the sound file to be played at the click of a button ... so in my onClick () method I have:

 mSound.play(soundID, streamVolume, streamVolume, 1, 0, 1f); 

It works fine ... but only for 5 seconds, then it just cuts off ... any ideas? Thank you I am testing DROID 3 if this helps.

+4
source share
2 answers

SoundPool is designed for short audio files, such as notification files ... To play long audio files, simply use -...

  private MediaPlayer mp_file; ........... mp_file = MediaPlayer.create(getApplicationContext(), R.raw.big); mp_file.start(); 
+2
source

Have you verified that R.raw.sample is, in fact, more than 5 seconds?

If so, how much? Because note that SoundPool is intended for use with short length samples. If you can't get SoundPool to work, try MediaPlayer . It is easy to use and designed for use with longer patterns.

0
source

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


All Articles