Phonon.MediaObject

概要

函数

信号

详细描述

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() 函数。

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() 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() .

另请参阅

Symbian Platform Security Requirements Phonon.MediaSource Phonon.AudioOutput VideoWidget 音乐播放器范例 Phonon Overview Phonon.VideoPlayer Phonon.createPlayer() Phonon Module

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

Stops and removes all playing and enqueued media sources.

另请参阅

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

PySide.phonon.Phonon.MediaObject. clearQueue ( )

Clears the queue of media sources.

另请参阅

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

PySide.phonon.Phonon.MediaObject. currentSource ( )
返回类型: 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.

另请参阅

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

PySide.phonon.Phonon.MediaObject. currentSourceChanged ( newSource )
参数: newSource PySide.phonon.Phonon::MediaSource
PySide.phonon.Phonon.MediaObject. currentTime ( )
返回类型: PySide.QtCore.qint64

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

另请参阅

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

PySide.phonon.Phonon.MediaObject. enqueue ( sources )
参数: sources
PySide.phonon.Phonon.MediaObject. enqueue ( urls )
参数: urls
PySide.phonon.Phonon.MediaObject. enqueue ( source )
参数: source PySide.phonon.Phonon::MediaSource

追加 source to the queue.

You can use this function to provide the next source after the PySide.phonon.Phonon::MediaObject.aboutToFinish() 信号已被发射。

另请参阅

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

PySide.phonon.Phonon.MediaObject. errorString ( )
返回类型: 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 后端

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.

另请参阅

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

PySide.phonon.Phonon.MediaObject. errorType ( )
返回类型: 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 .

另请参阅

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

PySide.phonon.Phonon.MediaObject. finished ( )
PySide.phonon.Phonon.MediaObject. hasVideo ( )
返回类型: PySide.QtCore.bool

Check whether the current media source includes a video stream.

警告

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>
											

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

另请参阅

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

PySide.phonon.Phonon.MediaObject. hasVideoChanged ( hasVideo )
参数: hasVideo PySide.QtCore.bool
PySide.phonon.Phonon.MediaObject. isSeekable ( )
返回类型: PySide.QtCore.bool

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

警告

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>
											

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

另请参阅

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

PySide.phonon.Phonon.MediaObject. metaData ( key )
参数: key – unicode
返回类型: 字符串列表

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() 信号被发射。

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 )
参数: key PySide.phonon.Phonon.MetaData
返回类型: 字符串列表
PySide.phonon.Phonon.MediaObject. metaData ( )
返回类型:

Returns all meta data in a multi map.

另请参阅

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.

另请参阅

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 ,什么都不发生。

另请参阅

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

PySide.phonon.Phonon.MediaObject. prefinishMark ( )
返回类型: 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 .

默认为 0 (disabled).

警告

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() .

另请参阅

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

PySide.phonon.Phonon.MediaObject. prefinishMarkReached ( msecToEnd )
参数: msecToEnd PySide.QtCore.qint32
PySide.phonon.Phonon.MediaObject. queue ( )
返回类型:

Returns the queued media sources.

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

另请参阅

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

PySide.phonon.Phonon.MediaObject. remainingTime ( )
返回类型: PySide.QtCore.qint64

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

Returns the remaining time in milliseconds.

另请参阅

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

PySide.phonon.Phonon.MediaObject. seek ( time )
参数: time PySide.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.

另请参阅

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

PySide.phonon.Phonon.MediaObject. seekableChanged ( isSeekable )
参数: isSeekable PySide.QtCore.bool
PySide.phonon.Phonon.MediaObject. setCurrentSource ( source )
参数: source PySide.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 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.

举例说明:

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

另请参阅

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

PySide.phonon.Phonon.MediaObject. setPrefinishMark ( msecToEnd )
参数: msecToEnd 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 .

默认为 0 (disabled).

警告

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() .

另请参阅

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

PySide.phonon.Phonon.MediaObject. setQueue ( urls )
参数: urls
PySide.phonon.Phonon.MediaObject. setQueue ( sources )
参数: sources
PySide.phonon.Phonon.MediaObject. setTickInterval ( newTickInterval )
参数: newTickInterval PySide.QtCore.qint32

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

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.

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.

默认为 0 (disabled).

警告

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>
											

另请参阅

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

PySide.phonon.Phonon.MediaObject. setTransitionTime ( msec )
参数: msec 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).

警告

This feature might not work reliably with every backend.

PySide.phonon.Phonon.MediaObject. state ( )
返回类型: PySide.phonon.Phonon.State

返回当前 Phonon.State of the object.

另请参阅

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

PySide.phonon.Phonon.MediaObject. stateChanged ( newstate , oldstate )
参数:
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.

另请参阅

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

PySide.phonon.Phonon.MediaObject. tick ( time )
参数: time PySide.QtCore.qint64
PySide.phonon.Phonon.MediaObject. tickInterval ( )
返回类型: PySide.QtCore.qint32

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

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.

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.

默认为 0 (disabled).

警告

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>
											

另请参阅

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

PySide.phonon.Phonon.MediaObject. totalTime ( )
返回类型: PySide.QtCore.qint64

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

Returns the total time in milliseconds.

警告

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

另请参阅

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

PySide.phonon.Phonon.MediaObject. totalTimeChanged ( newTotalTime )
参数: newTotalTime PySide.QtCore.qint64
PySide.phonon.Phonon.MediaObject. transitionTime ( )
返回类型: 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).

警告

This feature might not work reliably with every backend.