Play several sound effects simultaneously using OpenSL ES Android

好久不见. 提交于 2019-12-22 14:04:10

问题


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:

  1. Use several audio players (and therefore buffer queues) for reproduce the sounds.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!