SoundInstance

Play 3d audio content. More...

Import Statement: import QtAudioEngine 1.0
Since: Qt 5.0

Detailed Description

This type is part of the QtAudioEngine 1.0 module.

There are two ways to create SoundInstance objects. You can obtain it by calling newInstance method of a Sound:

import QtQuick 2.0
import QtAudioEngine 1.0

Rectangle {
    id:root
    color:"white"
    width: 300
    height: 500

    AudioEngine {
        id:audioengine

        AudioSample {
            name:"explosion01"
            source: "explosion-01.wav"
        }

        Sound {
            name:"explosion"
            PlayVariation {
                sample:"explosion01"
            }
        }
    }

    property variant soundEffect: audioengine.sounds["explosion"].newInstance();

    MouseArea {
        anchors.fill: parent
        onPressed: {
            root.soundEffect.play();
        }
    }
}

Or alternatively, you can explicitly define SoundInstance outside of AudioEngine for easier qml bindings:

import QtQuick 2.0
import QtAudioEngine 1.0

Rectangle {
    id:root
    color:"white"
    width: 300
    height: 500

    AudioEngine {
        id:audioengine

        AudioSample {
            name:"explosion01"
            source: "explosion-01.wav"
        }

        Sound {
            name:"explosion"
            PlayVariation {
                sample:"explosion01"
            }
        }
    }

    Item {
        id: animator
        x: 10 + observer.percent * 100
        y: 20 + observer.percent * 80
        property real percent: 0
        SequentialAnimation on percent {
            loops: Animation.Infinite
            running: true
            NumberAnimation {
            duration: 8000
            from: 0
            to: 1
            }

        }
    }

    SoundInstance {
        id:soundEffect
        engine:audioengine
        sound:"explosion"
        position:Qt.vector3d(animator.x, animator.y, 0);
    }

    MouseArea {
        anchors.fill: parent
        onPressed: {
            soundEffect.play();
        }
    }
}