KDE 4.7 PyKDE API Reference
  • KDE's Python API
  • Overview
  • PyKDE Home
  • Sitemap
  • Contact Us
 

MediaObject Class Reference

from PyKDE4.phonon import *

Inherits: QObject,Phonon.MediaNode
Namespace: Phonon

Detailed Description

\class MediaObject mediaobject.h 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:

 media = new MediaObject(this);
 connect(media, SIGNAL(finished()), SLOT(slotFinished());
 media->setCurrentSource("/home/username/music/filename.ogg");
 media->play();

If you want to play more than one media file (one after another) you can either tell MediaObject about all those files

 media->setCurrentSource(":/sounds/startsound.ogg");
 media->enqueue("/home/username/music/song.mp3");
 media->enqueue(":/sounds/endsound.ogg");
or provide the next file just in time:
   media->setCurrentSource(":/sounds/startsound.ogg");
   connect(media, SIGNAL(aboutToFinish()), SLOT(enqueueNextSource()));
 }

 void enqueueNextSource()
 {
   media->enqueue("/home/username/music/song.mp3");
 }

Some platforms support system-wide tracking of a user's activities. For instance, the zeitgeist project (http://zeitgeist-project.com) on Linux.

This integration is opt-in only and can be enabled by setting the PlaybackTracking property to true:

 media->setProperty("PlaybackTracking", true);

This kind of information is normally used to provide a universal history view to the user, such as what songs were played when, regardless of the media player. This is in addition to any emails read, IM conversations, websites viewed, etc.

Author:
Matthias Kretz <kretz@kde.org>


Signals

 aboutToFinish ()
 bufferStatus (int percentFilled)
 currentSourceChanged (Phonon.MediaSource newSource)
 finished ()
 hasVideoChanged (bool hasVideo)
 metaDataChanged ()
 prefinishMarkReached (int msecToEnd)
 seekableChanged (bool isSeekable)
 stateChanged (Phonon::State newstate, Phonon::State oldstate)
 tick (long time)
 totalTimeChanged (long newTotalTime)

Methods

 clear (self)
 clearQueue (self)
Phonon.MediaSource currentSource (self)
long currentTime (self)
 enqueue (self, Phonon.MediaSource source)
 enqueue (self, [Phonon.MediaSource] sources)
 enqueue (self, [QUrl] urls)
QString errorString (self)
Phonon::ErrorType errorType (self)
bool hasVideo (self)
bool isSeekable (self)
QStringList metaData (self, QString key)
QStringList metaData (self, Phonon::MetaData key)
QMultiMap metaData (self)
 pause (self)
 play (self)
int prefinishMark (self)
[Phonon.MediaSource] queue (self)
long remainingTime (self)
 seek (self, long time)
 setCurrentSource (self, Phonon.MediaSource source)
 setPrefinishMark (self, int msecToEnd)
 setQueue (self, [Phonon.MediaSource] sources)
 setQueue (self, [QUrl] urls)
 setTickInterval (self, int newTickInterval)
 setTransitionTime (self, int msec)
Phonon::State state (self)
 stop (self)
int tickInterval (self)
long totalTime (self)
int transitionTime (self)

Signal Documentation

aboutToFinish (   )

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.

See also:
enqueue

Signal syntax:
QObject.connect(source, SIGNAL("aboutToFinish()"), target_slot)
bufferStatus ( int  percentFilled
)

Tells about the status of the buffer.

You can use this signal to show a progress bar to the user when in BufferingState:

 progressBar->setRange(0, 100); // this is the default
 connect(media, SIGNAL(bufferStatus(int)), progressBar, SLOT(setValue(int)));

Parameters:
percentFilled  A number between 0 and 100 telling you how much the buffer is filled.

Signal syntax:
QObject.connect(source, SIGNAL("bufferStatus(int)"), target_slot)
currentSourceChanged ( Phonon.MediaSource  newSource
)

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.

Parameters:
newSource  The source that starts to play at the time the signal is emitted.

Signal syntax:
QObject.connect(source, SIGNAL("currentSourceChanged(const Phonon::MediaSource&)"), target_slot)
finished (   )

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.

Warning:
This signal is not emitted when the current source has finished and there's another source in the queue. It is only emitted when the queue is empty.

See also:
currentSourceChanged
See also:
aboutToFinish
See also:
prefinishMarkReached

Signal syntax:
QObject.connect(source, SIGNAL("finished()"), target_slot)
hasVideoChanged ( bool  hasVideo
)

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

Parameters:
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.

Signal syntax:
QObject.connect(source, SIGNAL("hasVideoChanged(bool)"), target_slot)
metaDataChanged (   )

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 syntax:
QObject.connect(source, SIGNAL("metaDataChanged()"), target_slot)
prefinishMarkReached ( int  msecToEnd
)

Emitted when there are only msecToEnd milliseconds left for playback.

Parameters:
msecToEnd  The remaining time until the playback queue finishes.

Warning:
This signal is not emitted when there is another source in the queue. It is only emitted when the queue is empty.

See also:
setPrefinishMark
See also:
prefinishMark
See also:
aboutToFinish
See also:
finished

Signal syntax:
QObject.connect(source, SIGNAL("prefinishMarkReached(qint32)"), target_slot)
seekableChanged ( bool  isSeekable
)

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

Parameters:
isSeekable  true if the stream is seekable (i.e. calling seek() works) false if the stream is not seekable (i.e. all calls to seek() will be ignored)

Signal syntax:
QObject.connect(source, SIGNAL("seekableChanged(bool)"), target_slot)
stateChanged ( Phonon::State  newstate,
Phonon::State  oldstate
)

