I am building an app that uses two media players to play two audio files at the same time. This works fine on my Samsung Galaxy S3 device, but when I run it on a Nexus 5 the audio becomes fragmented / un-listenable.
I am wondering wether using two media players concurrently is possible on the Nexus 5, and if not how can I play two audio files at the same time?
The SoundPool class is specifically designed with multiplexing multiple audio files together so that they can be played together.
SoundPool soundPool = new SoundPool(2, // number of streams
AudioManager.STREAM_MUSIC, // stream type
0); // source quality, does nothing
soundPool.setOnLoadCompleteListener(loadCompleteListener);
int soundOneId = soundPool.load(context, R.raw.sound1, 1);
int soundTwoId = soundPool.load(context, R.raw.sound2, 1);
// Once loadCompleteListener.onLoadComplete has been called for both sounds
soundPool.play(soundOneId);
soundPool.play(soundTwoId);
Use AudioTrack, which provides low latency audio even when streaming. http://developer.android.com/reference/android/media/AudioTrack.html.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With