Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QMediaPlayer Class Reference

The QMediaPlayer class allows the playing of a media source. More...

    #include <QMediaPlayer>

This class is under development and is subject to change.

Inherits QMediaObject.


Public Types

enum Error { NoError, ResourceError, FormatError, NetworkError, AccessDeniedError, ServiceMissingError }
enum Flag { LowLatency }
flags Flags
enum MediaStatus { UnknownMediaStatus, NoMedia, LoadingMedia, LoadedMedia, ..., InvalidMedia }
enum State { PlayingState, PausedState, StoppedState }

Properties


Public Functions

QMediaPlayer ( QObject * parent = 0, Flags flags = 0, QMediaServiceProvider * provider = QMediaServiceProvider::defaultServiceProvider() )
~QMediaPlayer ()
int bufferStatus () const
qint64 duration () const
Error error () const
QString errorString () const
bool isMuted () const
bool isSeekable () const
bool isVideoAvailable () const
QMediaContent media () const
MediaStatus mediaStatus () const
const QIODevice * mediaStream () const
qreal playbackRate () const
qint64 position () const
State state () const
int volume () const

Public Slots

void pause ()
void play ()
void setMedia ( const QMediaContent & media, QIODevice * stream = 0 )
void setMuted ( bool muted )
void setPlaybackRate ( qreal rate )
void setPosition ( qint64 position )
void setVolume ( int volume )
void stop ()
  • 1 public slot inherited from QObject

Signals

void bufferStatusChanged ( int percentFilled )
void durationChanged ( qint64 duration )
void error ( QMediaPlayer::Error error )
void mediaChanged ( const QMediaContent & media )
void mediaStatusChanged ( QMediaPlayer::MediaStatus status )
void mutingChanged ( bool muted )
void playbackRateChanged ( qreal rate )
void positionChanged ( qint64 position )
void seekableChanged ( bool seekable )
void stateChanged ( QMediaPlayer::State state )
void videoAvailabilityChanged ( bool videoAvailable )
void volumeChanged ( int volume )

Static Public Members

QtMedia::SupportEstimate hasSupport ( const QString & mimeType, const QStringList & codecs = QStringList(), Flags flags = 0 )
  • 4 static public members inherited from QObject

Additional Inherited Members

  • 1 public type inherited from QObject
  • 2 protected functions inherited from QMediaObject
  • 7 protected functions inherited from QObject
  • 2 protected variables inherited from QObject

Detailed Description

The QMediaPlayer class allows the playing of a media source.

