Qt 之QMediaPlayer类详解
Posted 刘二毛
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Qt 之QMediaPlayer类详解相关的知识,希望对你有一定的参考价值。
这是一个播放多媒体流的类
几个重要的枚举类型
enum QMediaPlayer::MediaStatus
Defines the status of a media player's current media.
Constant | Value | Description |
---|---|---|
QMediaPlayer::UnknownMediaStatus | 0 | The status of the media cannot be determined. |
QMediaPlayer::NoMedia | 1 | The is no current media. The player is in the StoppedState. |
QMediaPlayer::LoadingMedia | 2 | The current media is being loaded. The player may be in any state. |
QMediaPlayer::LoadedMedia | 3 | The current media has been loaded. The player is in the StoppedState. |
QMediaPlayer::StalledMedia | 4 | Playback of the current media has stalled due to insufficient buffering or some other temporary interruption. The player is in thePlayingState or PausedState. |
QMediaPlayer::BufferingMedia | 5 | The player is buffering data but has enough data buffered for playback to continue for the immediate future. The player is in thePlayingState or PausedState. |
QMediaPlayer::BufferedMedia | 6 | The player has fully buffered the current media. The player is in thePlayingState or PausedState. |
QMediaPlayer::EndOfMedia | 7 | Playback has reached the end of the current media. The player is in theStoppedState. |
QMediaPlayer::InvalidMedia | 8 | The current media cannot be played. The player is in the StoppedState. |
Properties:
- audioAvailable : const bool 音频是否有效 notifier信号 void audioAvailableChanged(bool available)
- bufferStatus : const int This property holds the percentage of the temporary buffer filled before playback begins or resumes, from (empty) to (full)
- currentMedia : const QMediaContent 当前正在播放的媒体的内容
- duration : const qint64 当前媒体的duration notifier信号 void durationChanged(qint64 duration)
- error : const QString a string describing the last error condition
- media : QMediaContent a string describing the last error condition
- mediaStatus : const MediaStatus 当前媒体流的状态 notifier信号 void mediaStatusChanged(QMediaPlayer::MediaStatus status)
- muted : bool 是否静音 isMuted();setMuted() notifier信号 void mutedChanged(bool muted)
- playbackRate : qreal 播放速率;1是正常速率,大于1加快播放 void setPlaybackRate(qreal rate);notifier信号 void playbackRateChanged(qreal rate)
- position : qint64 决定当前视频的播放位置(ms) void setPosition(qint64 position) notifier信号 void positionChanged(qint64 position)
- seekable : const bool may change across the life time of the QMediaPlayer object, use the seekableChanged() signal to monitor changes.
- state : const State 播放器的播放状态 notifer signal void stateChanged(QMediaPlayer::State state)
- videoAvailable : const bool
- volume : int The playback volume is linear in effect and the value can range from 0 - 100 notifer signal void volumeChanged(int volume)
公有成员函数
QMediaPlayer(QObject * parent = 0, Flags flags = 0) | |
~QMediaPlayer() | |
int | bufferStatus() const |
QMediaContent | currentMedia() const |
QNetworkConfiguration | currentNetworkConfiguration() const |
qint64 | duration() const |
Error | error() const |
QString | errorString() const |
bool | isAudioAvailable() const |
bool | isMuted() const |
bool | isSeekable() const |
bool | isVideoAvailable() const |
QMediaContent | media() const |
MediaStatus | mediaStatus() const |
const QIODevice * | mediaStream() const |
qreal | playbackRate() const |
QMediaPlaylist * | playlist() const |
qint64 | position() const |
void | setVideoOutput(QVideoWidget * output) Attach a QVideoWidget video output to the media player ,可替换新 |
void | setVideoOutput(QGraphicsVideoItem * output) |
void | setVideoOutput(QAbstractVideoSurface * surface) Sets a video surface as the video output of a media player |
State | state() const |
int | volume() const |
公有槽
void | pause() |
void | play() 开始或重新开始播放当前媒体流 |
void | setMedia(const QMediaContent & media, QIODevice * stream = 0) |
void | setMuted(bool muted) |
void | setNetworkConfigurations(const QList<QNetworkConfiguration> & configurations) |
void | setPlaybackRate(qreal rate) |
void | setPlaylist(QMediaPlaylist * playlist) |
void | setPosition(qint64 position) |
void | setVolume(int volume) |
void | stop() Stop playing, and reset the play position to the beginning. |
信号:
void | audioAvailableChanged(bool available) |
void | bufferStatusChanged(int percentFilled) |
void | currentMediaChanged(const QMediaContent & media) |
void | durationChanged(qint64 duration) |
void | error(QMediaPlayer::Error error) |
void | mediaChanged(const QMediaContent & media) |
void | mediaStatusChanged(QMediaPlayer::MediaStatus status) |
void | mutedChanged(bool muted) |
void | networkConfigurationChanged(const QNetworkConfiguration & configuration) |
void | playbackRateChanged(qreal rate) |
void | positionChanged(qint64 position) |
void | seekableChanged(bool seekable) |
void | stateChanged(QMediaPlayer::State state) |
void | videoAvailableChanged(bool videoAvailable) |
void | volumeChanged(int volume) |
以上是关于Qt 之QMediaPlayer类详解的主要内容,如果未能解决你的问题,请参考以下文章
Qt系列文章之二十六(基于QMediaPlayer 在 QVideoWidget或QGraphicsVideoItem 组件上播放视频)
Qt系列文章之二十六(基于QMediaPlayer 在 QVideoWidget或QGraphicsVideoItem 组件上播放视频)