Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business


The SoundEffect element allows playing short-lasting and looping sound effects in wav file format. More...

Import Statement: import Felgo 3.0




Detailed Description

Playing SoundEffect has a very low latency and is therefore well suited for short notification sounds.

The sound is preloaded as soon as the source property is set and can then be started with low latency by calling play(). You can also set the loops property to implementing looping sounds.

For playing encoded audio files for example in MP3 format or with no latency requirements use the BackgroundMusic component. For videos use the Video component.

Felgo Additions to SoundEffect

SoundEffect enhances the Qt 5 component SoundEffect in the Qt Multimedia 5.0 module with the following additions:

  • Allow to pause and resume all SoundEffect objects by setting settings.soundEnabled to true or false.
  • Proper application handling: if the app is moved to the background all instances of SoundEffect and BackgroundMusic are paused on mobile platforms. All instances are then resumed when the app gets focus again and comes into foreground. This is especially useful on mobile devices, where the default SoundEffect component would continue playing if the app is moved to the background. On Desktop platforms, the SoundEffect and BackgroundMusic instances keep playing. You can modify this behavior with the autoPauseInBackground property.
  • Use the autoPlay property to start playing a SoundEffect when it is loaded, useful if you have a BackgroundMusic type sound that should be loaded when starting your app.

SoundEffect Details

This type allows you to play uncompressed audio files (typically WAV files) in a generally lower latency way, and is suitable for "feedback" type sounds in response to user actions (e.g. virtual keyboard sounds, positive or negative feedback for popup dialogs, or game sounds). If low latency is not important, consider using the MediaPlayer or BackgroundMusic types instead, since they support a wider variety of media formats and are less resource intensive.

Typically the sound effect should be reused, which allows all the parsing and preparation to be done ahead of time, and only triggered when necessary. This is easy to achieve with QML, since you can declare your SoundEffect instance and refer to it elsewhere.

Note: Since SoundEffect requires slightly more resources to achieve lower latency playback, the platform may limit the number of simultaneously playing sound effects.

Finding Sounds

For free sounds, we recommend the following websites:

These sites have a great search feature, as you can search by categories or tags. Most of the sounds are available for free if you add the license to your game. There also are low-price premium version of the sounds, which allows you to use them without any license note.

Supported SoundEffect Formats

The wav format is the single format that is supported on all platforms. Try to follow the same Performance Hints mentioned in the BackgroundMusic component for maximum performance.

Note: If you target the Android platform, ensure that all wav files are 16 bit PCM (or higher) encoded. Convert all 8 bit wav files to 16 bit and rebuild the app.

Example Usage

Here is an example of playing a looping sound on mouse click:

 import Felgo 3.0
 import QtQuick 2.0
 import QtMultimedia 5.0 // required for SoundEffect.Infinite enum value for infinite looping

 GameWindow {

   MouseArea {
     anchors.fill: parent
     onClicked: clickSound.play()

   SoundEffect {
     id: clickSound
     source: "clickSound.wav"
     loops: SoundEffect.Infinite

Property Documentation

autoPauseInBackground : bool

Set this property to automatically pause this SoundEffect when the app is moved to background.

On mobile that happens if the user presses the home button and leaves the app. On desktop that happens when the app loses its focus or gets minimized.

By default, this value is true on mobile platforms and false on desktop platforms.

autoPlay : bool

Set this property to play the sound effect automatically when this item is loaded, e.g. at application start.

By default, it is set to true. So when the settings.soundEnabled property is also set to true, the music is played after initialization of the Settings object.

See also GameWindowApplicationWindow::settings.

category : string

This property contains the category of this sound effect.

Some platforms can perform different audio routing for different categories, or may allow the user to set different volume levels for different categories.

This setting will be ignored on platforms that do not support audio categories.

loops : int

This property provides a way to control the number of times to repeat the sound on each play().

By default, loops is set to 1 and therefore plays the sound effect only once.

Set to SoundEffect.Infinite to enable infinite looping.

Note: To have access to the SoundEffect.Infinite enum, make sure to call import QtMultimedia 5.0 in the header of your QML file

loopsRemaining : int

This property contains the number of loops remaining before the sound effect stops by itself, or SoundEffect.Infinite if that's what has been set in loops.

muted : bool

This property provides a way to control muting. A value of true will mute this sound. Otherwise, playback will occur with the currently specified volume. The default value is false.

playing : bool

This property holds whether the sound is playing.

This property is read-only.

source : url

This property holds the url for the sound to play. For the SoundEffect to attempt to load the source, the URL must exist and the application must have read permission in the specified directory. If the desired source is a local file, the URL may be specified by using either an absolute or a relative (to the file that declared the SoundEffect) path.

status : int

This property indicates the current status of the SoundEffect as enumerated within SoundEffect. Possible statuses are listed below.

Value Description
SoundEffect.Null No source has been set or the source is null.
SoundEffect.Loading The SoundEffect is trying to load the source.
SoundEffect.Ready The source is loaded and ready for play.
SoundEffect.Error An error occurred during operation, such as failure of loading the source.

volume : real

This property holds the volume of the sound output, from 0.0 (silent) to 1.0 (maximum volume).

Note: The volume property affects ALL Sounds and the BackgroundMusic instances on Windows, but not on mobile platforms. So the last volume setting that is defined is used for all sounds in the application.

The default value is 1.

Method Documentation


Returns whether the sound effect has finished loading the source.


Starts playback of the sound effect if the soundEnabled property in GameWindowApplicationWindow::settings is true, looping the effect for the number of times as specified in the loops property.

Sets the playing property to true.

See also stop().


Stop current playback.

Sets the playing property to false.

See also play().

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded