# QtMultimedia.Playlist

For specifying a list of media to be played. More...

 Import Statement: import QtMultimedia 5.4

## Detailed Description

\backportedfrom 5.6

The Playlist type provides a way to play a list of media with the MediaPlayer, Audio and Video types. It can be used as a data source for view elements (such as ListView) and other elements that interact with model data (such as Repeater). When used as a data model, each playlist item's source URL can be accessed using the source role.

import QtQuick 2.0
import QtMultimedia 5.4
Item {
width: 400;
height: 300;
Audio {
id: player;
playlist: Playlist {
id: playlist
PlaylistItem { source: "song1.ogg"; }
PlaylistItem { source: "song2.ogg"; }
PlaylistItem { source: "song3.ogg"; }
}
}
ListView {
model: playlist;
delegate: Text {
font.pixelSize: 16;
text: source;
}
}
MouseArea {
anchors.fill: parent;
onPressed: {
if (player.playbackState != Audio.PlayingState) {
player.play();
} else {
player.pause();
}
}
}
}

## Property Documentation

 currentIndex : int

This property holds the position of the current item in the playlist.

 currentItemsource : url

This property holds the source URL of the current item in the playlist.

 error : enumeration

This property holds the error condition of the playlist.

ValueDescription
NoErrorNo errors
FormatErrorFormat error.
FormatNotSupportedErrorFormat not supported.
NetworkErrorNetwork error.

 errorString : string

This property holds a string describing the current error condition of the playlist.

 itemCount : int

This property holds the number of items in the playlist.

 playbackMode : enumeration

This property holds the order in which items in the playlist are played.

ValueDescription
CurrentItemOnceThe current item is played only once.
CurrentItemInLoopThe current item is played repeatedly in a loop.
SequentialPlayback starts from the current and moves through each successive item until the last is reached and then stops. The next item is a null item when the last one is currently playing.
LoopPlayback restarts at the first item after the last has finished playing.
RandomPlay items in random order.

This property indicates if the playlist can be modified.

## Method Documentation

Appends the source URL to the playlist.

Returns true if the source is added successfully.

Appends source URLs to the playlist.

Returns true if the sources are added successfully.

 bool clear()

Removes all the items from the playlist.

Returns true if the operation is successful.

 bool insertItem(index, source)

Inserts the source URL to the playlist at the given index.

Returns true if the source is added successfully.

 url itemSource(index)

Returns the source URL of the item at the given index in the playlist.

Loads a playlist from the given location. If format is specified, it is used, otherwise the format is guessed from the location name and the data.

New items are appended to the playlist.

onloaded() is emitted if the playlist loads successfully, otherwise onLoadFailed() is emitted with error and errorString defined accordingly.

 bool moveItem(from, to)

Moves the item at the first given index to the second given index.

Returns true if the source is moved successfully.

 next()

Advances to the next item in the playlist.

 int nextIndex(steps)

Returns the index of the item in the playlist which would be current after calling next() steps times.

Returned value depends on the size of the playlist, the current position and the playback mode.

 previous()

Returns to the previous item in the playlist.

 int previousIndex(steps)

Returns the index of the item in the playlist which would be current after calling previous() steps times.

Returned value depends on the size of the playlist, the current position and the playback mode.

 bool removeItem(index)

Removed the item at the given index from the playlist.

Returns true if the source is removed successfully.

 bool removeItems(int start, int end)

Removes items in the playlist from start to \end inclusive.

Returns true if the items are removed successfully.

 bool save(location, format)

Saves the playlist to the given location. If format is specified, it is used, otherwise the format is guessed from the location name.

Returns true if the playlist is saved successfully.

 shuffle()

Shuffles items in the playlist.