|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qdeclarativeaudio_p.h" |
|
43 |
|
44 #include <qmediaplayercontrol.h> |
|
45 |
|
46 QT_BEGIN_NAMESPACE |
|
47 |
|
48 |
|
49 /*! |
|
50 \qmlclass Audio QDeclarativeAudio |
|
51 \brief The Audio element allows you to add audio playback to a scene. |
|
52 |
|
53 This element is part of the \bold{Qt.multimedia 1.0} module. |
|
54 |
|
55 \qml |
|
56 import Qt 4.7 |
|
57 import Qt.multimedia 1.0 |
|
58 |
|
59 Text { |
|
60 text: "Click Me!"; |
|
61 font.pointSize: 24; |
|
62 width: 150; height: 50; |
|
63 |
|
64 Audio { |
|
65 id: playMusic |
|
66 source: "music.wav" |
|
67 } |
|
68 MouseArea { |
|
69 id: playArea |
|
70 anchors.fill: parent |
|
71 onPressed: { playMusic.play() } |
|
72 } |
|
73 } |
|
74 \endqml |
|
75 |
|
76 \sa Video |
|
77 */ |
|
78 |
|
79 /*! |
|
80 \internal |
|
81 \class QDeclarativeAudio |
|
82 \brief The QDeclarativeAudio class provides an audio item that you can add to a QDeclarativeView. |
|
83 */ |
|
84 |
|
85 void QDeclarativeAudio::_q_error(int errorCode, const QString &errorString) |
|
86 { |
|
87 m_error = QMediaPlayer::Error(errorCode); |
|
88 m_errorString = errorString; |
|
89 |
|
90 emit error(Error(errorCode), errorString); |
|
91 emit errorChanged(); |
|
92 } |
|
93 |
|
94 |
|
95 QDeclarativeAudio::QDeclarativeAudio(QObject *parent) |
|
96 : QObject(parent) |
|
97 { |
|
98 } |
|
99 |
|
100 QDeclarativeAudio::~QDeclarativeAudio() |
|
101 { |
|
102 shutdown(); |
|
103 } |
|
104 |
|
105 /*! |
|
106 \qmlmethod Audio::play() |
|
107 |
|
108 Starts playback of the media. |
|
109 |
|
110 Sets the \l playing property to true, and the \l paused property to false. |
|
111 */ |
|
112 |
|
113 void QDeclarativeAudio::play() |
|
114 { |
|
115 if (m_playerControl == 0) |
|
116 return; |
|
117 |
|
118 setPaused(false); |
|
119 setPlaying(true); |
|
120 } |
|
121 |
|
122 /*! |
|
123 \qmlmethod Audio::pause() |
|
124 |
|
125 Pauses playback of the media. |
|
126 |
|
127 Sets the \l playing and \l paused properties to true. |
|
128 */ |
|
129 |
|
130 void QDeclarativeAudio::pause() |
|
131 { |
|
132 if (m_playerControl == 0) |
|
133 return; |
|
134 |
|
135 setPaused(true); |
|
136 setPlaying(true); |
|
137 } |
|
138 |
|
139 /*! |
|
140 \qmlmethod Audio::stop() |
|
141 |
|
142 Stops playback of the media. |
|
143 |
|
144 Sets the \l playing and \l paused properties to false. |
|
145 */ |
|
146 |
|
147 void QDeclarativeAudio::stop() |
|
148 { |
|
149 if (m_playerControl == 0) |
|
150 return; |
|
151 |
|
152 setPlaying(false); |
|
153 setPaused(false); |
|
154 } |
|
155 |
|
156 /*! |
|
157 \qmlproperty url Audio::source |
|
158 |
|
159 This property holds the source URL of the media. |
|
160 */ |
|
161 |
|
162 /*! |
|
163 \qmlproperty url Audio::autoLoad |
|
164 |
|
165 This property indicates if loading of media should begin immediately. |
|
166 |
|
167 Defaults to true, if false media will not be loaded until playback is started. |
|
168 */ |
|
169 |
|
170 /*! |
|
171 \qmlproperty bool Audio::playing |
|
172 |
|
173 This property holds whether the media is playing. |
|
174 |
|
175 Defaults to false, and can be set to true to start playback. |
|
176 */ |
|
177 |
|
178 /*! |
|
179 \qmlproperty bool Audio::paused |
|
180 |
|
181 This property holds whether the media is paused. |
|
182 |
|
183 Defaults to false, and can be set to true to pause playback. |
|
184 */ |
|
185 |
|
186 /*! |
|
187 \qmlsignal Audio::onStarted() |
|
188 |
|
189 This handler is called when playback is started. |
|
190 */ |
|
191 |
|
192 /*! |
|
193 \qmlsignal Audio::onResumed() |
|
194 |
|
195 This handler is called when playback is resumed from the paused state. |
|
196 */ |
|
197 |
|
198 /*! |
|
199 \qmlsignal Audio::onPaused() |
|
200 |
|
201 This handler is called when playback is paused. |
|
202 */ |
|
203 |
|
204 /*! |
|
205 \qmlsignal Audio::onStopped() |
|
206 |
|
207 This handler is called when playback is stopped. |
|
208 */ |
|
209 |
|
210 /*! |
|
211 \qmlproperty enumeration Audio::status |
|
212 |
|
213 This property holds the status of media loading. It can be one of: |
|
214 |
|
215 \list |
|
216 \o NoMedia - no media has been set. |
|
217 \o Loading - the media is currently being loaded. |
|
218 \o Loaded - the media has been loaded. |
|
219 \o Buffering - the media is buffering data. |
|
220 \o Stalled - playback has been interrupted while the media is buffering data. |
|
221 \o Buffered - the media has buffered data. |
|
222 \o EndOfMedia - the media has played to the end. |
|
223 \o InvalidMedia - the media cannot be played. |
|
224 \o UnknownStatus - the status of the media is unknown. |
|
225 \endlist |
|
226 */ |
|
227 |
|
228 QDeclarativeAudio::Status QDeclarativeAudio::status() const |
|
229 { |
|
230 return Status(m_status); |
|
231 } |
|
232 |
|
233 /*! |
|
234 \qmlsignal Audio::onLoaded() |
|
235 |
|
236 This handler is called when the media source has been loaded. |
|
237 */ |
|
238 |
|
239 /*! |
|
240 \qmlsignal Audio::onBuffering() |
|
241 |
|
242 This handler is called when the media starts buffering. |
|
243 */ |
|
244 |
|
245 /*! |
|
246 \qmlsignal Audio::onStalled() |
|
247 |
|
248 This handler is called when playback has stalled while the media buffers. |
|
249 */ |
|
250 |
|
251 /*! |
|
252 \qmlsignal Audio::onBuffered() |
|
253 |
|
254 This handler is called when the media has finished buffering. |
|
255 */ |
|
256 |
|
257 /*! |
|
258 \qmlsignal Audio::onEndOfMedia() |
|
259 |
|
260 This handler is called when playback stops because end of the media has been reached. |
|
261 */ |
|
262 /*! |
|
263 \qmlproperty int Audio::duration |
|
264 |
|
265 This property holds the duration of the media in milliseconds. |
|
266 |
|
267 If the media doesn't have a fixed duration (a live stream for example) this will be 0. |
|
268 */ |
|
269 |
|
270 /*! |
|
271 \qmlproperty int Audio::position |
|
272 |
|
273 This property holds the current playback position in milliseconds. |
|
274 |
|
275 If the \l seekable property is true, this property can be set to seek to a new position. |
|
276 */ |
|
277 |
|
278 /*! |
|
279 \qmlproperty real Audio::volume |
|
280 |
|
281 This property holds the volume of the audio output, from 0.0 (silent) to 1.0 (maximum volume). |
|
282 */ |
|
283 |
|
284 /*! |
|
285 \qmlproperty bool Audio::muted |
|
286 |
|
287 This property holds whether the audio output is muted. |
|
288 */ |
|
289 |
|
290 /*! |
|
291 \qmlproperty real Audio::bufferProgress |
|
292 |
|
293 This property holds how much of the data buffer is currently filled, from 0.0 (empty) to 1.0 |
|
294 (full). |
|
295 */ |
|
296 |
|
297 /*! |
|
298 \qmlproperty bool Audio::seekable |
|
299 |
|
300 This property holds whether position of the audio can be changed. |
|
301 |
|
302 If true; setting a \l position value will cause playback to seek to the new position. |
|
303 */ |
|
304 |
|
305 /*! |
|
306 \qmlproperty real Audio::playbackRate |
|
307 |
|
308 This property holds the rate at which audio is played at as a multiple of the normal rate. |
|
309 */ |
|
310 |
|
311 /*! |
|
312 \qmlproperty enumeration Audio::error |
|
313 |
|
314 This property holds the error state of the audio. It can be one of: |
|
315 |
|
316 \list |
|
317 \o NoError - there is no current error. |
|
318 \o ResourceError - the audio cannot be played due to a problem allocating resources. |
|
319 \o FormatError - the audio format is not supported. |
|
320 \o NetworkError - the audio cannot be played due to network issues. |
|
321 \o AccessDenied - the audio cannot be played due to insufficient permissions. |
|
322 \o ServiceMissing - the audio cannot be played because the media service could not be |
|
323 instantiated. |
|
324 \endlist |
|
325 */ |
|
326 |
|
327 QDeclarativeAudio::Error QDeclarativeAudio::error() const |
|
328 { |
|
329 return Error(m_error); |
|
330 } |
|
331 |
|
332 void QDeclarativeAudio::componentComplete() |
|
333 { |
|
334 setObject(this); |
|
335 } |
|
336 |
|
337 |
|
338 /*! |
|
339 \qmlproperty string Audio::errorString |
|
340 |
|
341 This property holds a string describing the current error condition in more detail. |
|
342 */ |
|
343 |
|
344 /*! |
|
345 \qmlsignal Audio::onError(error, errorString) |
|
346 |
|
347 This handler is called when an \l {QMediaPlayer::Error}{error} has |
|
348 occurred. The errorString parameter may contain more detailed |
|
349 information about the error. |
|
350 */ |
|
351 |
|
352 QT_END_NAMESPACE |
|
353 |
|
354 #include "moc_qdeclarativeaudio_p.cpp" |
|
355 |
|
356 |