Emitted when the state of the MediaObject has changed.

Parameters:
newstate  The state the Player is in now.
oldstate  The state the Player was in before.

Signal syntax:
QObject.connect(source, SIGNAL("stateChanged(Phonon::State, Phonon::State)"), target_slot)
tick ( long  time
)

This signal gets emitted every tickInterval milliseconds.

Parameters:
time  The position of the media file in milliseconds.

See also:
setTickInterval, tickInterval

Signal syntax:
QObject.connect(source, SIGNAL("tick(qint64)"), target_slot)
totalTimeChanged ( long  newTotalTime
)

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.

Parameters:
newTotalTime  The length of the media file in milliseconds.

See also:
totalTime

Signal syntax:
QObject.connect(source, SIGNAL("totalTimeChanged(qint64)"), target_slot)

Method Documentation

clear (   self )

Stops and removes all playing and enqueued media sources.

See also:
setCurrentSource

clearQueue (   self )

Clears the queue of sources.

Phonon.MediaSource currentSource (   self )

Returns the current media source.

See also:
setCurrentSource

long currentTime (   self )

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

Returns:
The current time in milliseconds.

See also:
tick

enqueue (  self,
Phonon.MediaSource  source
)

Appends multiple sources to the queue.

See also:
setQueue
See also:
clearQueue

enqueue (  self,
[Phonon.MediaSource]  sources
)

Appends multiple sources to the queue.

See also:
setQueue
See also:
clearQueue

enqueue (  self,
[QUrl]  urls
)

Appends multiple sources to the queue.

See also:
setQueue
See also:
clearQueue

QString errorString (   self )

Returns a human-readable description of the last error that occurred.

Phonon::ErrorType errorType (   self )

Tells your program what to do about the error.

See also:
Phonon.ErrorType

bool hasVideo (   self )

Check whether the media data includes a video stream.

Warning:
This information cannot be known immediately. It is best to also listen to the hasVideoChanged signal.

   connect(media, SIGNAL(hasVideoChanged(bool)), hasVideoChanged(bool));
   media->setCurrentSource("somevideo.avi");
   media->hasVideo(); // returns false;
 }

 void hasVideoChanged(bool b)
 {
   // b == true
   media->hasVideo(); // returns true;
 }

Returns:
true if the media contains video data. false otherwise.

See also:
hasVideoChanged

bool isSeekable (   self )

Check whether the current media may be seeked.

Warning:
This information cannot be known immediately. It is best to also listen to the seekableChanged signal.

   connect(media, SIGNAL(seekableChanged(bool)), seekableChanged(bool));
   media->setCurrentSource("somevideo.avi");
   media->isSeekable(); // returns false;
 }

 void seekableChanged(bool b)
 {
   // b == true
   media->isSeekable(); // returns true;
 }

Returns:
true when the current media may be seeked. false otherwise.

See also:
seekableChanged()

QStringList metaData (  self,
QString  key
)

Returns all meta data.

QStringList metaData (  self,
Phonon::MetaData  key
)

Returns all meta data.

QMultiMap metaData (   self )

Returns all meta data.

pause (   self )

Requests playback to pause. If it was paused before nothing changes.

Possible states right after this call:

  • PlayingState
  • PausedState
  • ErrorState
  • play (   self )

    Requests playback of the media data to start. Playback only starts when stateChanged() signals that it goes into PlayingState, though.

    Possible states right after this call:

  • BufferingState
  • PlayingState
  • ErrorState
  • int prefinishMark (   self )
    [Phonon.MediaSource] queue (   self )

    Returns the queued media sources. This list does not include the current source (returned by currentSource).

    long remainingTime (   self )

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

    Returns:
    The remaining time in milliseconds.

    seek (  self,
    long  time
    )

    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.

    Parameters:
    time  The time in milliseconds where to continue playing.

    Possible states right after this call:

  • BufferingState
  • PlayingState
  • ErrorState
  • See also:
    SeekSlider

    setCurrentSource (  self,
    Phonon.MediaSource  source
    )

    Set the media source the MediaObject should use.

    Parameters:
    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.

     QUrl url("http://www.example.com/music.ogg");
     media->setCurrentSource(url);
    

    See also:
    currentSource

    setPrefinishMark (  self,
    int  msecToEnd
    )
    setQueue (  self,
    [Phonon.MediaSource]  sources
    )

    Set the MediaSources to play when the current media has finished.

    This function overwrites the current queue.

    See also:
    clearQueue
    See also:
    enqueue

    setQueue (  self,
    [QUrl]  urls
    )

    Set the MediaSources to play when the current media has finished.

    This function overwrites the current queue.

    See also:
    clearQueue
    See also:
    enqueue

    setTickInterval (  self,
    int  newTickInterval
    )
    setTransitionTime (  self,
    int  msec
    )
    Phonon::State state (   self )

    Get the current state.

    Returns:
    The state of the object.

    See also:
    State
    See also:
    stateChanged

    stop (   self )

    Requests playback to stop. If it was stopped before nothing changes.

    Possible states right after this call:

  • the state it was in before (e.g. PlayingState)
  • StoppedState
  • ErrorState
  • int tickInterval (   self )
    long totalTime (   self )

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

    Returns:
    The total time in milliseconds.

    See also:
    totalTimeChanged

    int transitionTime (   self )
    • Full Index

    Modules

    • akonadi
    • dnssd
    • kdecore
    • kdeui
    • khtml
    • kio
    • knewstuff
    • kparts
    • kutils
    • nepomuk
    • phonon
    • plasma
    • polkitqt
    • solid
    • soprano
    This documentation is maintained by Simon Edwards.
    KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal