Phonon.MediaObject

Synopsis

Functions

Slots

Signals

Detailed Description

The MediaObject class provides an interface for media playback.

The media object manages a Phonon.MediaSource , which supplies the media object with multimedia content, e.g., from a file. A playback in Phonon is always started by calling the PySide.phonon.Phonon.MediaObject.play() function.

The state of play (play, pause, stop, seek) is controlled by the media object, and you can also query the current PySide.phonon.Phonon.MediaObject.state() . It keeps track of the playback position in the media stream, and emits the PySide.phonon.Phonon.MediaObject.tick() signal when the current position in the stream changes.

Notice that most functions of this class are asynchronous, so you cannot rely on that a state is entered after a function call before you receive the PySide.phonon.Phonon.MediaObject.stateChanged() signal. The description of the Phonon.State enum gives a description of the different states.

Before PySide.phonon.Phonon::MediaObject.play() is called, the media object should be connected to output nodes , which outputs the media to the underlying hardware. The output nodes required are dependent on the contents of the multimedia file that is played back. Phonon has currently two output nodes: the Phonon.AudioOutput for audio content and Phonon.VideoWidget for video content. If a Phonon.MediaSource contains both audio and video, both nodes need to be connected to the media object.

mediaObject = Phonon.MediaObject(self)

videoWidget = Phonon.VideoWidget(self)
Phonon.createPath(mediaObject, videoWidget)

audioOutput = Phonon.AudioOutput(Phonon.VideoCategory, self)
Phonon.createPath(mediaObject, audioOutput)
mediaObject.play()

The media object can queue sources for playback. When it has finished to play one source, it will start playing the next in the queue; the new source is then removed from the queue. The queue can be altered at any time.

<Code snippet "doc/src/snippets/code/doc_src_phonon-api.cpp:7" not found>

You can also make use of the PySide.phonon.Phonon.MediaObject.aboutToFinish() signal, which is guaranteed to be emitted in time for altering the queue.

<Code snippet "doc/src/snippets/code/doc_src_phonon-api.cpp:8" not found>

When playback is finishing, i.e., when a media source has been played to the end and the queue is empty, several signals are emitted. First, the media object will emit PySide.phonon.Phonon::MediaObject.aboutToFinish() - shortly before the playback has finished - and then PySide.phonon.Phonon::MediaObject.finished() . The PySide.phonon.Phonon::MediaObject.stateChanged() signal will also be emitted with PausedState , which is the state the media object takes when the playback is finished. If you wish to enter another state, you can connect a slot to PySide.phonon.Phonon::MediaObject.finished() and set a new state there.

The media object resolves the meta information, such as title, artist, and album. The meta data is not resolved immediately after a new source is provided, but will be resolved before the object leaves the LoadingState . The data is queried by string keys - which should follow the Ogg Vorbis specification http://xiph.org/vorbis/doc/v-comment.html - or by using the Phonon.MetaData enum. The data available will depend on the type and content of the individual media files. PySide.phonon.Phonon::MediaObject.metaDataChanged() will be emitted when the media object has resolved new meta data.

Errors encountered during playback and loading of media sources are reported by emitting a state changed signal with ErrorState . The severity of the error can be queried by the Phonon.ErrorType . With a NormalError , it might be possible to continue the playback, for instance, if only audio playback fails for a media source which also has video. A FatalError indicates that Phonon cannot continue playback of the current source, but it is possible to try with a different one. A user readable error message is given by PySide.phonon.Phonon::MediaObject.errorString() .

See also

Symbian Platform Security Requirements Phonon.MediaSource Phonon.AudioOutput VideoWidget Music Player Example Phonon Overview Phonon.VideoPlayer Phonon.createPlayer() Phonon Module

class PySide.phonon.Phonon.MediaObject([parent=None])
Parameters:parentPySide.QtCore.QObject
PySide.phonon.Phonon.MediaObject.aboutToFinish()
PySide.phonon.Phonon.MediaObject.bufferStatus(percentFilled)
Parameters:percentFilledPySide.QtCore.int
PySide.phonon.Phonon.MediaObject.clear()

Stops and removes all playing and enqueued media sources.

See also

PySide.phonon.Phonon::MediaObject.setCurrentSource()

PySide.phonon.Phonon.MediaObject.clearQueue()

Clears the queue of media sources.

See also

PySide.phonon.Phonon::MediaObject.queue() PySide.phonon.Phonon::MediaObject.enqueue()

PySide.phonon.Phonon.MediaObject.currentSource()
Return type:PySide.phonon.Phonon::MediaSource

Returns the current media source, i.e., the media source that is being played back. The current source is either set with PySide.phonon.Phonon::MediaObject.setCurrentSource() or taken from the media PySide.phonon.Phonon::MediaObject.queue() when a media source has finished playing.

See also

PySide.phonon.Phonon::MediaObject.setCurrentSource()

PySide.phonon.Phonon.MediaObject.currentSourceChanged(newSource)
Parameters:newSourcePySide.phonon.Phonon::MediaSource
PySide.phonon.Phonon.MediaObject.currentTime()
Return type:PySide.QtCore.qint64

Returns the current time (in milliseconds), i.e., position in the media stream, of the file currently being played.

See also

PySide.phonon.Phonon::MediaObject.tick() PySide.phonon.Phonon::MediaObject.totalTime() PySide.phonon.Phonon::MediaObject.remainingTime()

PySide.phonon.Phonon.MediaObject.enqueue(sources)
Parameters:sources
PySide.phonon.Phonon.MediaObject.enqueue(urls)
Parameters:urls
PySide.phonon.Phonon.MediaObject.enqueue(source)
Parameters:sourcePySide.phonon.Phonon::MediaSource

Appends source to the queue.

You can use this function to provide the next source after the PySide.phonon.Phonon::MediaObject.aboutToFinish() signal has been emitted.

See also

PySide.phonon.Phonon::MediaObject.aboutToFinish() PySide.phonon.Phonon::MediaObject.setQueue() PySide.phonon.Phonon::MediaObject.clearQueue()

PySide.phonon.Phonon.MediaObject.errorString()
Return type:unicode

Returns a human-readable description of the last error that occurred. The strings given may vary between backends.

The error description can be used to give a message to the user - and the developer - when the PySide.phonon.Phonon::MediaObject.stateChanged() signal is emitted with ErrorState .

Qt Backends

On Windows, Qt fetches its error messages from the DirectShow backend. This usually includes an error number, which can be looked up in the DirectShow documentation: http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dx81_c/directx_cpp/htm/errorandsuccesscodes.asp.

On Linux and Mac, the error strings are not fetched directly from the backend, but are created in the backend.

See also

Phonon.ErrorState PySide.phonon.Phonon::MediaObject.stateChanged()

PySide.phonon.Phonon.MediaObject.errorType()
Return type:PySide.phonon.Phonon.ErrorType

Tells your program what to do about the last error that occurred. Use this function after receiving a PySide.phonon.Phonon::MediaObject.stateChanged() signal with ErrorState .

See also

Phonon.ErrorType Phonon.ErrorState PySide.phonon.Phonon::MediaObject.stateChanged()

PySide.phonon.Phonon.MediaObject.finished()
PySide.phonon.Phonon.MediaObject.hasVideo()
Return type:PySide.QtCore.bool

Check whether the current media source includes a video stream.

Warning

This information is not resolved immediately after a media object gets a new source. Listen to the PySide.phonon.Phonon::MediaObject.hasVideoChanged() signal instead.

<Code snippet "doc/src/snippets/code/doc_src_phonon-api.cpp:11" not found>

Returns true if the media contains video data; otherwise, returns false .

See also

PySide.phonon.Phonon::MediaObject.hasVideoChanged()

PySide.phonon.Phonon.MediaObject.hasVideoChanged(hasVideo)
Parameters:hasVideoPySide.QtCore.bool
PySide.phonon.Phonon.MediaObject.isSeekable()
Return type:PySide.QtCore.bool

Check whether it is possible to seek, i.e., change the playback position in the media stream.

Warning

This information is not solved immediately after the media object gets a new media source. The PySide.phonon.Phonon::MediaObject.hasVideoChanged() signal is emitted after this information is available.

<Code snippet "doc/src/snippets/code/doc_src_phonon-api.cpp:12" not found>

Returns true if the current media may be seeked; otherwise, returns false .

See also

PySide.phonon.Phonon::MediaObject.seekableChanged()

PySide.phonon.Phonon.MediaObject.metaData(key)
Parameters:key – unicode
Return type:list of strings

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:

Note that meta data is not resolved before the metaDataChanged() signal is emitted.

A typical usage looks like this:

<Code snippet "doc/src/snippets/code/doc_src_phonon-api.cpp:13" not found>
PySide.phonon.Phonon.MediaObject.metaData(key)
Parameters:keyPySide.phonon.Phonon.MetaData
Return type:list of strings
PySide.phonon.Phonon.MediaObject.metaData()
Return type:

Returns all meta data in a multi map.

See also

PySide.phonon.Phonon::MediaObject.metaDataChanged()

PySide.phonon.Phonon.MediaObject.metaDataChanged()
PySide.phonon.Phonon.MediaObject.pause()

Requests playback to pause, and the media object to enter the PausedState . If it was paused already, nothing changes.

This function is asynchronous and the media might not be paused immediately.

See also

PySide.phonon.Phonon::MediaObject.play() PySide.phonon.Phonon::MediaObject.stop() PySide.phonon.Phonon::MediaObject.stateChanged()

PySide.phonon.Phonon.MediaObject.play()

Requests playback of the media data to start.

Playback starts when the PySide.phonon.Phonon::MediaObject.stateChanged() signal is emitted with PlayingState .

If the media object is already in a PlayingState , nothing happens.

See also

PySide.phonon.Phonon::MediaObject.stop() PySide.phonon.Phonon::MediaObject.pause() PySide.phonon.Phonon::MediaObject.stateChanged()

PySide.phonon.Phonon.MediaObject.prefinishMark()
Return type:PySide.QtCore.qint32

This property holds the time when the prefinishMarkReached signal is emitted before playback ends..

This property specifies the time in milliseconds the PySide.phonon.Phonon::MediaObject.prefinishMarkReached() signal is emitted before the playback finishes. A value of 0 disables the signal. The signal is only emitted for the last source in the media queue .

Defaults to 0 (disabled).

Warning

For some media data the total time cannot be determined accurately, therefore the accuracy of the prefinishMarkReached signal can be bad sometimes. Still, it is better to use this method than to look at PySide.phonon.Phonon::MediaObject.totalTime() and PySide.phonon.Phonon::MediaObject.currentTime() to emulate the behavior because the backend might have more information available than your application does through PySide.phonon.Phonon::MediaObject.totalTime() and PySide.phonon.Phonon::MediaObject.currentTime() .

See also

PySide.phonon.Phonon::MediaObject.prefinishMarkReached()

PySide.phonon.Phonon.MediaObject.prefinishMarkReached(msecToEnd)
Parameters:msecToEndPySide.QtCore.qint32
PySide.phonon.Phonon.MediaObject.queue()
Return type:

Returns the queued media sources.

This does list does not include the current source, returned by PySide.phonon.Phonon::MediaObject.currentSource() .

See also

PySide.phonon.Phonon::MediaObject.setQueue() PySide.phonon.Phonon::MediaObject.enqueue()

PySide.phonon.Phonon.MediaObject.remainingTime()
Return type:PySide.QtCore.qint64

Get the remaining time (in milliseconds) of the file currently being played.

Returns the remaining time in milliseconds.

See also

PySide.phonon.Phonon::MediaObject.totalTime() PySide.phonon.Phonon::MediaObject.currentTime() PySide.phonon.Phonon::MediaObject.totalTimeChanged()

PySide.phonon.Phonon.MediaObject.seek(time)
Parameters:timePySide.QtCore.qint64

Requests a seek to the time indicated, specified in milliseconds.

You can only seek if PySide.phonon.Phonon::MediaObject.state() is 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 .

If the current source of the media object is not seekable, calls to this functions do nothing.

See also

SeekSlider PySide.phonon.Phonon::MediaObject.tick()

PySide.phonon.Phonon.MediaObject.seekableChanged(isSeekable)
Parameters:isSeekablePySide.QtCore.bool
PySide.phonon.Phonon.MediaObject.setCurrentSource(source)
Parameters:sourcePySide.phonon.Phonon::MediaSource

Set the media source the MediaObject should use.

After the media object receives a new source, it will enter the LoadingState . When it is ready to play, it enters the StoppedState unless another state has been requested, e.g., by calling PySide.phonon.Phonon::MediaObject.play() .

source is the MediaSource object to the media data. You can just as well use a PySide.QtCore.QUrl or PySide.QtCore.QString (for a local file) here.

We show an example:

<Code snippet "doc/src/snippets/code/doc_src_phonon-api.cpp:14" not found>

See also

PySide.phonon.Phonon::MediaObject.currentSource() MediaSource

PySide.phonon.Phonon.MediaObject.setPrefinishMark(msecToEnd)
Parameters:msecToEndPySide.QtCore.qint32

This property holds the time when the prefinishMarkReached signal is emitted before playback ends..

This property specifies the time in milliseconds the PySide.phonon.Phonon::MediaObject.prefinishMarkReached() signal is emitted before the playback finishes. A value of 0 disables the signal. The signal is only emitted for the last source in the media queue .

Defaults to 0 (disabled).

Warning

For some media data the total time cannot be determined accurately, therefore the accuracy of the prefinishMarkReached signal can be bad sometimes. Still, it is better to use this method than to look at PySide.phonon.Phonon::MediaObject.totalTime() and PySide.phonon.Phonon::MediaObject.currentTime() to emulate the behavior because the backend might have more information available than your application does through PySide.phonon.Phonon::MediaObject.totalTime() and PySide.phonon.Phonon::MediaObject.currentTime() .

See also

PySide.phonon.Phonon::MediaObject.prefinishMarkReached()

PySide.phonon.Phonon.MediaObject.setQueue(urls)
Parameters:urls
PySide.phonon.Phonon.MediaObject.setQueue(sources)
Parameters:sources
PySide.phonon.Phonon.MediaObject.setTickInterval(newTickInterval)
Parameters:newTickIntervalPySide.QtCore.qint32

This property holds The time interval in milliseconds between two ticks..

The PySide.phonon.Phonon::MediaObject.tick() signal is emitted continuously during playback. 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.

The PySide.phonon.Phonon::MediaObject.tick() signal can, for instance, be used to update widgets that show the current position in the playback of a media source.

Defaults to 0 (disabled).

Warning

The back-end is free to choose a different tick interval close to what you asked for. This means that the following code may fail:

<Code snippet "doc/src/snippets/code/doc_src_phonon-api.cpp:9" not found>

On the other hand the following is guaranteed:

<Code snippet "doc/src/snippets/code/doc_src_phonon-api.cpp:10" not found>

See also

PySide.phonon.Phonon::MediaObject.tick()

PySide.phonon.Phonon.MediaObject.setTransitionTime(msec)
Parameters:msecPySide.QtCore.qint32

This property Defines the time between playback of two media sources in the media queue..

A positive transition time defines a gap of silence between queued media sources.

A transition time of 0 ms requests gapless playback (i.e., the next source in the media queue starts immediately after the playback of the current source finishes).

A negative transition time defines a crossfade between the queued media sources.

Defaults to 0 (gapless playback).

Warning

This feature might not work reliably with every backend.

PySide.phonon.Phonon.MediaObject.state()
Return type:PySide.phonon.Phonon.State

Returns the current Phonon.State of the object.

See also

Phonon.State PySide.phonon.Phonon::MediaObject.stateChanged()

PySide.phonon.Phonon.MediaObject.stateChanged(newstate, oldstate)
Parameters:
PySide.phonon.Phonon.MediaObject.stop()

Requests playback to stop, and the media object to enter the StoppedState . If it was stopped before nothing changes.

This function is asynchronous and the media might not be stopped immediately.

See also

PySide.phonon.Phonon::MediaObject.play() PySide.phonon.Phonon::MediaObject.pause() PySide.phonon.Phonon::MediaObject.stateChanged()

PySide.phonon.Phonon.MediaObject.tick(time)
Parameters:timePySide.QtCore.qint64
PySide.phonon.Phonon.MediaObject.tickInterval()
Return type:PySide.QtCore.qint32

This property holds The time interval in milliseconds between two ticks..

The PySide.phonon.Phonon::MediaObject.tick() signal is emitted continuously during playback. 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.

The PySide.phonon.Phonon::MediaObject.tick() signal can, for instance, be used to update widgets that show the current position in the playback of a media source.

Defaults to 0 (disabled).

Warning

The back-end is free to choose a different tick interval close to what you asked for. This means that the following code may fail:

<Code snippet "doc/src/snippets/code/doc_src_phonon-api.cpp:9" not found>

On the other hand the following is guaranteed:

<Code snippet "doc/src/snippets/code/doc_src_phonon-api.cpp:10" not found>

See also

PySide.phonon.Phonon::MediaObject.tick()

PySide.phonon.Phonon.MediaObject.totalTime()
Return type:PySide.QtCore.qint64

Get the total time (in milliseconds) of the file currently being played.

Returns the total time in milliseconds.

Warning

The total time is not defined before the media object enters the LoadingState .

See also

PySide.phonon.Phonon::MediaObject.totalTimeChanged()

PySide.phonon.Phonon.MediaObject.totalTimeChanged(newTotalTime)
Parameters:newTotalTimePySide.QtCore.qint64
PySide.phonon.Phonon.MediaObject.transitionTime()
Return type:PySide.QtCore.qint32

This property Defines the time between playback of two media sources in the media queue..

A positive transition time defines a gap of silence between queued media sources.

A transition time of 0 ms requests gapless playback (i.e., the next source in the media queue starts immediately after the playback of the current source finishes).

A negative transition time defines a crossfade between the queued media sources.

Defaults to 0 (gapless playback).

Warning

This feature might not work reliably with every backend.