Phonon.AbstractMediaStream

Synopsis

Functions

Virtual functions

Detailed Description

The AbstractMediaStream class is the base class for custom media data streams.

This class is subclassed to provide custom data streams for Phonon.MediaSource s.

The Phonon.MediaSource knows how to handle the most common media sources, such as files and CD. If you need to fetch multimedia from other sources, you can reimplement this class, which can be used by a Phonon.MediaSource .

When a backend needs more data from the stream, PySide.phonon.Phonon::AbstractMediaStream.needData() will be called. You must then use PySide.phonon.Phonon::AbstractMediaStream.writeData() to write the data to the backend. You can either write one time and wait for a new PySide.phonon.Phonon::AbstractMediaStream.needData() call, or continue to write data until you receive an PySide.phonon.Phonon::AbstractMediaStream.enoughData() call. When the stream is at its end, call PySide.phonon.Phonon::AbstractMediaStream.endOfData() instead of PySide.phonon.Phonon::AbstractMediaStream.writeData() .

Before the custom stream is passed to a Phonon.MediaSource , PySide.phonon.Phonon::AbstractMediaStream.setStreamSize() needs to be called, and also PySide.phonon.Phonon::AbstractMediaStream.setStreamSeekable() (if the stream is seekable). A good place to do this work is in the constructor. A seekable stream must also reimplement PySide.phonon.Phonon::AbstractMediaStream.seekStream() .

We show two examples. The first writes data repeatedly until it receives the PySide.phonon.Phonon::AbstractMediaStream.enoughData() call, while the second only writes once and waits for a new PySide.phonon.Phonon::AbstractMediaStream.needData() call.

Example where data is written repeatedly.

class PushStream (AbstractMediaStream):
    def __init__(self, parent = None):
        AbstractMediaStream.__init(self, parent)
        self.timer = QTimer(self)
        self.setStreamSize(self.getMediaStreamSize())

        self.timer.timeout.connect(self.moreData)
        self.timer.setInterval(0)

    @Slot()
    def moreData(self):
        data = self.getMediaData()
        if data.isEmpty():
            self.endOfData()
        else:
            self.writeData(data)

    def needData(self):
        self.timer.start()
        self.moreData()

    def enoughData(self):
        self.timer.stop()

Example where data is written once:

class PushStream (AbstractMediaStream):
    def __init__(self, parent = None):
        AbstractMediaStream.__init(self, parent)
        self.setStreamSize(self.getMediaStreamSize())

    @Slot()
    def needData(self):
        data = self.getMediaData()
        if data.isEmpty():
            self.endOfData()
        else:
            self.writeData(data)

See also

Phonon.MediaSource Phonon.MediaObject

class PySide.phonon.Phonon.AbstractMediaStream([parent=None])
Parameters:parentPySide.QtCore.QObject

Constructs an AbstractMediaStream object with the given parent .

PySide.phonon.Phonon.AbstractMediaStream.endOfData()

Tells the backend that the media data stream is at its end.

Warning

Don’t call this function before the first PySide.phonon.Phonon::AbstractMediaStream.needData() is emitted.

See also

PySide.phonon.Phonon::AbstractMediaStream.writeData() PySide.phonon.Phonon::AbstractMediaStream.needData()

PySide.phonon.Phonon.AbstractMediaStream.enoughData()

If your stream is a push stream, reimplement this function to be notified when the backend has enough data and your stream object may take a break.

This method is important for pushing data to the backend in order to not fill the backend buffer unnecessarily.

See also

PySide.phonon.Phonon::AbstractMediaStream.needData()

PySide.phonon.Phonon.AbstractMediaStream.error(errorType, errorString)
Parameters:
PySide.phonon.Phonon.AbstractMediaStream.needData()

Reimplement this function to be notified when the backend needs data.

When this function is called you should write data to the backend (See PySide.phonon.Phonon::AbstractMediaStream.writeData() ).

See also

PySide.phonon.Phonon::AbstractMediaStream.writeData() PySide.phonon.Phonon::AbstractMediaStream.endOfData() PySide.phonon.Phonon::AbstractMediaStream.enoughData()

PySide.phonon.Phonon.AbstractMediaStream.reset()

Reimplement this function to reset the stream. Subsequent calls to writeData should start from the first position of the data unless a seek is requested.

The function is necessary for the case where a non-seekable MediaStream is played more than once. For a seekable stream the implementation can simply call

self.seekStream(0)

See also

PySide.phonon.Phonon::AbstractMediaStream.writeData() PySide.phonon.Phonon::AbstractMediaStream.needData()

PySide.phonon.Phonon.AbstractMediaStream.seekStream(offset)
Parameters:offsetPySide.QtCore.qint64

Reimplement this function if your stream is seekable.

When this function is called the next call to writeData has to be at the requested offset .

Warning

Do not call the parent implementation.

See also

PySide.phonon.Phonon::AbstractMediaStream.setStreamSeekable() PySide.phonon.Phonon::AbstractMediaStream.streamSeekable() PySide.phonon.Phonon::AbstractMediaStream.needData()

PySide.phonon.Phonon.AbstractMediaStream.setStreamSeekable(arg__1)
Parameters:arg__1PySide.QtCore.bool

Sets whether your data stream is seekable. s should be true if the stream is seekable; otherwise false.

Defaults to false .

If you set this to true you have to implement the PySide.phonon.Phonon::AbstractMediaStream.seekStream() function.

See also

PySide.phonon.Phonon::AbstractMediaStream.streamSeekable()

PySide.phonon.Phonon.AbstractMediaStream.setStreamSize(arg__1)
Parameters:arg__1PySide.QtCore.qint64

Sets the size of the stream in number of bytes.

A negative value means that the length of the stream cannot be known.

Defaults to 0.

This function has to be called. A backend will not call PySide.phonon.Phonon::AbstractMediaStream.needData() until the stream size is set.

See also

PySide.phonon.Phonon::AbstractMediaStream.streamSize()

PySide.phonon.Phonon.AbstractMediaStream.streamSeekable()
Return type:PySide.QtCore.bool

Returns whether your data stream is set as seekable.

Defaults to false .

See also

PySide.phonon.Phonon::AbstractMediaStream.setStreamSeekable()

PySide.phonon.Phonon.AbstractMediaStream.streamSize()
Return type:PySide.QtCore.qint64

Returns the stream size that was set with PySide.phonon.Phonon::AbstractMediaStream.setStreamSize() .

A negative value means that the length of the stream cannot be known.

Defaults to 0.

See also

PySide.phonon.Phonon::AbstractMediaStream.setStreamSize()

PySide.phonon.Phonon.AbstractMediaStream.writeData(data)
Parameters:dataPySide.QtCore.QByteArray

Sends the media data to the backend for decoding.

Use this function to send data to the backend after PySide.phonon.Phonon::AbstractMediaStream.needData() has been called.

If your stream is a push stream, data should be written until the PySide.phonon.Phonon::AbstractMediaStream.enoughData() function is called. For a pull stream, write data once before the call to PySide.phonon.Phonon::AbstractMediaStream.needData() function returns.

If the data is depleted, call PySide.phonon.Phonon::AbstractMediaStream.endOfData() instead of PySide.phonon.Phonon::AbstractMediaStream.writeData() .

Warning

Don’t call this function before the first PySide.phonon.Phonon::AbstractMediaStream.needData() is emitted.

See also

PySide.phonon.Phonon::AbstractMediaStream.needData() PySide.phonon.Phonon::AbstractMediaStream.endOfData()