多个MediaPlayers不适用于Nexus 5

Oli*_*djo 9 android android-mediaplayer nexus-5

我正在构建一个应用程序,它使用两个媒体播放器同时播放两个音频文件.这在我的三星Galaxy S3设备上工作正常,但是当我在Nexus 5上运行它时,音频变得支离破碎/不可听.

我想知道在Nexus 5上同时使用两个媒体播放器是否可行,如果不能,我怎么能同时播放两个音频文件?

ian*_*ake 5

的Soundpool类是专门与复用多个音频文件一起设计,使他们可以一起玩.

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);
Run Code Online (Sandbox Code Playgroud)


Dav*_*e C 5

使用AudioTrack,即使在流式传输时也能提供低延迟音频.http://developer.android.com/reference/android/media/AudioTrack.html.