Playing system sounds

A static play() function is provided in the SystemSound class to asynchronously play any system-defined sound file. Here's a QML code sample that shows you how to use the play() function to play a camera shutter sound.

import bb.cascades 1.2
import bb.multimedia 1.2

Page {
    Container {
        // ...
        
        attachedObjects: [
            SystemSound {
                id: sysSound
                sound: SystemSound.CameraShutterEvent
            }
        ]
        
        Button {
            text: "Play System Sound"
                    
            onClicked: {
                sysSound.play();
            }
        }
    }
}

Here's a C++ code sample that shows you how to use the play() function to play a camera shutter sound.

// Code sample showing the single line of code
// needed to asynchronously play a system sound
SystemSound::play(SystemSound::CameraShutterEvent);

You can use the play() function to play a sound, either one time or many times in rapid succession. As you can see in the following C++ code sample, a SystemSound object called keypress is used to play a system sound (SystemSound::InputKeypress) two times in rapid succession by repeatedly calling the keypress.play() function in a for loop.

// SystemSound object created and used from C++.
// In this C++ code sample, the InputKeypress system
// sound is played two times

// Define the system sound that you want to play
SystemSound keypress(SystemSound::InputKeypress);

// Play the sound as desired by calling the
// keypress.play() method repeatedly
for(int i=0; i<2; i++) {
    keypress.play();
}

The architectural flow diagram for SystemSound is shown here. The flow for SystemSound is pretty straightforward in that you only need to set a system sound to play, then play it one or more times as shown in the code samples above.

Flow diagram for SystemSound

Last modified: 2013-12-20

comments powered by Disqus