#include <Phonon/MediaObject>
Interface for media playback of a given URL.
This class is the most important class in Phonon. Use it to open a media file at an arbitrary location, a CD or DVD or to stream media data from the application to the backend.
This class controls the state (play, pause, stop, seek) and you can use it to get a lot of information about the media data.
Notice that most functions of this class are asynchronous. That means if you call play() the object only starts playing when the stateChanged() signal tells you that the object changed into PlayingState. The states you can expect are documented for those methods.
A common usage example is the following:
If you want to play more than one media file (one after another) you can either tell MediaObject about all those files
or provide the next file just in time:
Definition at line 84 of file mediaobject.h.
Public Slots | |
void | setTickInterval (qint32 newTickInterval) |
void | play () |
Requests playback of the media data to start. More... | |
void | pause () |
Requests playback to pause. More... | |
void | stop () |
Requests playback to stop. More... | |
void | seek (qint64 time) |
Requests a seek to the time indicated. More... | |
void | clear () |
Stops and removes all playing and enqueued media sources. More... | |
Public Slots inherited from QObject | |
void | deleteLater () |
Signals | |
void | stateChanged (Phonon::State newstate, Phonon::State oldstate) |
Emitted when the state of the MediaObject has changed. More... | |
void | tick (qint64 time) |
This signal gets emitted every tickInterval milliseconds. More... | |
void | metaDataChanged () |
This signal is emitted whenever the audio/video data that is being played is associated with new meta data. More... | |
void | seekableChanged (bool isSeekable) |
Emitted whenever the return value of isSeekable() changes. More... | |
void | hasVideoChanged (bool hasVideo) |
Emitted whenever the return value of hasVideo() changes. More... | |
void | bufferStatus (int percentFilled) |
Tells about the status of the buffer. More... | |
void | finished () |
Emitted when the object has finished playback. More... | |
void | currentSourceChanged (const Phonon::MediaSource &newSource) |
Emitted when the MediaObject makes a transition to the next MediaSource in the queue(). More... | |
void | aboutToFinish () |
Emitted before the playback of the whole queue stops. More... | |
void | prefinishMarkReached (qint32 msecToEnd) |
Emitted when there are only msecToEnd milliseconds left for playback. More... | |
void | totalTimeChanged (qint64 newTotalTime) |
This signal is emitted as soon as the total time of the media file is known or has changed. More... | |
Signals inherited from QObject | |
void | destroyed (QObject *=0) |
Public Member Functions | |
~MediaObject () | |
Destroys the MediaObject. More... | |
State | state () const |
Get the current state. More... | |
bool | hasVideo () const |
Check whether the media data includes a video stream. More... | |
bool | isSeekable () const |
Check whether the current media may be seeked. More... | |
qint32 | tickInterval () const |
QStringList | metaData (const QString &key) const |
Returns the strings associated with the given key . More... | |
QStringList | metaData (Phonon::MetaData key) const |
Returns the strings associated with the given key . More... | |
QMultiMap< QString, QString > | metaData () const |
Returns all meta data. More... | |
QString | errorString () const |
Returns a human-readable description of the last error that occurred. More... | |
ErrorType | errorType () const |
Tells your program what to do about the error. More... | |
MediaSource | currentSource () const |
Returns the current media source. More... | |
void | setCurrentSource (const MediaSource &source) |
Set the media source the MediaObject should use. More... | |
QList< MediaSource > | queue () const |
Returns the queued media sources. More... | |
void | setQueue (const QList< MediaSource > &sources) |
Set the MediaSources to play when the current media has finished. More... | |
void | setQueue (const QList< QUrl > &urls) |
Set the MediaSources to play when the current media has finished. More... | |
void | enqueue (const MediaSource &source) |
Appends one source to the queue. More... | |
void | enqueue (const QList< MediaSource > &sources) |
Appends multiple sources to the queue. More... | |
void | enqueue (const QList< QUrl > &urls) |
Appends multiple sources to the queue. More... | |
void | clearQueue () |
Clears the queue of sources. More... | |
qint64 | currentTime () const |
Get the current time (in milliseconds) of the file currently being played. More... | |
qint64 | totalTime () const |
Get the total time (in milliseconds) of the file currently being played. More... | |
qint64 | remainingTime () const |
Get the remaining time (in milliseconds) of the file currently being played. More... | |
qint32 | prefinishMark () const |
void | setPrefinishMark (qint32 msecToEnd) |
qint32 | transitionTime () const |
void | setTransitionTime (qint32 msec) |
Public Member Functions inherited from QObject | |
Q_INVOKABLE | QObject (QObject *parent=0) |
virtual | ~QObject () |
virtual bool | event (QEvent *) |
virtual bool | eventFilter (QObject *, QEvent *) |
QString | objectName () const |
void | setObjectName (const QString &name) |
bool | isWidgetType () const |
bool | signalsBlocked () const |
bool | blockSignals (bool b) |
QThread * | thread () const |
void | moveToThread (QThread *thread) |
int | startTimer (int interval) |
void | killTimer (int id) |
template<typename T > | |
T | findChild (const QString &aName=QString()) const |
template<typename T > | |
QList< T > | findChildren (const QString &aName=QString()) const |
template<typename T > | |
QList< T > | findChildren (const QRegExp &re) const |
const QObjectList & | children () const |
void | setParent (QObject *) |
void | installEventFilter (QObject *) |
void | removeEventFilter (QObject *) |
bool | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0) |
bool | disconnect (const QObject *receiver, const char *member=0) |
void | dumpObjectTree () |
void | dumpObjectInfo () |
bool | setProperty (const char *name, const QVariant &value) |
QVariant | property (const char *name) const |
QList< QByteArray > | dynamicPropertyNames () const |
void | setUserData (uint id, QObjectUserData *data) |
QObjectUserData * | userData (uint id) const |
QObject * | parent () const |
bool | inherits (const char *classname) const |
Public Member Functions inherited from MediaNode | |
virtual | ~MediaNode () |
bool | isValid () const |
Tells whether the backend provides an implementation of this class. More... | |
QList< Path > | inputPaths () const |
QList< Path > | outputPaths () const |
Properties | |
qint32 | transitionTime |
Defines the time between media sources. More... | |
qint32 | prefinishMark |
Get a signal before playback finishes. More... | |
qint32 | tickInterval |
The time interval in milliseconds between two ticks. More... | |
Properties inherited from QObject | |
QString | objectName |
Friends | |
class | FrontendInterfacePrivate |
Additional Inherited Members | |
Static Public Member Functions inherited from QObject | |
static bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
static bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static uint | registerUserData () |
Protected Member Functions inherited from QObject | |
QObject * | sender () const |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
virtual void | timerEvent (QTimerEvent *) |
virtual void | childEvent (QChildEvent *) |
virtual void | customEvent (QEvent *) |
virtual void | connectNotify (const char *signal) |
virtual void | disconnectNotify (const char *signal) |
QObject (QObjectPrivate &dd, QObject *parent=0) | |
Protected Member Functions inherited from MediaNode | |
MediaNode (MediaNodePrivate &dd) | |
Protected Attributes inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Protected Attributes inherited from MediaNode | |
MediaNodePrivate *const | k_ptr |
Static Protected Attributes inherited from QObject | |
static const QMetaObject | staticQtMetaObject |
~MediaObject | ( | ) |
Destroys the MediaObject.
State state | ( | ) | const |
bool hasVideo | ( | ) | const |
Check whether the media data includes a video stream.
true
if the media contains video data. false
otherwise.bool isSeekable | ( | ) | const |
Check whether the current media may be seeked.
true
when the current media may be seeked. false
otherwise.qint32 tickInterval | ( | ) | const |
QStringList metaData | ( | const QString & | key | ) | const |
Returns the strings associated with the given key
.
Backends should use the keys specified in the Ogg Vorbis documentation: http://xiph.org/vorbis/doc/v-comment.html
Therefore the following should work with every backend:
A typical usage looks like this:
For Audio CDs you can query
to get a DiscID hash that you can use with the MusicBrainz service: http://musicbrainz.org/doc/ClientHOWTO
QStringList metaData | ( | Phonon::MetaData | key | ) | const |
Returns the strings associated with the given key
.
Same as above except that the keys are defined in the Phonon::MetaData enum.
QString errorString | ( | ) | const |
Returns a human-readable description of the last error that occurred.
ErrorType errorType | ( | ) | const |
Tells your program what to do about the error.
MediaSource currentSource | ( | ) | const |
Returns the current media source.
void setCurrentSource | ( | const MediaSource & | source | ) |
Set the media source the MediaObject should use.
source | The MediaSource object to the media data. You can just as well use a QUrl or QString (for a local file) here. Setting an empty (invalid) source, will stop and remove the current source. |
QList<MediaSource> queue | ( | ) | const |
Returns the queued media sources.
This list does not include the current source (returned by currentSource).
void setQueue | ( | const QList< MediaSource > & | sources | ) |
Set the MediaSources to play when the current media has finished.
This function will overwrite the current queue.
Set the MediaSources to play when the current media has finished.
This function overwrites the current queue.
void enqueue | ( | const MediaSource & | source | ) |
Appends one source to the queue.
Use this function to provide the next source just in time after the aboutToFinish signal was emitted.
void enqueue | ( | const QList< MediaSource > & | sources | ) |
Appends multiple sources to the queue.
Appends multiple sources to the queue.
void clearQueue | ( | ) |
Clears the queue of sources.
qint64 currentTime | ( | ) | const |
Get the current time (in milliseconds) of the file currently being played.
qint64 totalTime | ( | ) | const |
Get the total time (in milliseconds) of the file currently being played.
qint64 remainingTime | ( | ) | const |
Get the remaining time (in milliseconds) of the file currently being played.
qint32 prefinishMark | ( | ) | const |
qint32 transitionTime | ( | ) | const |
|
slot |
Requests playback of the media data to start.
Playback only starts when stateChanged() signals that it goes into PlayingState, though.
|
slot |
Requests playback to pause.
If it was paused before nothing changes.
|
slot |
Requests playback to stop.
If it was stopped before nothing changes.
Requests a seek to the time indicated.
You can only seek if state() == PlayingState, BufferingState or PausedState.
The call is asynchronous, so currentTime can still be the old value right after this method was called. If all you need is a slider that shows the current position and allows the user to seek use the class SeekSlider.
time | The time in milliseconds where to continue playing. |
|
slot |
Stops and removes all playing and enqueued media sources.
|
signal |
Emitted when the state of the MediaObject has changed.
newstate | The state the Player is in now. |
oldstate | The state the Player was in before. |
This signal gets emitted every tickInterval milliseconds.
time | The position of the media file in milliseconds. |
|
signal |
This signal is emitted whenever the audio/video data that is being played is associated with new meta data.
E.g. for radio streams this happens when the next song is played.
You can get the new meta data with the metaData methods.
|
signal |
Emitted whenever the return value of isSeekable() changes.
Normally you'll check isSeekable() first and then let this signal tell you whether seeking is possible now or not. That way you don't have to poll isSeekable().
|
signal |
Emitted whenever the return value of hasVideo() changes.
Normally you'll check hasVideo() first and then let this signal tell you whether video is available now or not. That way you don't have to poll hasVideo().
hasVideo | true The stream contains video and adding a VideoWidget will show a video. false There is no video data in the stream and adding a VideoWidget will show an empty (black) VideoWidget. |
Tells about the status of the buffer.
You can use this signal to show a progress bar to the user when in BufferingState:
percentFilled | A number between 0 and 100 telling you how much the buffer is filled. |
|
signal |
Emitted when the object has finished playback.
It is not emitted if you call stop(), pause() or load(), but only on end-of-queue or a critical error.
|
signal |
Emitted when the MediaObject makes a transition to the next MediaSource in the queue().
In other words, it is emitted when an individual MediaSource is finished.
newSource | The source that starts to play at the time the signal is emitted. |
|
signal |
Emitted before the playback of the whole queue stops.
When this signal is emitted you still have time to provide the next MediaSource (using enqueue()) so that playback continues.
This signal can be used to provide the next MediaSource just in time for the transition still to work.
Emitted when there are only msecToEnd
milliseconds left for playback.
msecToEnd | The remaining time until the playback queue finishes. |
This signal is emitted as soon as the total time of the media file is known or has changed.
For most non-local media data the total time of the media can only be known after some time. Initially the totalTime function can not return useful information. You have to wait for this signal to know the real total time.
newTotalTime | The length of the media file in milliseconds. |
|
friend |
Definition at line 86 of file mediaobject.h.
|
readwrite |
Defines the time between media sources.
A positive transition time defines a gap of silence between queued media sources.
A transition time of 0 ms requests gapless playback (sample precise queueing of the next source).
A negative transition time defines a crossfade between the queued media sources.
Defaults to 0 (gapless playback).
Definition at line 106 of file mediaobject.h.
|
readwrite |
Get a signal before playback finishes.
This property specifies the time in milliseconds the prefinishMarkReached signal is emitted before the playback finishes. A value of 0
disables the signal.
Defaults to 0
(disabled).
Definition at line 127 of file mediaobject.h.
|
readwrite |
The time interval in milliseconds between two ticks.
The tick interval is the time that elapses between the emission of two tick signals. If you set the interval to 0
the tick signal gets disabled.
Defaults to 0
(disabled).
Definition at line 154 of file mediaobject.h.