Audio

The Audio element is for playing audio.

Audio support varies between operating systems. To ensure your project works on all platforms, try to only use common audio formats like WAV and MP3.

Item {
    on Gesture.tapped(point) {
        audioExample.play()
    }
}
// Audio declared outside the visual code
Audio as audioExample {
    source: "ding.m4a"
}

property Bool enabled: true

When true, the Audio element is enabled and will preroll its audio and respond to other commands, like play().

You might disable audio when you want to control exactly when it begins loading and consuming resources.

property Audio.Status statusread only

The status of the Audio.

Audio.Status.Idle

The element is disabled, or there is no source specified.

Audio.Status.Loading

The element is loading the audio source.

Audio.Status.Ready

The element has successfully loaded the audio, and is ready for playback.

Audio.Status.Failed

The element has failed to load the audio source.

property Url source

The audio's source url. This may be a local file in your project, or a network URL.

If you specify a video file as the source, the video's audio track will be played.

Audio {
    source: "ding.m4a"
}

property Bool playingread only

property Bool pausedread only

True when the audio is playing and when it is paused.

property Float timeread only

property Float durationread only

The current play time, and the total duration of the audio in seconds.

You can change the play time by calling the seekTo() method.

property Float volume: 1.0

The volume at which to play the audio, from 0.0 which mutes the audio to 1.0 which plays it at maximum volume.

property Array<Video.TimeRange> bufferedTimeRangesread only

The time ranges for which content has been buffered.

property Video.TimeRange seekableTimeRangeread only

property Array<Video.TimeRange> seekableTimeRangesread only

The time ranges within the content that can be seeked to. In a local file, the seekable range will be the entire audio file, however in a live stream, the seekable range will often grow or change over time as new content is produced and older content is removed.

The seekableTimeRanges list contains the complete list of seekable time ranges. It is possible, although unusual, for this to be a discontiguous set of times. The seekableTimeRange property is a simplified time range that simply spans all the seekableTimeRanges including any gaps.

property Audio.AudioCategory category: .Ambient

Controls how the audio affects background music apps the user has running, such as the Apple Music or Spotify apps.

Audio.AudioCategory.Ambient

The audio is mixed with the background music.

Audio.AudioCategory.AppMusic

Background music is paused when this Audio element plays.

In both cases, the Audio is silenced if the user locks their device or exits the app.

function play()

function pause()

function stop()

function seekTo(Float seconds)

Play, pause, stop and seek the audio.