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
Developer
Posts: 29
Registered: ‎05-22-2012
My Device: any BB10 released
My Carrier: Airtel
Accepted Solution

How to play 2 or more sounds at the same time?

i'm building an instrument app using QML & everything turns up fine except this little thing. I've created several 'ImageButton' & gave individual sounds to them by 'onClicked' command. but i found these sounds play in a queue (second click plays after first button audio gets completed & third plays after 2nd & so on...) instead of playing at the same time. Is there any command that enables buttons to initiate at the same time?

 

thanks

Developer
Posts: 43
Registered: ‎08-02-2012
My Device: Z10
My Carrier: RIM

Re: How to play 2 or more sounds at the same time?

if you use MediaPlayer, you can create one MediaPlayer for 1 sound.

Ex:

MediaPlayer {

 id: media1

sourceUrl: "asset:///sounds/1.mp3"

}

MediaPlayer {

id: media2

sourceUrl: "asset:///sounds/2.mp3"

}

 

Then you can call them

Developer
Posts: 29
Registered: ‎05-22-2012
My Device: any BB10 released
My Carrier: Airtel

Re: How to play 2 or more sounds at the same time?

i am using MediaPlayer. Here is the code:

ImageButton {
                                              id: tabla2d
                                              //imageSource: "asset:///images/tabla2.png"
                                              
                                              layoutProperties: AbsoluteLayoutProperties {
                                          positionX: 341
                                          positionY: 610
                                                  
                                              }
                                              onClicked: {
                                                          
                                                          myPlayer.setSourceUrl("asset:///sounds/maidan2.wav")
                                                          myPlayer.play()
                                                      }
                                              
                                              defaultImageSource: ""
                                              pressedImageSource: "asset:///images/maidan2.png"
                                              disabledImageSource: ""
                               overlapTouchPolicy: OverlapTouchPolicy.Allow
           

                                          }

 ...

attachedObjects: [       
                        SystemSound {
                            id: systemSound
                            sound: soundSelectorDropdown.selectedValue
                       },
                        MediaPlayer {
                            id: myPlayer
                    }        
                    ]       

 

any changes?

Developer
Posts: 43
Registered: ‎08-02-2012
My Device: Z10
My Carrier: RIM

Re: How to play 2 or more sounds at the same time?

[ Edited ]

You can add more myPlayer

 

 ....

 MediaPlayer {

id: myPlayer2

}

 

Now you can player your sound with myPlayer2 at the same time with myPlayer.

You can create as many myPlayer you want then play them at the same time with different sound.

Hope this help

Developer
Posts: 29
Registered: ‎05-22-2012
My Device: any BB10 released
My Carrier: Airtel

Re: How to play 2 or more sounds at the same time?

thanks man. works the way i needed. appreciate it