QMediaPlaylist Class
The QMediaPlaylist class provides a list of media content to play. 更多...
头文件: | #include <QMediaPlaylist> |
qmake: | QT += multimedia |
基类: | QObject and QMediaBindableInterface |
公有类型
enum | Error { NoError, FormatError, FormatNotSupportedError, NetworkError, AccessDeniedError } |
enum | PlaybackMode { CurrentItemOnce, CurrentItemInLoop, Sequential, Loop, Random } |
属性
- currentIndex : int
- currentMedia : const QMediaContent
- playbackMode : QMediaPlaylist::PlaybackMode
- 1 个属性继承自 QObject
公有函数
QMediaPlaylist(QObject *parent = Q_NULLPTR) | |
virtual | ~QMediaPlaylist() |
bool | addMedia(const QMediaContent &content) |
bool | addMedia(const QList<QMediaContent> &items) |
bool | clear() |
int | currentIndex() const |
QMediaContent | currentMedia() const |
Error | error() const |
QString | errorString() const |
bool | insertMedia(int pos, const QMediaContent &content) |
bool | insertMedia(int pos, const QList<QMediaContent> &items) |
bool | isEmpty() const |
bool | isReadOnly() const |
void | load(const QNetworkRequest &request, const char *format = Q_NULLPTR) |
void | load(const QUrl &location, const char *format = Q_NULLPTR) |
void | load(QIODevice *device, const char *format = Q_NULLPTR) |
QMediaContent | media(int index) const |
int | mediaCount() const |
bool | moveMedia(int from, int to) |
int | nextIndex(int steps = 1) const |
PlaybackMode | playbackMode() const |
int | previousIndex(int steps = 1) const |
bool | removeMedia(int pos) |
bool | removeMedia(int start, int end) |
bool | save(const QUrl &location, const char *format = Q_NULLPTR) |
bool | save(QIODevice *device, const char *format) |
void | setPlaybackMode(PlaybackMode mode) |
重新实现的公有函数
virtual QMediaObject * | mediaObject() const override |
- 32 个公有函数继承自 QObject
- 1 个公有函数继承自 QMediaBindableInterface
公有槽函数
void | next() |
void | previous() |
void | setCurrentIndex(int playlistPosition) |
void | shuffle() |
- 1 个公有槽函数继承自 QObject
信号
void | currentIndexChanged(int position) |
void | currentMediaChanged(const QMediaContent &content) |
void | loadFailed() |
void | loaded() |
void | mediaAboutToBeInserted(int start, int end) |
void | mediaAboutToBeRemoved(int start, int end) |
void | mediaChanged(int start, int end) |
void | mediaInserted(int start, int end) |
void | mediaRemoved(int start, int end) |
void | playbackModeChanged(QMediaPlaylist::PlaybackMode mode) |
- 2 个信号继承自 QObject
其他继承的成员
- 1 个公有变量继承自 QObject
- 10 个静态公有成员继承自 QObject
- 9 个受保护的函数继承自 QObject
- 1 个受保护的函数继承自 QMediaBindableInterface
- 2 个受保护的变量继承自 QObject
详细描述
The QMediaPlaylist class provides a list of media content to play.
QMediaPlaylist is intended to be used with other media objects, like QMediaPlayer.
QMediaPlaylist allows to access the service intrinsic playlist functionality if available, otherwise it provides the local memory playlist implementation.
playlist = new QMediaPlaylist; playlist->addMedia(QUrl("http://example.com/movie1.mp4")); playlist->addMedia(QUrl("http://example.com/movie2.mp4")); playlist->addMedia(QUrl("http://example.com/movie3.mp4")); playlist->setCurrentIndex(1); player = new QMediaPlayer; player->setPlaylist(playlist); videoWidget = new QVideoWidget; player->setVideoOutput(videoWidget); videoWidget->show(); player->play();
Depending on playlist source implementation, most of the playlist mutating operations can be asynchronous.
参见 QMediaContent.
成员类型
enum QMediaPlaylist::Error
This enum describes the QMediaPlaylist error codes.
Constant | Value | Description |
---|---|---|
QMediaPlaylist::NoError | 0 | No errors. |
QMediaPlaylist::FormatError | 1 | Format error. |
QMediaPlaylist::FormatNotSupportedError | 2 | Format not supported. |
QMediaPlaylist::NetworkError | 3 | Network error. |
QMediaPlaylist::AccessDeniedError | 4 | Access denied error. |
enum QMediaPlaylist::PlaybackMode
The QMediaPlaylist::PlaybackMode describes the order items in playlist are played.
Constant | Value | Description |
---|---|---|
QMediaPlaylist::CurrentItemOnce | 0 | The current item is played only once. |
QMediaPlaylist::CurrentItemInLoop | 1 | The current item is played repeatedly in a loop. |
QMediaPlaylist::Sequential | 2 | Playback 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. |
QMediaPlaylist::Loop | 3 | Playback restarts at the first item after the last has finished playing. |
QMediaPlaylist::Random | 4 | Play items in random order. |
属性
currentIndex : int
Current position.
访问函数:
int | currentIndex() const |
void | setCurrentIndex(int playlistPosition) |
Notifier signal:
void | currentIndexChanged(int position) |
currentMedia : const QMediaContent
Current media content.
访问函数:
QMediaContent | currentMedia() const |
Notifier signal:
void | currentMediaChanged(const QMediaContent &content) |
playbackMode : QMediaPlaylist::PlaybackMode
This property defines the order that items in the playlist are played.
访问函数:
PlaybackMode | playbackMode() const |
void | setPlaybackMode(PlaybackMode mode) |
Notifier signal:
void | playbackModeChanged(QMediaPlaylist::PlaybackMode mode) |
成员函数
QMediaPlaylist::QMediaPlaylist(QObject *parent = Q_NULLPTR)
Create a new playlist object with the given parent.
[virtual]
QMediaPlaylist::~QMediaPlaylist()
Destroys the playlist.
bool QMediaPlaylist::addMedia(const QMediaContent &content)
Append the media content to the playlist.
Returns true if the operation is successful, otherwise returns false.
bool QMediaPlaylist::addMedia(const QList<QMediaContent> &items)
Append multiple media content items to the playlist.
Returns true if the operation is successful, otherwise returns false.
bool QMediaPlaylist::clear()
Remove all the items from the playlist.
Returns true if the operation is successful, otherwise return false.
int QMediaPlaylist::currentIndex() const
Returns position of the current media content in the playlist.
Note: Getter function for property currentIndex.
参见 setCurrentIndex().
[signal]
void QMediaPlaylist::currentIndexChanged(int position)
Signal emitted when playlist position changed to position.
Note: Notifier signal for property currentIndex.
QMediaContent QMediaPlaylist::currentMedia() const
Returns the current media content.
Note: Getter function for property currentMedia.
[signal]
void QMediaPlaylist::currentMediaChanged(const QMediaContent &content)
Signal emitted when current media changes to content.
Note: Notifier signal for property currentMedia.
Error QMediaPlaylist::error() const
Returns the last error condition.
QString QMediaPlaylist::errorString() const
Returns the string describing the last error condition.
bool QMediaPlaylist::insertMedia(int pos, const QMediaContent &content)
Insert the media content to the playlist at position pos.
Returns true if the operation is successful, otherwise returns false.
bool QMediaPlaylist::insertMedia(int pos, const QList<QMediaContent> &items)
Insert multiple media content items to the playlist at position pos.
Returns true if the operation is successful, otherwise returns false.
bool QMediaPlaylist::isEmpty() const
Returns true if the playlist contains no items, otherwise returns false.
参见 mediaCount().
bool QMediaPlaylist::isReadOnly() const
Returns true if the playlist can be modified, otherwise returns false.
参见 mediaCount().
void QMediaPlaylist::load(const QNetworkRequest &request, const char *format = Q_NULLPTR)
Load playlist using network request. If format is specified, it is used, otherwise format is guessed from playlist name and data.
New items are appended to playlist.
QMediaPlaylist::loaded() signal is emitted if playlist was loaded successfully, otherwise the playlist emits loadFailed().
void QMediaPlaylist::load(const QUrl &location, const char *format = Q_NULLPTR)
Load playlist from location. If format is specified, it is used, otherwise format is guessed from location name and data.
New items are appended to playlist.
QMediaPlaylist::loaded() signal is emitted if playlist was loaded successfully, otherwise the playlist emits loadFailed().
void QMediaPlaylist::load(QIODevice *device, const char *format = Q_NULLPTR)
Load playlist from QIODevice device. If format is specified, it is used, otherwise format is guessed from device data.
New items are appended to playlist.
QMediaPlaylist::loaded() signal is emitted if playlist was loaded successfully, otherwise the playlist emits loadFailed().
[signal]
void QMediaPlaylist::loadFailed()
Signal emitted if failed to load playlist.
[signal]
void QMediaPlaylist::loaded()
Signal emitted when playlist finished loading.
QMediaContent QMediaPlaylist::media(int index) const
Returns the media content at index in the playlist.
[signal]
void QMediaPlaylist::mediaAboutToBeInserted(int start, int end)
Signal emitted when items are to be inserted at start and ending at end.
[signal]
void QMediaPlaylist::mediaAboutToBeRemoved(int start, int end)
Signal emitted when item are to be deleted at start and ending at end.
[signal]
void QMediaPlaylist::mediaChanged(int start, int end)
This signal is emitted after media has been changed in the playlist between start and end positions inclusive.
int QMediaPlaylist::mediaCount() const
Returns the number of items in the playlist.
参见 isEmpty().
[signal]
void QMediaPlaylist::mediaInserted(int start, int end)
This signal is emitted after media has been inserted into the playlist. The new items are those between start and end inclusive.
[override virtual]
QMediaObject *QMediaPlaylist::mediaObject() const
Reimplemented from QMediaBindableInterface::mediaObject().
Returns the QMediaObject instance that this QMediaPlaylist is bound too, or 0 otherwise.
[signal]
void QMediaPlaylist::mediaRemoved(int start, int end)
This signal is emitted after media has been removed from the playlist. The removed items are those between start and end inclusive.
bool QMediaPlaylist::moveMedia(int from, int to)
Move the item from position from to position to.
Returns true if the operation is successful, otherwise false.
This function was introduced in Qt 5.7.
[slot]
void QMediaPlaylist::next()
Advance to the next media content in playlist.
int QMediaPlaylist::nextIndex(int steps = 1) const
Returns the index of the item, which would be current after calling next() steps times.
Returned value depends on the size of playlist, current position and playback mode.
参见 QMediaPlaylist::playbackMode() and previousIndex().
[signal]
void QMediaPlaylist::playbackModeChanged(QMediaPlaylist::PlaybackMode mode)
Signal emitted when playback mode changed to mode.
Note: Notifier signal for property playbackMode.
[slot]
void QMediaPlaylist::previous()
Return to the previous media content in playlist.
int QMediaPlaylist::previousIndex(int steps = 1) const
Returns the index of the item, which would be current after calling previous() steps times.
参见 QMediaPlaylist::playbackMode() and nextIndex().
bool QMediaPlaylist::removeMedia(int pos)
Remove the item from the playlist at position pos.
Returns true if the operation is successful, otherwise return false.
bool QMediaPlaylist::removeMedia(int start, int end)
Remove items in the playlist from start to end inclusive.
Returns true if the operation is successful, otherwise return false.
bool QMediaPlaylist::save(const QUrl &location, const char *format = Q_NULLPTR)
Save playlist to location. If format is specified, it is used, otherwise format is guessed from location name.
Returns true if playlist was saved successfully, otherwise returns false.
bool QMediaPlaylist::save(QIODevice *device, const char *format)
Save playlist to QIODevice device using format format.
Returns true if playlist was saved successfully, otherwise returns false.
[slot]
void QMediaPlaylist::setCurrentIndex(int playlistPosition)
Activate media content from playlist at position playlistPosition.
Note: Setter function for property currentIndex.
参见 currentIndex().
[slot]
void QMediaPlaylist::shuffle()
Shuffle items in the playlist.