简体   繁体   中英

How to play multiple sounds simultaneously in Android?

I've been trying to make multiple sounds work simultaneously but I kept getting errors like Sample not ready and Error creating AudioTrack. Though I've taken care of the first error, the other error persists.

I'm using two mp3 files, that are away above 5 mb(>4 minutes) and thus was wondering if SoundPool is the right way to go about it? I can use Media Manager but it doesn't let me play multiple files simultaneously.

SoundPool is recommended for <1MB sound clips, so I'd use MediaPlayer in your case. You can call the following for each sound and they will play simultaneously:

MediaPlayer.create(YourActivity.this, R.raw.your_sound).start();

Or you can create multiple MediaPlayer objects and play a sound on each, then release() them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM