source: trunk/doc/src/snippets/code/doc_src_phonon-api.qdoc@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 6.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:BSD$
10** You may use this file under the terms of the BSD license as follows:
11**
12** "Redistribution and use in source and binary forms, with or without
13** modification, are permitted provided that the following conditions are
14** met:
15** * Redistributions of source code must retain the above copyright
16** notice, this list of conditions and the following disclaimer.
17** * Redistributions in binary form must reproduce the above copyright
18** notice, this list of conditions and the following disclaimer in
19** the documentation and/or other materials provided with the
20** distribution.
21** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22** the names of its contributors may be used to endorse or promote
23** products derived from this software without specific prior written
24** permission.
25**
26** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41//! [0]
42PushStream::PushStream(QObject *parent)
43 : AbstractMediaStream(parent), m_timer(new QTimer(this))
44{
45 setStreamSize(getMediaStreamSize());
46
47 connect(m_timer, SIGNAL(timeout()), SLOT(moreData()));
48 m_timer->setInterval(0);
49}
50
51void PushStream::moreData()
52{
53 const QByteArray data = getMediaData();
54 if (data.isEmpty()) {
55 endOfData();
56 } else {
57 writeData(data);
58 }
59}
60
61void PushStream::needData()
62{
63 m_timer->start();
64 moreData();
65}
66
67void PushStream::enoughData()
68{
69 m_timer->stop();
70}
71//! [0]
72
73
74//! [1]
75PullStream::PullStream(QObject *parent)
76 : AbstractMediaStream(parent)
77{
78 setStreamSize(getMediaStreamSize());
79}
80
81void PullStream::needData()
82{
83 const QByteArray data = getMediaData();
84 if (data.isEmpty()) {
85 endOfData();
86 } else {
87 writeData(data);
88 }
89}
90//! [1]
91
92
93//! [2]
94seekStream(0);
95//! [2]
96
97
98//! [3]
99MediaObject m;
100QString fileName("/home/foo/bar.ogg");
101QUrl url("http://www.example.com/stream.mp3");
102QBuffer *someBuffer;
103m.setCurrentSource(fileName);
104m.setCurrentSource(url);
105m.setCurrentSource(someBuffer);
106m.setCurrentSource(Phonon::Cd);
107//! [3]
108
109
110//! [4]
111VideoPlayer *player = new VideoPlayer(Phonon::VideoCategory, parentWidget);
112connect(player, SIGNAL(finished()), player, SLOT(deleteLater()));
113player->play(url);
114//! [4]
115
116
117//! [5]
118audioPlayer->load(url);
119audioPlayer->play();
120//! [5]
121
122
123//! [6]
124media = new MediaObject(this);
125connect(media, SIGNAL(finished()), SLOT(slotFinished());
126media->setCurrentSource("/home/username/music/filename.ogg");
127
128...
129
130media->play();
131//! [6]
132
133
134//! [7]
135media->setCurrentSource(":/sounds/startsound.ogg");
136media->enqueue("/home/username/music/song.mp3");
137media->enqueue(":/sounds/endsound.ogg");
138//! [7]
139
140
141//! [8]
142 media->setCurrentSource(":/sounds/startsound.ogg");
143 connect(media, SIGNAL(aboutToFinish()), SLOT(enqueueNextSource()));
144}
145
146void enqueueNextSource()
147{
148 media->enqueue("/home/username/music/song.mp3");
149}
150//! [8]
151
152
153//! [9]
154int x = 200;
155media->setTickInterval(x);
156Q_ASSERT(x == producer->tickInterval());
157//! [9]
158
159
160//! [10]
161int x = 200;
162media->setTickInterval(x);
163Q_ASSERT(x >= producer->tickInterval() &&
164 x <= 2producer->tickInterval());
165//! [10]
166
167
168//! [11]
169 connect(media, SIGNAL(hasVideoChanged(bool)), hasVideoChanged(bool));
170 media->setCurrentSource("somevideo.avi");
171 media->hasVideo(); // returns false;
172}
173
174void hasVideoChanged(bool b)
175{
176 // b == true
177 media->hasVideo(); // returns true;
178}
179//! [11]
180
181
182//! [12]
183 connect(media, SIGNAL(hasVideoChanged(bool)), hasVideoChanged(bool));
184 media->setCurrentSource("somevideo.avi");
185 media->hasVideo(); // returns false;
186}
187
188void hasVideoChanged(bool b)
189{
190 // b == true
191 media->hasVideo(); // returns true;
192}
193//! [12]
194
195
196//! [13]
197setMetaArtist(media->metaData("ARTIST"));
198setMetaAlbum(media->metaData("ALBUM"));
199setMetaTitle(media->metaData("TITLE"));
200setMetaDate(media->metaData("DATE"));
201setMetaGenre(media->metaData("GENRE"));
202setMetaTrack(media->metaData("TRACKNUMBER"));
203setMetaComment(media->metaData("DESCRIPTION"));
204//! [13]
205
206
207//! [14]
208QUrl url("http://www.example.com/music.ogg");
209media->setCurrentSource(url);
210//! [14]
211
212
213//! [15]
214progressBar->setRange(0, 100); // this is the default
215connect(media, SIGNAL(bufferStatus(int)), progressBar, SLOT(setValue(int)));
216//! [15]
217
218
219//! [16]
220QObject::connect(BackendCapabilities::notifier(), SIGNAL(capabilitiesChanged()), ...
221//! [16]
222
223
224//! [17]
225QComboBox *cb = new QComboBox(parentWidget);
226ObjectDescriptionModel *model = new ObjectDescriptionModel(cb);
227model->setModelData(BackendCapabilities::availableAudioOutputDevices());
228cb->setModel(model);
229cb->setCurrentIndex(0); // select first entry
230//! [17]
231
232
233//! [18]
234int cbIndex = cb->currentIndex();
235AudioOutputDevice selectedDevice = model->modelData(cbIndex);
236//! [18]
237
238
239//! [19]
240Path path = Phonon::createPath(...);
241Effect *effect = new Effect(this);
242path.insertEffect(effect);
243//! [19]
244
245
246//! [20]
247MediaObject *media = new MediaObject;
248AudioOutput *output = new AudioOutput(Phonon::MusicCategory);
249Path path = Phonon::createPath(media, output);
250Q_ASSERT(path.isValid()); // for this simple case the path should always be
251 //valid - there are unit tests to ensure it
252// insert an effect
253QList<EffectDescription> effectList = BackendCapabilities::availableAudioEffects();
254if (!effectList.isEmpty()) {
255 Effect *effect = path.insertEffect(effectList.first());
256}
257//! [20]
258
259
260//! [21]
261MediaObject *media = new MediaObject(parent);
262VideoWidget *vwidget = new VideoWidget(parent);
263Phonon::createPath(media, vwidget);
264//! [21]
Note: See TracBrowser for help on using the repository browser.