SoundInstance QML Type

Play 3d audio content. 更多...

import 語句: import QtAudioEngine 1.15
Since: Qt 5.0
繼承:

Item

特性

信號

方法

詳細描述

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

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:

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();
        }
    }
}
					

特性文檔編製

direction : vector3d

This property holds the current 3d direction.

engine : QtAudioEngine::AudioEngine

This property holds the reference to AudioEngine , must be set only once.

gain : vector3d

This property holds the gain adjustment which will be used to modulate the audio output level from this SoundInstance .

pitch : vector3d

This property holds the pitch adjustment which will be used to modulate the audio pitch from this SoundInstance .

position : vector3d

This property holds the current 3d position.

sound : string

This property specifies which Sound this SoundInstance will use. Unlike some properties in other types, this property can be changed dynamically.

state : enumeration

This property holds the current playback state. It can be one of:

描述
StopppedState The SoundInstance is not playing, and when playback begins next it will play from position zero.
PlayingState The SoundInstance is playing the media.
PausedState The SoundInstance is not playing, and when playback begins next it will play from the position that it was paused at.

velocity : vector3d

This property holds the current 3d velocity.

信號文檔編製

directionChanged ()

此信號發射,當 direction 改變。

相應處理程序是 onDirectionChanged .

注意: 相應處理程序是 onDirectionChanged .

gainChanged ()

此信號發射,當 gain 改變。

相應處理程序是 onGainChanged .

注意: 相應處理程序是 onGainChanged .

pitchChanged ()

此信號發射,當 pitch 改變。

相應處理程序是 onPitchChanged .

注意: 相應處理程序是 onPitchChanged .

positionChanged ()

此信號發射,當 position 改變。

相應處理程序是 onPositionChanged .

注意: 相應處理程序是 onPositionChanged .

soundChanged ()

此信號發射,當 sound 改變。

相應處理程序是 onSoundChanged .

注意: 相應處理程序是 onSoundChanged .

stateChanged ( state )

此信號發射,當 state 改變。

相應處理程序是 onStateChanged .

注意: 相應處理程序是 onStateChanged .

velocityChanged ()

此信號發射,當 velocity 改變。

相應處理程序是 onVelocityChanged .

注意: 相應處理程序是 onVelocityChanged .

方法文檔編製

pause ()

Pauses current playback.

play ()

Starts playback.

stop ()

Stops current playback.