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]
|
---|
42 | PushStream::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 |
|
---|
51 | void PushStream::moreData()
|
---|
52 | {
|
---|
53 | const QByteArray data = getMediaData();
|
---|
54 | if (data.isEmpty()) {
|
---|
55 | endOfData();
|
---|
56 | } else {
|
---|
57 | writeData(data);
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | void PushStream::needData()
|
---|
62 | {
|
---|
63 | m_timer->start();
|
---|
64 | moreData();
|
---|
65 | }
|
---|
66 |
|
---|
67 | void PushStream::enoughData()
|
---|
68 | {
|
---|
69 | m_timer->stop();
|
---|
70 | }
|
---|
71 | //! [0]
|
---|
72 |
|
---|
73 |
|
---|
74 | //! [1]
|
---|
75 | PullStream::PullStream(QObject *parent)
|
---|
76 | : AbstractMediaStream(parent)
|
---|
77 | {
|
---|
78 | setStreamSize(getMediaStreamSize());
|
---|
79 | }
|
---|
80 |
|
---|
81 | void 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]
|
---|
94 | seekStream(0);
|
---|
95 | //! [2]
|
---|
96 |
|
---|
97 |
|
---|
98 | //! [3]
|
---|
99 | MediaObject m;
|
---|
100 | QString fileName("/home/foo/bar.ogg");
|
---|
101 | QUrl url("http://www.example.com/stream.mp3");
|
---|
102 | QBuffer *someBuffer;
|
---|
103 | m.setCurrentSource(fileName);
|
---|
104 | m.setCurrentSource(url);
|
---|
105 | m.setCurrentSource(someBuffer);
|
---|
106 | m.setCurrentSource(Phonon::Cd);
|
---|
107 | //! [3]
|
---|
108 |
|
---|
109 |
|
---|
110 | //! [4]
|
---|
111 | VideoPlayer *player = new VideoPlayer(Phonon::VideoCategory, parentWidget);
|
---|
112 | connect(player, SIGNAL(finished()), player, SLOT(deleteLater()));
|
---|
113 | player->play(url);
|
---|
114 | //! [4]
|
---|
115 |
|
---|
116 |
|
---|
117 | //! [5]
|
---|
118 | audioPlayer->load(url);
|
---|
119 | audioPlayer->play();
|
---|
120 | //! [5]
|
---|
121 |
|
---|
122 |
|
---|
123 | //! [6]
|
---|
124 | media = new MediaObject(this);
|
---|
125 | connect(media, SIGNAL(finished()), SLOT(slotFinished());
|
---|
126 | media->setCurrentSource("/home/username/music/filename.ogg");
|
---|
127 |
|
---|
128 | ...
|
---|
129 |
|
---|
130 | media->play();
|
---|
131 | //! [6]
|
---|
132 |
|
---|
133 |
|
---|
134 | //! [7]
|
---|
135 | media->setCurrentSource(":/sounds/startsound.ogg");
|
---|
136 | media->enqueue("/home/username/music/song.mp3");
|
---|
137 | media->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 |
|
---|
146 | void enqueueNextSource()
|
---|
147 | {
|
---|
148 | media->enqueue("/home/username/music/song.mp3");
|
---|
149 | }
|
---|
150 | //! [8]
|
---|
151 |
|
---|
152 |
|
---|
153 | //! [9]
|
---|
154 | int x = 200;
|
---|
155 | media->setTickInterval(x);
|
---|
156 | Q_ASSERT(x == producer->tickInterval());
|
---|
157 | //! [9]
|
---|
158 |
|
---|
159 |
|
---|
160 | //! [10]
|
---|
161 | int x = 200;
|
---|
162 | media->setTickInterval(x);
|
---|
163 | Q_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 |
|
---|
174 | void 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 |
|
---|
188 | void hasVideoChanged(bool b)
|
---|
189 | {
|
---|
190 | // b == true
|
---|
191 | media->hasVideo(); // returns true;
|
---|
192 | }
|
---|
193 | //! [12]
|
---|
194 |
|
---|
195 |
|
---|
196 | //! [13]
|
---|
197 | setMetaArtist(media->metaData("ARTIST"));
|
---|
198 | setMetaAlbum(media->metaData("ALBUM"));
|
---|
199 | setMetaTitle(media->metaData("TITLE"));
|
---|
200 | setMetaDate(media->metaData("DATE"));
|
---|
201 | setMetaGenre(media->metaData("GENRE"));
|
---|
202 | setMetaTrack(media->metaData("TRACKNUMBER"));
|
---|
203 | setMetaComment(media->metaData("DESCRIPTION"));
|
---|
204 | //! [13]
|
---|
205 |
|
---|
206 |
|
---|
207 | //! [14]
|
---|
208 | QUrl url("http://www.example.com/music.ogg");
|
---|
209 | media->setCurrentSource(url);
|
---|
210 | //! [14]
|
---|
211 |
|
---|
212 |
|
---|
213 | //! [15]
|
---|
214 | progressBar->setRange(0, 100); // this is the default
|
---|
215 | connect(media, SIGNAL(bufferStatus(int)), progressBar, SLOT(setValue(int)));
|
---|
216 | //! [15]
|
---|
217 |
|
---|
218 |
|
---|
219 | //! [16]
|
---|
220 | QObject::connect(BackendCapabilities::notifier(), SIGNAL(capabilitiesChanged()), ...
|
---|
221 | //! [16]
|
---|
222 |
|
---|
223 |
|
---|
224 | //! [17]
|
---|
225 | QComboBox *cb = new QComboBox(parentWidget);
|
---|
226 | ObjectDescriptionModel *model = new ObjectDescriptionModel(cb);
|
---|
227 | model->setModelData(BackendCapabilities::availableAudioOutputDevices());
|
---|
228 | cb->setModel(model);
|
---|
229 | cb->setCurrentIndex(0); // select first entry
|
---|
230 | //! [17]
|
---|
231 |
|
---|
232 |
|
---|
233 | //! [18]
|
---|
234 | int cbIndex = cb->currentIndex();
|
---|
235 | AudioOutputDevice selectedDevice = model->modelData(cbIndex);
|
---|
236 | //! [18]
|
---|
237 |
|
---|
238 |
|
---|
239 | //! [19]
|
---|
240 | Path path = Phonon::createPath(...);
|
---|
241 | Effect *effect = new Effect(this);
|
---|
242 | path.insertEffect(effect);
|
---|
243 | //! [19]
|
---|
244 |
|
---|
245 |
|
---|
246 | //! [20]
|
---|
247 | MediaObject *media = new MediaObject;
|
---|
248 | AudioOutput *output = new AudioOutput(Phonon::MusicCategory);
|
---|
249 | Path path = Phonon::createPath(media, output);
|
---|
250 | Q_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
|
---|
253 | QList<EffectDescription> effectList = BackendCapabilities::availableAudioEffects();
|
---|
254 | if (!effectList.isEmpty()) {
|
---|
255 | Effect *effect = path.insertEffect(effectList.first());
|
---|
256 | }
|
---|
257 | //! [20]
|
---|
258 |
|
---|
259 |
|
---|
260 | //! [21]
|
---|
261 | MediaObject *media = new MediaObject(parent);
|
---|
262 | VideoWidget *vwidget = new VideoWidget(parent);
|
---|
263 | Phonon::createPath(media, vwidget);
|
---|
264 | //! [21]
|
---|