doc/src/snippets/code/doc_src_phonon-api.qdoc
changeset 0 1918ee327afb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/src/snippets/code/doc_src_phonon-api.qdoc	Mon Jan 11 14:00:40 2010 +0000
@@ -0,0 +1,265 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights.  These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+PushStream::PushStream(QObject *parent)
+  : AbstractMediaStream(parent), m_timer(new QTimer(this))
+{
+  setStreamSize(getMediaStreamSize());
+
+  connect(m_timer, SIGNAL(timeout()), SLOT(moreData()));
+  m_timer->setInterval(0);
+}
+
+void PushStream::moreData()
+{
+  const QByteArray data = getMediaData();
+  if (data.isEmpty()) {
+    endOfData();
+  } else {
+    writeData(data);
+  }
+}
+
+void PushStream::needData()
+{
+  m_timer->start();
+  moreData();
+}
+
+void PushStream::enoughData()
+{
+  m_timer->stop();
+}
+//! [0]
+
+
+//! [1]
+PullStream::PullStream(QObject *parent)
+  : AbstractMediaStream(parent)
+{
+  setStreamSize(getMediaStreamSize());
+}
+
+void PullStream::needData()
+{
+  const QByteArray data = getMediaData();
+  if (data.isEmpty()) {
+    endOfData();
+  } else {
+    writeData(data);
+  }
+}
+//! [1]
+
+
+//! [2]
+seekStream(0);
+//! [2]
+
+
+//! [3]
+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);
+//! [3]
+
+
+//! [4]
+VideoPlayer *player = new VideoPlayer(Phonon::VideoCategory, parentWidget);
+connect(player, SIGNAL(finished()), player, SLOT(deleteLater()));
+player->play(url);
+//! [4]
+
+
+//! [5]
+audioPlayer->load(url);
+audioPlayer->play();
+//! [5]
+
+
+//! [6]
+media = new MediaObject(this);
+connect(media, SIGNAL(finished()), SLOT(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");
+  connect(media, SIGNAL(aboutToFinish()), SLOT(enqueueNextSource()));
+}
+
+void enqueueNextSource()
+{
+  media->enqueue("/home/username/music/song.mp3");
+}
+//! [8]
+
+
+//! [9]
+int x = 200;
+media->setTickInterval(x);
+Q_ASSERT(x == producer->tickInterval());
+//! [9]
+
+
+//! [10]
+int x = 200;
+media->setTickInterval(x);
+Q_ASSERT(x >= producer->tickInterval() &&
+         x <= 2producer->tickInterval());
+//! [10]
+
+
+//! [11]
+  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;
+}
+//! [11]
+
+
+//! [12]
+  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;
+}
+//! [12]
+
+
+//! [13]
+setMetaArtist(media->metaData("ARTIST"));
+setMetaAlbum(media->metaData("ALBUM"));
+setMetaTitle(media->metaData("TITLE"));
+setMetaDate(media->metaData("DATE"));
+setMetaGenre(media->metaData("GENRE"));
+setMetaTrack(media->metaData("TRACKNUMBER"));
+setMetaComment(media->metaData("DESCRIPTION"));
+//! [13]
+
+
+//! [14]
+QUrl url("http://www.example.com/music.ogg");
+media->setCurrentSource(url);
+//! [14]
+
+
+//! [15]
+progressBar->setRange(0, 100); // this is the default
+connect(media, SIGNAL(bufferStatus(int)), progressBar, SLOT(setValue(int)));
+//! [15]
+
+
+//! [16]
+QObject::connect(BackendCapabilities::notifier(), SIGNAL(capabilitiesChanged()), ...
+//! [16]
+
+
+//! [17]
+QComboBox *cb = new QComboBox(parentWidget);
+ObjectDescriptionModel *model = new ObjectDescriptionModel(cb);
+model->setModelData(BackendCapabilities::availableAudioOutputDevices());
+cb->setModel(model);
+cb->setCurrentIndex(0); // select first entry
+//! [17]
+
+
+//! [18]
+int cbIndex = cb->currentIndex();
+AudioOutputDevice selectedDevice = model->modelData(cbIndex);
+//! [18]
+
+
+//! [19]
+Path path = Phonon::createPath(...);
+Effect *effect = new Effect(this);
+path.insertEffect(effect);
+//! [19]
+
+
+//! [20]
+MediaObject *media = new MediaObject;
+AudioOutput *output = new AudioOutput(Phonon::MusicCategory);
+Path path = Phonon::createPath(media, output);
+Q_ASSERT(path.isValid()); // for this simple case the path should always be
+                          //valid - there are unit tests to ensure it
+// insert an effect
+QList<EffectDescription> effectList = BackendCapabilities::availableAudioEffects();
+if (!effectList.isEmpty()) {
+    Effect *effect = path.insertEffect(effectList.first());
+}
+//! [20]
+
+
+//! [21]
+MediaObject *media = new MediaObject(parent);
+VideoWidget *vwidget = new VideoWidget(parent);
+Phonon::createPath(media, vwidget);
+//! [21]