|  | Home · All Classes · Modules

# Phonon.MediaSource Class Reference
[phonon module]

The MediaSource class provides multimedia data for media objects. More...

### Types

- enum Type { Invalid, LocalFile, Url, Disc, Stream, Empty }

### Methods

- __init__ (self, QString)
- __init__ (self, QUrl)
- __init__ (self, DiscType, QString deviceName = QString())
- __init__ (self, QIODevice)
- __init__ (self, MediaSource)
- bool autoDelete (self)
- QString deviceName (self)
- DiscType discType (self)
- QString fileName (self)
- setAutoDelete (self, bool)
- Type type (self)
- QUrl url (self)

### Special Methods

- bool __eq__ (self, MediaSource)
- bool __ne__ (self, MediaSource)

## Detailed Description

The MediaSource class provides multimedia data for media objects.

The MediaSource class manages a source of multimedia content, such as a music or video file, of which data is given to a MediaObject.

The media source knows how fetch its data from several sources, e.g., from files, a QIODevice, or a CD. The possible source types are described by the Type enum. The type of the source is set by the media source itself, and is dependent on the constructor used to create it. Note that it is possible to provide data from any source by implementing a QIODevice.

The class has several functions to acquire information about the source it manages, e.g., fileName() and url(). The return from these functions are dependent on the type() of the media source.

Normally, a programmer does not need to be concerned with media sources. It's constructors are implicit, so one can, for instance, send an URL or filename directly to the constructors of the MediaObject.

     MediaObject m;
     QString fileName("/home/foo/bar.ogg");
     QUrl url("http://www.example.com/stream.mp3");
     QBuffer *someBuffer;
     m.setCurrentSource(fileName);
     m.setCurrentSource(url);
     m.setCurrentSource(someBuffer);
     m.setCurrentSource(Phonon.Cd);

A MediaSource object cannot be reused for another multimedia source. It is possible to play the same source again, and also stop and start a non-seekable media source, such as a radio stream, with the same MediaSource object.

### Qt Backends

Currently, Qt's backends support files in local and remote locations. Support for other sources, such as CD/DVD, are planned for the future.

See also MediaObject and Phonon Module.

## Type Documentation

### MediaSource.Type

Identifies the type of media described by the MediaSource object.

Constant | Value | Description
--- | --- | ---
`Phonon.MediaSource.Invalid` | `-1` | The MediaSource object does not describe any valid source.
`Phonon.MediaSource.LocalFile` | `0` | The MediaSource object describes a local file.
`Phonon.MediaSource.Url` | `1` | The MediaSource object describes an URL, which can be either a local file or a file on the network.
`Phonon.MediaSource.Disc` | `2` | The MediaSource object describes a disc, e.g., a CD.
`Phonon.MediaSource.Stream` | `3` | The MediaSource object describes a data stream. This is the type used for QIODevices. Note that a stream opened with a QUrl, will still be of the Url type.
`Phonon.MediaSource.Empty` | `4` | The media source doesn't have a source.

See also MediaSource.type().

## Method Documentation

### MediaSource.__init__ (self, QString)

Creates a MediaSource object for the file specified by fileName. You can also use this constructor with Qt resources

### MediaSource.__init__ (self, QUrl)

### MediaSource.__init__ (self, DiscType, QString deviceName = QString())

Creates a MediaSource object for a the URL specified by url.

If the multimedia content you would like to play back is on a remote network location, you should use this constructor; though, it also possible to specify an URL to a local file.

See also QUrl.

### MediaSource.__init__ (self, QIODevice)

Creates a MediaSource object for the type of disc specified by discType in the named device referred to by deviceName.

Note: deviceName is a platform dependent device name. It can be useful to specify this if the computer has more than one CD drive. On KDE, it is recommended to use the Solid hardware discovery framework to retrieve the device name in a portable way.

### MediaSource.__init__ (self, MediaSource)

### bool MediaSource.autoDelete (self)

Returns the setting of the auto-delete option. The default is false.

See also setAutoDelete().

### QString MediaSource.deviceName (self)

Returns the device name of the MediaSource if type() == Disc; otherwise returns QString().

See also type().

### DiscType MediaSource.discType (self)

Returns the disc type of the MediaSource if type() == Disc; otherwise returns NoDisc.

See also type().

### QString MediaSource.fileName (self)

Returns the file name of the MediaSource if type() == LocalFile; otherwise, returns QString().

See also type().

### MediaSource.setAutoDelete (self, bool)

If enable is true, the media source will take ownership of the object passed in the MediaSource's constructor object that was passed in the constructor; otherwise, the programmer is responsible for deletion of this object.

This setting is false by default. If you enable it, you should only access the stream or device as long as you keep the media source object around. As long as you keep the media source wrapping the stream or device, the object will not get deleted.

See also autoDelete().

### Type MediaSource.type (self)

Returns the type of the MediaSource (depends on the constructor that was used).

See also Type.

### QUrl MediaSource.url (self)

Returns the URL of the MediaSource if type() == URL or type() == LocalFile; otherwise returns QUrl().

See also type().

### bool MediaSource.__eq__ (self, MediaSource)

### bool MediaSource.__ne__ (self, MediaSource)