问题
I'm using OpenSL ES for playing music and sounds in my project. I've used native-audio sample as start and it's fine for reproduce background music and a single sound but when I try to reproduce two or more sounds at same time the sounds aren't reproduced simultaneously because the sound buffers are enqueued for playback when all previous buffers are played.
Then, after a little research, I've found two ways to fix it, in short:
- Use several audio players (and therefore buffer queues) for reproduce the sounds.
- Mix the sound effects buffers together into a single buffer and then enqueue.
My questions are: What do you think is the best approach? There's a better way that I've ignored?
Thanks in advance.
回答1:
I'm working with OpenSL ES as well. Little bit complicated ay the beginning...
Anyway you can create as much ObjectPlayer you want, always remember that the maximum ammount of objects is 32.
So, ideally, if you want to play 4 sounds at the same time, you need 4 PlayerObject and 1 OutputMixObject
Hope you can find usefull
回答2:
Here's a completely different approach: I'm using SoundPool to do this: It's very simple and it works perfectly.
来源:https://stackoverflow.com/questions/10478858/play-several-sound-effects-simultaneously-using-opensl-es-android