Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Developer
MedNez
Posts: 67
Registered: ‎11-24-2008
My Device: Not Specified
Accepted Solution

Best Practices for playing multiple sounds - one MediaPlayer or many?

Hello!

 

I am using the MediaPlayer object in QML. 

 

Problem: If I have 10 objects, and when you tap an object a sound plays... then with ONE MediaPlayer, the sound that is playing has to finish before another sound can start. (Or you can write the code to 'stop the existing sound and play another one'). Either way, you can't have a musical flurry when you tap each object.

 

Current Solution: Add a MediaPlayer component to each object, so when you tap that object, it plays its own MediaPlayer. Sounds amazing because the sounds overlap. In a game, if you are hitting objects quicker than their sound can play, this sounds great as the dings/boops/pings are nicely overlapping as they sound.

 

However I feel that this might be taking up unnecessary memory? For example if I had 100 objects, I don't think I'd want 100 MediaPlayer components attached?

 

Is there a better way to do concurrent sound in QML?

Developer
Dredvard
Posts: 160
Registered: ‎01-27-2012
My Device: Playbook

Re: Best Practices for playing multiple sounds - one MediaPlayer or many?

[ Edited ]

Check this.   They used multiple simultaneous sounds with only one soundmanger.

 

https://github.com/blackberry/Presentations/tree/master/2012-BlackBerryJam-Americas/JAM09/BaDumTss

---
If you find my post helpful please "like" it and "accept as a solution"
New Developer
MedNez
Posts: 67
Registered: ‎11-24-2008
My Device: Not Specified

Re: Best Practices for playing multiple sounds - one MediaPlayer or many?

Awesome. Thanks. I have implemented this. 

 

I have a question about the destructor and app cleanup, but I've started a new (more relevant) thread for that:

 

http://supportforums.blackberry.com/t5/Cascades-Development/C-App-Destructor-causes-build-error/td-p...

New Contributor
deion
Posts: 6
Registered: ‎02-07-2013
My Device: Playbook

Re: Best Practices for playing multiple sounds - one MediaPlayer or many?

That really doesn't answer the question. The issue was on what is the best usage of the cascades MediaPlayer class to play simultaneous sounds. The code given as a reference uses OpenAL and not MediaPlayer or mmr.

To present my story: I was trying to play simultaneous sounds in my game app: gameloop music + laser guns + explosions. Using multiple MediaPlayer instances, one for each of the sounds I wanted to play, the sounds could be played in parallel, however the performance of my game was really bad after integrating the MediaPlayer code. Plus the debug console was full of tons of messages from MediaPlayer and it was hard for me to follow my own debug messages.

Conclusion: the MediaPlayer is OK as ease of use, the API is OK; however the performance was POOR for such a simple task (playing 3-4 multiple .wav sounds in parallel), which should be trivial especially for a game. It seems to me the MediaPlayer class is too bloated and should only be used to stream remote media from a server.

 

I used the OpenAL code mentioned above in the BaDumTss JAM sample and it works great; and also the code is easy to use and understand, it's just one class, SoundManager.

 

Regards,

Ionut