Multiple MediaPlayers do not work on Nexus 5
android, android-mediaplayer, nexus-5
Solution
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);
Problem
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?