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

Last change on this file since 788 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 6.3 KB
Line 
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]
43PushStream::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
52void PushStream::moreData()
53{
54 const QByteArray data = getMediaData();
55 if (data.isEmpty()) {
56 endOfData();
57 } else {
58 writeData(data);
59 }
60}
61
62void PushStream::needData()
63{
64 m_timer->start();
65 moreData();
66}
67
68void PushStream::enoughData()
69{
70 m_timer->stop();
71}
72//! [0]
73
74
75//! [1]
76PullStream::PullStream(QObject *parent)
77 : AbstractMediaStream(parent)
78{
79 setStreamSize(getMediaStreamSize());
80}
81
82void 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]
95seekStream(0);
96//! [2]
97
98
99//! [3]
100MediaObject m;
101QString fileName("/home/foo/bar.ogg");
102QUrl url("http://www.example.com/stream.mp3");
103QBuffer *someBuffer;
104m.setCurrentSource(fileName);
105m.setCurrentSource(url);
106m.setCurrentSource(someBuffer);
107m.setCurrentSource(Phonon::Cd);
108//! [3]
109
110
111//! [4]
112VideoPlayer *player = new VideoPlayer(Phonon::VideoCategory, parentWidget);
113connect(player, SIGNAL(finished()), player, SLOT(deleteLater()));
114player->play(url);
115//! [4]
116
117
118//! [5]
119audioPlayer->load(url);
120audioPlayer->play();
121//! [5]
122
123
124//! [6]
125media = new MediaObject(this);
126connect(media, SIGNAL(finished()), SLOT(slotFinished());
127media->setCurrentSource("/home/username/music/filename.ogg");
128
129...
130
131media->play();
132//! [6]
133
134
135//! [7]
136media->setCurrentSource(":/sounds/startsound.ogg");
137media->enqueue("/home/username/music/song.mp3");
138media->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
147void enqueueNextSource()
148{
149 media->enqueue("/home/username/music/song.mp3");
150}
151//! [8]
152
153
154//! [9]
155int x = 200;
156media->setTickInterval(x);
157Q_ASSERT(x == producer->tickInterval());
158//! [9]
159
160
161//! [10]
162int x = 200;
163media->setTickInterval(x);
164Q_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
175void 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
189void hasVideoChanged(bool b)
190{
191 // b == true
192 media->hasVideo(); // returns true;
193}
194//! [12]
195
196
197//! [13]
198setMetaArtist(media->metaData("ARTIST"));
199setMetaAlbum(media->metaData("ALBUM"));
200setMetaTitle(media->metaData("TITLE"));
201setMetaDate(media->metaData("DATE"));
202setMetaGenre(media->metaData("GENRE"));
203setMetaTrack(media->metaData("TRACKNUMBER"));
204setMetaComment(media->metaData("DESCRIPTION"));
205//! [13]
206
207
208//! [14]
209QUrl url("http://www.example.com/music.ogg");
210media->setCurrentSource(url);
211//! [14]
212
213
214//! [15]
215progressBar->setRange(0, 100); // this is the default
216connect(media, SIGNAL(bufferStatus(int)), progressBar, SLOT(setValue(int)));
217//! [15]
218
219
220//! [16]
221QObject::connect(BackendCapabilities::notifier(), SIGNAL(capabilitiesChanged()), ...
222//! [16]
223
224
225//! [17]