The QMediaPlayer class is a high level media playback class. It can be used to playback such content as songs, movies and internet radio. The content to playback is specified as a QMediaContent, which can be thought of as a main or canonical URL with addition information attached. When provided with a QMediaContent playback may be able to commence.

    player = new QMediaPlayer;
    connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
    player->setMedia(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3"));
    player->setVolume(50);
    player->play();

QVideoWidget can be used with QMediaPlayer for video rendering and QMediaPlaylist for accessing playlist functionality.

    player = new QMediaPlayer;

    playlist = new QMediaPlaylist(player);
    playlist->append(QUrl("http://example.com/movie1.mp4"));
    playlist->append(QUrl("http://example.com/movie2.mp4"));

    widget = new QVideoWidget(player);
    widget->show();

    player->play();

See also QMediaObject, QMediaService, QVideoWidget, and QMediaPlaylist.


Member Type Documentation

enum QMediaPlayer::Error

Defines a media player error condition.

ConstantValueDescription
QMediaPlayer::NoError0No error has occurred.
QMediaPlayer::ResourceError1A media resource couldn't be resolved.
QMediaPlayer::FormatError2The format of a media resource isn't (fully) supported. Playback may still be possible, but without an audio or video component.
QMediaPlayer::NetworkError3A network error occurred.
QMediaPlayer::AccessDeniedError4There are not the appropriate permissions to play a media resource.
QMediaPlayer::ServiceMissingError5A valid playback service was not found, playback cannot proceed.

enum QMediaPlayer::Flag
flags QMediaPlayer::Flags

ConstantValueDescription
QMediaPlayer::LowLatency0x01The player is expected to be used with simple audio formats, but playback should start without significant delay. Such playback service can be used for beeps, ringtones, etc.

The Flags type is a typedef for QFlags<Flag>. It stores an OR combination of Flag values.

enum QMediaPlayer::MediaStatus

Defines the status of a media player's current media.

ConstantValueDescription
QMediaPlayer::UnknownMediaStatus0The status of the media cannot be determined.
QMediaPlayer::NoMedia1The is no current media. The player is in the StoppedState.
QMediaPlayer::LoadingMedia2The current media is being loaded. The player may be in any state.
QMediaPlayer::LoadedMedia3The current media has been loaded. The player is in the StoppedState.
QMediaPlayer::StalledMedia4Playback of the current media has stalled due to insufficient buffering or some other temporary interruption. The player is in the PlayingState or PausedState.
QMediaPlayer::BufferingMedia5The player is buffering data but has enough data buffered for playback to continue for the immediate future. The player is in the PlayingState or PausedState.
QMediaPlayer::BufferedMedia6The player has fully buffered the current media. The player is in the PlayingState or PausedState.
QMediaPlayer::EndOfMedia7Playback has reached the end of the current media. The player is in the StoppedState.
QMediaPlayer::InvalidMedia8The current media cannot be played. The player is in the StoppedState.

enum QMediaPlayer::State

Defines the current state of a media player.

ConstantValueDescription
QMediaPlayer::PlayingState1The media player is currently playing content.
QMediaPlayer::PausedState2The media player has paused playback, playback of the current track will resume from the position the player was paused at.
QMediaPlayer::StoppedState0The media player is not playing content, playback will begin from the start of the current track.


Property Documentation

bufferStatus : const int

This property holds the percentage of the temporary buffer filled before playback begins.

When the player object is buffering; this property holds the percentage of the temporary buffer that is filled. The buffer will need to reach 100% filled before playback can resume, at which time the MediaStatus will be BufferedMedia.

Access functions:

int bufferStatus () const

Notifier signal:

void bufferStatusChanged ( int percentFilled )

See also mediaStatus().

duration : const qint64

This property holds the duration of the current media.

The value is the total playback time in milliseconds of the current media. The value may change across the life time of the QMediaPlayer object and may not be available when initial playback begins, connect to the durationChanged() signal to receive status notifications.

Access functions:

qint64 duration () const

Notifier signal:

void durationChanged ( qint64 duration )

error : const QString

This property holds a string describing the last error condition.

Access functions:

QString errorString () const

See also error().

media : QMediaContent

This property holds the active media source being used by the player object.

The player object will use the QMediaContent for selection of the content to be played.

By default this property has a null QMediaContent.

Access functions:

QMediaContent media () const
void setMedia ( const QMediaContent & media, QIODevice * stream = 0 )

Notifier signal:

void mediaChanged ( const QMediaContent & media )

See also QMediaContent.

mediaStatus : const MediaStatus

This property holds the status of the current media stream.

The stream status describes how the playback of the current stream is progressing.

By default this property is QMediaPlayer::NoMedia

Access functions:

MediaStatus mediaStatus () const

Notifier signal:

void mediaStatusChanged ( QMediaPlayer::MediaStatus status )

See also state.

muted : bool

This property holds the muted state of the current media.

The value will be true if the playback volume is muted; otherwise false.

Access functions:

bool isMuted () const
void setMuted ( bool muted )

Notifier signal:

void mutingChanged ( bool muted )

playbackRate : qreal

This property holds the playback rate of the current media.

This value is a multiplier applied to the media's standard play rate. By default this value is 1.0, indicating that the media is playing at the standard pace. Values higher than 1.0 will increase the rate of play. Values less than zero can be set and indicate the media will rewind at the multiplier of the standard pace.

Not all playback services support change of the playback rate. It is framework defined as to the status and quality of audio and video while fast forwarding or rewinding.

Access functions:

qreal playbackRate () const
void setPlaybackRate ( qreal rate )

Notifier signal:

void playbackRateChanged ( qreal rate )

position : qint64

This property holds the playback position of the current media.

The value is the current playback position, expressed in milliseconds since the beginning of the media. Periodically changes in the position will be indicated with the signal positionChanged(), the interval between updates can be set with QMediaObject's method setNotifyInterval().

Access functions:

qint64 position () const
void setPosition ( qint64 position )

Notifier signal:

void positionChanged ( qint64 position )

seekable : const bool

This property holds the seek-able status of the current media.

If seeking is supported this property will be true; false otherwise. The status of this property may change across the life time of the QMediaPlayer object, use the seekableChanged signal to monitor changes.

Access functions:

bool isSeekable () const

Notifier signal:

void seekableChanged ( bool seekable )

state : const State

This property holds the media player's playback state.

By default this property is QMediaPlayer::Stopped

Access functions:

State state () const

Notifier signal:

void stateChanged ( QMediaPlayer::State state )

See also mediaStatus(), play(), pause(), and stop().

videoAvailable : const bool

This property holds the video availability status for the current media.

If available, the QVideoWidget class can be used to view the video. As the life time of QMediaPlayer can be longer than the playback of one QMediaContent, this property may change over time, the videoAvailabilityChanged signal can be used to monitor it's status.

Access functions:

bool isVideoAvailable () const

Notifier signal:

void videoAvailabilityChanged ( bool videoAvailable )

See also QVideoWidget and QMediaContent.

volume : int

This property holds the current playback volume.

The playback volume is a linear in effect and the value can range from 0 - 100, values outside this range will be clamped.

Access functions:

int volume () const
void setVolume ( int volume )

Notifier signal:

void volumeChanged ( int volume )

Member Function Documentation

QMediaPlayer::QMediaPlayer ( QObject * parent = 0, Flags flags = 0, QMediaServiceProvider * provider = QMediaServiceProvider::defaultServiceProvider() )

Construct a QMediaPlayer that uses the playback service from provider, parented to parent and with flags.

If a playback service is not specified the system default will be used.

QMediaPlayer::~QMediaPlayer ()

Destroys the player object.

void QMediaPlayer::bufferStatusChanged ( int percentFilled )   [signal]

Signal the amount of the local buffer filled as a percentage by percentFilled.

void QMediaPlayer::durationChanged ( qint64 duration )   [signal]

Signal the duration of the content has changed to duration, expressed in milliseconds.

Error QMediaPlayer::error () const

Returns the current error state.

void QMediaPlayer::error ( QMediaPlayer::Error error )   [signal]

Signals that an error condition has occurred.

See also errorString().

QtMedia::SupportEstimate QMediaPlayer::hasSupport ( const QString & mimeType, const QStringList & codecs = QStringList(), Flags flags = 0 )   [static]

Returns the level of support a media player has for a mimeType and a set of codecs.

The flags argument allows additional requirements such as performance indicators to be specified.

void QMediaPlayer::mediaChanged ( const QMediaContent & media )   [signal]

Signals that the current playing content will be obtained from media.

See also media().

void QMediaPlayer::mediaStatusChanged ( QMediaPlayer::MediaStatus status )   [signal]

Signals that the status of the current media has changed.

See also mediaStatus().

const QIODevice * QMediaPlayer::mediaStream () const

Returns the stream source of media data.

This is only valid if a stream was passed to setMedia().

See also setMedia().

void QMediaPlayer::mutingChanged ( bool muted )   [signal]

Signal the mute state has changed to muted.

void QMediaPlayer::pause ()   [slot]

Pause playing the current source.

void QMediaPlayer::play ()   [slot]

Start or resume playing the current source.

void QMediaPlayer::playbackRateChanged ( qreal rate )   [signal]

Signals the playbackRate has changed to rate.

void QMediaPlayer::positionChanged ( qint64 position )   [signal]

Signal the position of the content has changed to position, expressed in milliseconds.

void QMediaPlayer::seekableChanged ( bool seekable )   [signal]

Signals the seekable status of the player object has changed.

void QMediaPlayer::stateChanged ( QMediaPlayer::State state )   [signal]

Signal the state of the Player object has changed.

void QMediaPlayer::stop ()   [slot]

Stop playing, and reset the play position to the beginning.

void QMediaPlayer::videoAvailabilityChanged ( bool videoAvailable )   [signal]

Signal the availability of visual content has changed to videoAvailable.

void QMediaPlayer::volumeChanged ( int volume )   [signal]

Signal the playback volume has changed to volume.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 80
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 6
Page suivante

Le Qt Labs au hasard

Logo

Améliorer les performances de Qt lors du rendu avec plus de SIMD

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt qtmobility-1.0-tp
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web