//! [0]
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()
//! [0]


//! [1]
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)
//! [1]


//! [2]
self.seekStream(0)
//! [2]


//! [3]
m = MediaObject()
fileName = "/home/foo/bar.ogg"
url = QUrl("http://www.example.com/stream.mp3")
someBuffer = QBuffer()
m.setCurrentSource(fileName)
m.setCurrentSource(url)
m.setCurrentSource(someBuffer)
m.setCurrentSource(Phonon.Cd)
//! [3]


//! [4]
player = VideoPlayer(Phonon.VideoCategory, parentWidget)
player.finished.connect(player.deleteLater)
player.play(url)
//! [4]


//! [5]
audioPlayer.load(url)
audioPlayer.play()
//! [5]


//! [6]
media = MediaObject(self)
media.finished.connect(self.slotFinished)
media.setCurrentSource("/home/username/music/filename.ogg")

# ...

media.play()
//! [6]


//! [7]
media.setCurrentSource(":/sounds/startsound.ogg")
media.enqueue("/home/username/music/song.mp3")
media.enqueue(":/sounds/endsound.ogg")
//! [7]


//! [8]
  media.setCurrentSource(":/sounds/startsound.ogg")
  media.aboutToFinish.connect(lambda : media.enqueue("/home/username/music/song.mp3"))
//! [8]


//! [9]
x = 200
media.setTickInterval(x)
assert(x == producer.tickInterval())
//! [9]


//! [10]
x = 200
media.setTickInterval(x)
assert(x >= producer.tickInterval() and x <= * producer.tickInterval())
//! [10]


//! [11]
//! [12]
    self.media.hasVideoChanged[bool].connect(hasVideoChanged)
    self.media.setCurrentSource("somevideo.avi")
    self.media.hasVideo() # returns false

    @Slot(bool)
    def hasVideoChanged(self, b):
        # b == true
        media.hasVideo() # returns true
//! [12]
//! [11]

//! [13]
self.setMetaArtist(media.metaData("ARTIST"))
self.setMetaAlbum(media.metaData("ALBUM"))
self.setMetaTitle(media.metaData("TITLE"))
self.setMetaDate(media.metaData("DATE"))
self.setMetaGenre(media.metaData("GENRE"))
self.setMetaTrack(media.metaData("TRACKNUMBER"))
self.setMetaComment(media.metaData("DESCRIPTION"))
//! [13]


//! [14]
url = QUrl("http://www.example.com/music.ogg")
media.setCurrentSource(url)
//! [14]


//! [15]
progressBar.setRange(0, 100) # this is the default
self.media.bufferStatus[int].connect(progressBar.setValue)
//! [15]


//! [16]
BackendCapabilities.notifier.capabilitiesChanged.connect(...)
//! [16]


//! [17]
cb = QComboBox(parentWidget)
model = ObjectDescriptionModel(cb)
model.setModelData(BackendCapabilities.availableAudioOutputDevices())
cb.setModel(model)
cb.setCurrentIndex(0) # select first entry
//! [17]


//! [18]
cbIndex = cb.currentIndex()
selectedDevice = model.modelData(cbIndex)
//! [18]


//! [19]
path = Phonon.createPath(...)
effect = Effect(this)
path.insertEffect(effect)
//! [19]


//! [20]
media = MediaObject()
output = AudioOutput(Phonon.MusicCategory)
path = Phonon.createPath(media, output)
assert(path.isValid()) # for this simple case the path should always be
                       # valid - there are unit tests to ensure it
# insert an effect
effectList = BackendCapabilities.availableAudioEffects()
if effectList:
    effect = path.insertEffect(effectList[0])
//! [20]


//! [21]
media = MediaObject(parent)
vwidget = VideoWidget(parent)
Phonon.createPath(media, vwidget)
//! [21]
