1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 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:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | //! [0]
|
---|
43 | PushStream::PushStream(QObject *parent)
|
---|
44 | : AbstractMediaStream(parent), m_timer(new QTimer(this))
|
---|
45 | {
|
---|
46 | setStreamSize(getMediaStreamSize());
|
---|
47 |
|
---|
48 | connect(m_timer, SIGNAL(timeout()), SLOT(moreData()));
|
---|
49 | m_timer->setInterval(0);
|
---|
50 | }
|
---|
51 |
|
---|
52 | void PushStream::moreData()
|
---|
53 | {
|
---|
54 | const QByteArray data = getMediaData();
|
---|
55 | if (data.isEmpty()) {
|
---|
56 | endOfData();
|
---|
57 | } else {
|
---|
58 | writeData(data);
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | void PushStream::needData()
|
---|
63 | {
|
---|
64 | m_timer->start();
|
---|
65 | moreData();
|
---|
66 | }
|
---|
67 |
|
---|
68 | void PushStream::enoughData()
|
---|
69 | {
|
---|
70 | m_timer->stop();
|
---|
71 | }
|
---|
72 | //! [0]
|
---|
73 |
|
---|
74 |
|
---|
75 | //! [1]
|
---|
76 | PullStream::PullStream(QObject *parent)
|
---|
77 | : AbstractMediaStream(parent)
|
---|
78 | {
|
---|
79 | setStreamSize(getMediaStreamSize());
|
---|
80 | }
|
---|
81 |
|
---|
82 | void PullStream::needData()
|
---|
83 | {
|
---|
84 | const QByteArray data = getMediaData();
|
---|
85 | if (data.isEmpty()) {
|
---|
86 | endOfData();
|
---|
87 | } else {
|
---|
88 | writeData(data);
|
---|
89 | }
|
---|
90 | }
|
---|
91 | //! [1]
|
---|
92 |
|
---|
93 |
|
---|
94 | //! [2]
|
---|
95 | seekStream(0);
|
---|
96 | //! [2]
|
---|
97 |
|
---|
98 |
|
---|
99 | //! [3]
|
---|
100 | MediaObject m;
|
---|
101 | QString fileName("/home/foo/bar.ogg");
|
---|
102 | QUrl url("http://www.example.com/stream.mp3");
|
---|
103 | QBuffer *someBuffer;
|
---|
104 | m.setCurrentSource(fileName);
|
---|
105 | m.setCurrentSource(url);
|
---|
106 | m.setCurrentSource(someBuffer);
|
---|
107 | m.setCurrentSource(Phonon::Cd);
|
---|
108 | //! [3]
|
---|
109 |
|
---|
110 |
|
---|
111 | //! [4]
|
---|
112 | VideoPlayer *player = new VideoPlayer(Phonon::VideoCategory, parentWidget);
|
---|
113 | connect(player, SIGNAL(finished()), player, SLOT(deleteLater()));
|
---|
114 | player->play(url);
|
---|
115 | //! [4]
|
---|
116 |
|
---|
117 |
|
---|
118 | //! [5]
|
---|
119 | audioPlayer->load(url);
|
---|
120 | audioPlayer->play();
|
---|
121 | //! [5]
|
---|
122 |
|
---|
123 |
|
---|
124 | //! [6]
|
---|
125 | media = new MediaObject(this);
|
---|
126 | connect(media, SIGNAL(finished()), SLOT(slotFinished());
|
---|
127 | media->setCurrentSource("/home/username/music/filename.ogg");
|
---|
128 |
|
---|
129 | ...
|
---|
130 |
|
---|
131 | media->play();
|
---|
132 | //! [6]
|
---|
133 |
|
---|
134 |
|
---|
135 | //! [7]
|
---|
136 | media->setCurrentSource(":/sounds/startsound.ogg");
|
---|
137 | media->enqueue("/home/username/music/song.mp3");
|
---|
138 | media->enqueue(":/sounds/endsound.ogg");
|
---|
139 | //! [7]
|
---|
140 |
|
---|
141 |
|
---|
142 | //! [8]
|
---|
143 | media->setCurrentSource(":/sounds/startsound.ogg");
|
---|
144 | connect(media, SIGNAL(aboutToFinish()), SLOT(enqueueNextSource()));
|
---|
145 | }
|
---|
146 |
|
---|
147 | void enqueueNextSource()
|
---|
148 | {
|
---|
149 | media->enqueue("/home/username/music/song.mp3");
|
---|
150 | }
|
---|
151 | //! [8]
|
---|
152 |
|
---|
153 |
|
---|
154 | //! [9]
|
---|
155 | int x = 200;
|
---|
156 | media->setTickInterval(x);
|
---|
157 | Q_ASSERT(x == producer->tickInterval());
|
---|
158 | //! [9]
|
---|
159 |
|
---|
160 |
|
---|
161 | //! [10]
|
---|
162 | int x = 200;
|
---|
163 | media->setTickInterval(x);
|
---|
164 | Q_ASSERT(x >= producer->tickInterval() &&
|
---|
165 | x <= 2producer->tickInterval());
|
---|
166 | //! [10]
|
---|
167 |
|
---|
168 |
|
---|
169 | //! [11]
|
---|
170 | connect(media, SIGNAL(hasVideoChanged(bool)), hasVideoChanged(bool));
|
---|
171 | media->setCurrentSource("somevideo.avi");
|
---|
172 | media->hasVideo(); // returns false;
|
---|
173 | }
|
---|
174 |
|
---|
175 | void hasVideoChanged(bool b)
|
---|
176 | {
|
---|
177 | // b == true
|
---|
178 | media->hasVideo(); // returns true;
|
---|
179 | }
|
---|
180 | //! [11]
|
---|
181 |
|
---|
182 |
|
---|
183 | //! [12]
|
---|
184 | connect(media, SIGNAL(hasVideoChanged(bool)), hasVideoChanged(bool));
|
---|
185 | media->setCurrentSource("somevideo.avi");
|
---|
186 | media->hasVideo(); // returns false;
|
---|
187 | }
|
---|
188 |
|
---|
189 | void hasVideoChanged(bool b)
|
---|
190 | {
|
---|
191 | // b == true
|
---|
192 | media->hasVideo(); // returns true;
|
---|
193 | }
|
---|
194 | //! [12]
|
---|
195 |
|
---|
196 |
|
---|
197 | //! [13]
|
---|
198 | setMetaArtist(media->metaData("ARTIST"));
|
---|
199 | setMetaAlbum(media->metaData("ALBUM"));
|
---|
200 | setMetaTitle(media->metaData("TITLE"));
|
---|
201 | setMetaDate(media->metaData("DATE"));
|
---|
202 | setMetaGenre(media->metaData("GENRE"));
|
---|
203 | setMetaTrack(media->metaData("TRACKNUMBER"));
|
---|
204 | setMetaComment(media->metaData("DESCRIPTION"));
|
---|
205 | //! [13]
|
---|
206 |
|
---|
207 |
|
---|
208 | //! [14]
|
---|
209 | QUrl url("http://www.example.com/music.ogg");
|
---|
210 | media->setCurrentSource(url);
|
---|
211 | //! [14]
|
---|
212 |
|
---|
213 |
|
---|
214 | //! [15]
|
---|
215 | progressBar->setRange(0, 100); // this is the default
|
---|
216 | connect(media, SIGNAL(bufferStatus(int)), progressBar, SLOT(setValue(int)));
|
---|
217 | //! [15]
|
---|
218 |
|
---|
219 |
|
---|
220 | //! [16]
|
---|
221 | QObject::connect(BackendCapabilities::notifier(), SIGNAL(capabilitiesChanged()), ...
|
---|
222 | //! [16]
|
---|
223 |
|
---|
224 |
|
---|
225 | //! [17]
|
---|
|
---|