|
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 <QtTest/QtTest> |
|
43 #include <QtCore> |
|
44 #include <QtGui> |
|
45 #include <QFile> |
|
46 |
|
47 #include <QMediaPlayer> |
|
48 #include <QMediaPlayerControl> |
|
49 #include <QMediaPlaylist> |
|
50 #include <QMediaService> |
|
51 #include <QMediaStreamsControl> |
|
52 #include <QVideoWidget> |
|
53 |
|
54 QTM_USE_NAMESPACE |
|
55 |
|
56 #define WAIT_FOR_CONDITION(a,e) \ |
|
57 for (int _i = 0; _i < 500; _i += 1) { \ |
|
58 if ((a) == (e)) break; \ |
|
59 QTest::qWait(10);} |
|
60 |
|
61 |
|
62 #define WAIT_LONG_FOR_CONDITION(a,e) \ |
|
63 for (int _i = 0; _i < 1800; _i += 1) { \ |
|
64 if ((a) == (e)) break; \ |
|
65 QTest::qWait(100);} |
|
66 |
|
67 class mediaStatusList : public QObject, public QList<QMediaPlayer::MediaStatus> |
|
68 { |
|
69 Q_OBJECT |
|
70 public slots: |
|
71 void mediaStatus(QMediaPlayer::MediaStatus status) { |
|
72 append(status); |
|
73 } |
|
74 |
|
75 public: |
|
76 mediaStatusList(QObject *obj, const char *aSignal) |
|
77 : QObject() |
|
78 { |
|
79 connect(obj, aSignal, this, SLOT(mediaStatus(QMediaPlayer::MediaStatus))); |
|
80 } |
|
81 }; |
|
82 |
|
83 class MockProvider : public QMediaServiceProvider |
|
84 { |
|
85 public: |
|
86 MockProvider(QMediaService *service):mockService(service) {} |
|
87 QMediaService *requestService(const QByteArray &, const QMediaServiceProviderHint &) |
|
88 { |
|
89 return mockService; |
|
90 } |
|
91 |
|
92 void releaseService(QMediaService *service) { delete service; } |
|
93 |
|
94 QMediaService *mockService; |
|
95 }; |
|
96 |
|
97 class tst_QMediaPlayer: public QObject |
|
98 { |
|
99 Q_OBJECT |
|
100 |
|
101 public slots: |
|
102 void initTestCase_data(); |
|
103 void initTestCase_data_default_winscw(); |
|
104 void initTestCase_data_default_armv5(); |
|
105 void initTestCase_data_50_winscw(); |
|
106 void initTestCase_data_50_armv5(); |
|
107 void initTestCase_data_32_winscw(); |
|
108 void initTestCase_data_32_armv5(); |
|
109 void initTestCase_data_31_winscw(); |
|
110 void initTestCase_data_31_armv5(); |
|
111 void initTestCase(); |
|
112 void cleanupTestCase(); |
|
113 void init(); |
|
114 void cleanup(); |
|
115 |
|
116 private slots: |
|
117 void testPositionWhilePlaying(); |
|
118 void testNullService(); |
|
119 void testMedia(); |
|
120 void testDuration(); |
|
121 void testPosition(); |
|
122 |
|
123 void testVolume(); |
|
124 void testVolumeWhilePlaying(); |
|
125 void testMuted(); |
|
126 void testMutedWhilePlaying(); |
|
127 void testVideoAndAudioAvailability(); |
|
128 void testError(); |
|
129 void testPlay(); |
|
130 void testPause(); |
|
131 void testStop(); |
|
132 void testMediaStatus(); |
|
133 void testPlaylist(); |
|
134 void testPlaybackRate(); |
|
135 void testPlaybackRateWhilePlaying(); |
|
136 |
|
137 |
|
138 private: |
|
139 QMediaPlayer *m_player; |
|
140 QVideoWidget *m_widget; |
|
141 bool runonce; |
|
142 }; |
|
143 |
|
144 void tst_QMediaPlayer::initTestCase_data() |
|
145 { |
|
146 #ifdef __WINSCW__ |
|
147 if(QSysInfo::s60Version() == QSysInfo::SV_S60_3_1) |
|
148 initTestCase_data_31_winscw(); |
|
149 else if(QSysInfo::s60Version() == QSysInfo::SV_S60_3_2) |
|
150 initTestCase_data_32_winscw(); |
|
151 else if(QSysInfo::s60Version() == QSysInfo::SV_S60_5_0) |
|
152 initTestCase_data_50_winscw(); |
|
153 else |
|
154 initTestCase_data_default_winscw(); |
|
155 #else |
|
156 if(QSysInfo::s60Version() == QSysInfo::SV_S60_3_1) |
|
157 initTestCase_data_31_armv5(); |
|
158 else if(QSysInfo::s60Version() == QSysInfo::SV_S60_3_2) |
|
159 initTestCase_data_32_armv5(); |
|
160 else if(QSysInfo::s60Version() == QSysInfo::SV_S60_5_0) |
|
161 initTestCase_data_50_armv5(); |
|
162 else |
|
163 initTestCase_data_default_armv5(); |
|
164 #endif |
|
165 } |
|
166 |
|
167 void tst_QMediaPlayer::initTestCase_data_default_winscw() |
|
168 { |
|
169 //TODO: add data |
|
170 } |
|
171 |
|
172 void tst_QMediaPlayer::initTestCase_data_default_armv5() |
|
173 { |
|
174 //TODO: add data |
|
175 } |
|
176 |
|
177 void tst_QMediaPlayer::initTestCase_data_50_winscw() |
|
178 { |
|
179 QTest::addColumn<bool>("valid"); |
|
180 QTest::addColumn<QMediaPlayer::State>("state"); |
|
181 QTest::addColumn<QMediaPlayer::MediaStatus>("status"); |
|
182 QTest::addColumn<QMediaContent>("mediaContent"); |
|
183 QTest::addColumn<qint64>("duration"); |
|
184 QTest::addColumn<qint64>("position"); |
|
185 QTest::addColumn<bool>("seekable"); |
|
186 QTest::addColumn<bool>("seekableWhilePlaying"); |
|
187 QTest::addColumn<int>("volume"); |
|
188 QTest::addColumn<bool>("videoAvailable"); |
|
189 QTest::addColumn<bool>("audioAvailable"); |
|
190 QTest::addColumn<qreal>("playbackRate"); |
|
191 QTest::addColumn<QMediaPlayer::Error>("error"); |
|
192 QTest::addColumn<QString>("errorString"); |
|
193 |
|
194 QTest::newRow("TestDataNull") |
|
195 << false //valid |
|
196 << QMediaPlayer::StoppedState // state |
|
197 << QMediaPlayer::NoMedia // status |
|
198 << QMediaContent() // mediaContent |
|
199 << qint64(-1) // duration |
|
200 << qint64(0) // position |
|
201 << false // seekable |
|
202 << false // seekableWhilePlaying |
|
203 << 50 // volume |
|
204 << false // videoAvailable |
|
205 << false //audioAvailable |
|
206 << qreal(0) // playbackRate |
|
207 << QMediaPlayer::NoError // error |
|
208 << QString(); // errorString |
|
209 |
|
210 QTest::newRow("test_3GPP.dat") |
|
211 << true //valid |
|
212 << QMediaPlayer::StoppedState // state |
|
213 << QMediaPlayer::LoadedMedia // status |
|
214 << QMediaContent(QUrl("file:///C:/data/testfiles/test_3GPP.dat")) // mediaContent |
|
215 << qint64(7200) // duration |
|
216 << qint64(3600) // position (duration/2) |
|
217 << true // seekable |
|
218 << false // seekableWhilePlaying |
|
219 << 50 // volume |
|
220 << true // videoAvailable |
|
221 << true //audioAvailable |
|
222 << qreal(0) // playbackRate |
|
223 << QMediaPlayer::NoError // error |
|
224 << QString(); // errorString |
|
225 |
|
226 QTest::newRow("test_3gp.3gp") |
|
227 << true //valid |
|
228 << QMediaPlayer::StoppedState // state |
|
229 << QMediaPlayer::LoadedMedia // status |
|
230 << QMediaContent(QUrl("file:///C:/data/testfiles/test_3gp.3gp")) // mediaContent |
|
231 << qint64(46860) // duration |
|
232 << qint64(23430) // position (duration/2) |
|
233 << true // seekable |
|
234 << true // seekableWhilePlaying |
|
235 << 50 // volume |
|
236 << true // videoAvailable |
|
237 << true //audioAvailable |
|
238 << qreal(0) // playbackRate |
|
239 << QMediaPlayer::NoError // error |
|
240 << QString(); // errorString |
|
241 |
|
242 QTest::newRow("test_mp4.mp4") |
|
243 << true //valid |
|
244 << QMediaPlayer::StoppedState // state |
|
245 << QMediaPlayer::LoadedMedia // status |
|
246 << QMediaContent(QUrl("file:///C:/data/testfiles/test_mp4.mp4")) // mediaContent |
|
247 << qint64(2701) // duration |
|
248 << qint64(1351) // position (duration/2) |
|
249 << true // seekable |
|
250 << true // seekableWhilePlaying |
|
251 << 50 // volume |
|
252 << true // videoAvailable |
|
253 << false //audioAvailable |
|
254 << qreal(0) // playbackRate |
|
255 << QMediaPlayer::FormatError // error |
|
256 << QString(); // errorString |
|
257 |
|
258 QTest::newRow("test_MP4.dat") |
|
259 << false //valid |
|
260 << QMediaPlayer::StoppedState // state |
|
261 << QMediaPlayer::InvalidMedia // status |
|
262 << QMediaContent(QUrl("file:///C:/data/testfiles/test_MP4.dat")) // mediaContent |
|
263 << qint64(-1) // duration |
|
264 << qint64(0) // position (duration/2) |
|
265 << true // seekable |
|
266 << false // seekableWhilePlaying |
|
267 << 50 // volume |
|
268 << true // videoAvailable |
|
269 << false //audioAvailable |
|
270 << qreal(0) // playbackRate |
|
271 << QMediaPlayer::AccessDeniedError// error |
|
272 << QString(); // errorString |
|
273 |
|
274 QTest::newRow("test_wmv9.wmv") |
|
275 << true //valid |
|
276 << QMediaPlayer::StoppedState // state |
|
277 << QMediaPlayer::LoadedMedia // status |
|
278 << QMediaContent(QUrl("file:///C:/data/testfiles/test_wmv9.wmv")) // mediaContent |
|
279 << qint64(169389) // duration |
|
280 << qint64(84695) // position (duration/2) |
|
281 << true // seekable |
|
282 << false // seekableWhilePlaying |
|
283 << 50 // volume |
|
284 << true // videoAvailable |
|
285 << false //audioAvailable |
|
286 << qreal(0) // playbackRate |
|
287 << QMediaPlayer::FormatError // error |
|
288 << QString(); // errorString |
|
289 |
|
290 QTest::newRow("test_h264_qcif.264") |
|
291 << false //valid |
|
292 << QMediaPlayer::StoppedState // state |
|
293 << QMediaPlayer::InvalidMedia // status |
|
294 << QMediaContent(QUrl("file:///C:/data/testfiles/test_h264_qcif.264")) // mediaContent |
|
295 << qint64(-1) // duration |
|
296 << qint64(0) // position (duration/2) |
|
297 << false // seekable |
|
298 << false // seekableWhilePlaying |
|
299 << 50 // volume |
|
300 << false // videoAvailable |
|
301 << false //audioAvailable |
|
302 << qreal(0) // playbackRate |
|
303 << QMediaPlayer::ResourceError // error |
|
304 << QString(); // errorString |
|
305 |
|
306 QTest::newRow("test_RM.dat") |
|
307 << true //valid |
|
308 << QMediaPlayer::StoppedState // state |
|
309 << QMediaPlayer::LoadedMedia // status |
|
310 << QMediaContent(QUrl("file:///C:/data/testfiles/test_RM.dat")) // mediaContent |
|
311 << qint64(20245) // duration |
|
312 << qint64(10123) // position (duration/2) |
|
313 << true // seekable |
|
314 << false // seekableWhilePlaying |
|
315 << 50 // volume |
|
316 << true // videoAvailable |
|
317 << true //audioAvailable |
|
318 << qreal(0) // playbackRate |
|
319 << QMediaPlayer::NoError // error |
|
320 << QString(); // errorString |
|
321 |
|
322 QTest::newRow("test_SWF.dat") |
|
323 << false //valid |
|
324 << QMediaPlayer::StoppedState // state |
|
325 << QMediaPlayer::InvalidMedia // status |
|
326 << QMediaContent(QUrl("file:///C:/data/testfiles/test_SWF.dat")) // mediaContent |
|
327 << qint64(-1) // duration |
|
328 << qint64(0) // position (duration/2) |
|
329 << false // seekable |
|
330 << false // seekableWhilePlaying |
|
331 << 50 // volume |
|
332 << false // videoAvailable |
|
333 << false //audioAvailable |
|
334 << qreal(0) // playbackRate |
|
335 << QMediaPlayer::ResourceError // error |
|
336 << QString(); // errorString |
|
337 |
|
338 QTest::newRow("test_WMV.dat") |
|
339 << true //valid |
|
340 << QMediaPlayer::StoppedState // state |
|
341 << QMediaPlayer::LoadedMedia // status |
|
342 << QMediaContent(QUrl("file:///C:/data/testfiles/test_WMV.dat")) // mediaContent |
|
343 << qint64(3098) // duration |
|
344 << qint64(1549) // position (duration/2) |
|
345 << true // seekable |
|
346 << false // seekableWhilePlaying, on emulator codec leaks memory and causes alloc panic on dtor |
|
347 << 50 // volume |
|
348 << true // videoAvailable |
|
349 << false //audioAvailable |
|
350 << qreal(0) // playbackRate |
|
351 << QMediaPlayer::FormatError // error |
|
352 << QString(); // errorString |
|
353 |
|
354 QTest::newRow("test_WMA.dat") |
|
355 << false //valid |
|
356 << QMediaPlayer::StoppedState // state |
|
357 << QMediaPlayer::InvalidMedia // status |
|
358 << QMediaContent(QUrl("file:///C:/data/testfiles/test_WMA.dat")) // mediaContent |
|
359 << qint64(-1) // duration |
|
360 << qint64(0) // position (duration/2) |
|
361 << true // seekable |
|
362 << false // seekableWhilePlaying |
|
363 << 50 // volume |
|
364 << true // videoAvailable |
|
365 << false //audioAvailable |
|
366 << qreal(0) // playbackRate |
|
367 << QMediaPlayer::AccessDeniedError // error |
|
368 << QString(); // errorString |
|
369 |
|
370 QTest::newRow("test_flash_video.flv") |
|
371 << false // valid |
|
372 << QMediaPlayer::StoppedState // state |
|
373 << QMediaPlayer::InvalidMedia // status |
|
374 << QMediaContent(QUrl("file:///C:/data/testfiles/test_flash_video.flv")) // mediaContent |
|
375 << qint64(-1) // duration |
|
376 << qint64(0) // position |
|
377 << false // seekable |
|
378 << false // seekableWhilePlaying |
|
379 << 50 // volume |
|
380 << false // videoAvailable |
|
381 << false //audioAvailable |
|
382 << qreal(0) // playbackRate |
|
383 << QMediaPlayer::ResourceError // error |
|
384 << QString(); // errorString |
|
385 |
|
386 QTest::newRow("test_MXMF.dat") |
|
387 << true //valid |
|
388 << QMediaPlayer::StoppedState // state |
|
389 << QMediaPlayer::LoadedMedia // status |
|
390 << QMediaContent(QUrl("file:///C:/data/testfiles/test_MXMF.dat")) // mediaContent |
|
391 << qint64(31980) // duration |
|
392 << qint64(15990) // position (duration/2) |
|
393 << true // seekable |
|
394 << true // seekableWhilePlaying |
|
395 << 50 // volume |
|
396 << false // videoAvailable |
|
397 << true //audioAvailable |
|
398 << qreal(0) // playbackRate |
|
399 << QMediaPlayer::NoError // error |
|
400 << QString(); // errorString |
|
401 |
|
402 QTest::newRow("test_amr.amr") |
|
403 << true // valid |
|
404 << QMediaPlayer::StoppedState // state |
|
405 << QMediaPlayer::LoadedMedia // status |
|
406 << QMediaContent(QUrl("file:///C:/data/testfiles/test_amr.amr")) // mediaContent |
|
407 << qint64(14402) // duration |
|
408 << qint64(7200) // position |
|
409 << true // seekable |
|
410 << false // seekableWhilePlaying |
|
411 << 50 // volume |
|
412 << false // videoAvailable |
|
413 << true // audioAvailable |
|
414 << qreal(0) // playbackRate |
|
415 << QMediaPlayer::NoError // error |
|
416 << QString(); // errorString |
|
417 |
|
418 QTest::newRow("test_AMR.dat") |
|
419 << true // valid |
|
420 << QMediaPlayer::StoppedState // state |
|
421 << QMediaPlayer::LoadedMedia // status |
|
422 << QMediaContent(QUrl("file:///C:/data/testfiles/test_AMR.dat")) // mediaContent |
|
423 << qint64(38509) // duration |
|
424 << qint64(19255) // position |
|
425 << true // seekable |
|
426 << false // seekableWhilePlaying |
|
427 << 50 // volume |
|
428 << false // videoAvailable |
|
429 << true // audioAvailable |
|
430 << qreal(0) // playbackRate |
|
431 << QMediaPlayer::NoError // error |
|
432 << QString(); // errorString |
|
433 |
|
434 QTest::newRow("test_mp3.mp3") |
|
435 << false // valid |
|
436 << QMediaPlayer::StoppedState // state |
|
437 << QMediaPlayer::InvalidMedia // status |
|
438 << QMediaContent(QUrl("file:///C:/data/testfiles/test_mp3.mp3")) // mediaContent |
|
439 << qint64(-1) //qint64(102044) duration |
|
440 << qint64(0) // position |
|
441 << false // seekable |
|
442 << false // seekableWhilePlaying |
|
443 << 50 // volume |
|
444 << false // videoAvailable |
|
445 << false // audioAvailable |
|
446 << qreal(0) // playbackRate |
|
447 << QMediaPlayer::ResourceError // error |
|
448 << QString(); // errorString |
|
449 |
|
450 QTest::newRow("test_MP3.dat") |
|
451 << false // valid |
|
452 << QMediaPlayer::StoppedState // state |
|
453 << QMediaPlayer::InvalidMedia // status |
|
454 << QMediaContent(QUrl("file:///C:/data/testfiles/test_MP3.dat")) // mediaContent |
|
455 << qint64(-1) //qint64(102044) duration |
|
456 << qint64(0) // position |
|
457 << false // seekable |
|
458 << false // seekableWhilePlaying |
|
459 << 50 // volume |
|
460 << false // videoAvailable |
|
461 << false // audioAvailable |
|
462 << qreal(0) // playbackRate |
|
463 << QMediaPlayer::ResourceError // error |
|
464 << QString(); // errorString |
|
465 |
|
466 QTest::newRow("test_MIDI.dat") |
|
467 << true // valid |
|
468 << QMediaPlayer::StoppedState // state |
|
469 << QMediaPlayer::LoadedMedia // status |
|
470 << QMediaContent(QUrl("file:///C:/data/testfiles/test_MIDI.dat")) // mediaContent |
|
471 << qint64(32782) // duration |
|
472 << qint64(16391) // position |
|
473 << true // seekable |
|
474 << true // seekableWhilePlaying |
|
475 << 50 // volume |
|
476 << false // videoAvailable |
|
477 << true // audioAvailable |
|
478 << qreal(0) // playbackRate |
|
479 << QMediaPlayer::NoError // error |
|
480 << QString(); // errorString |
|
481 |
|
482 QTest::newRow("test_ACC.dat") |
|
483 << false // valid |
|
484 << QMediaPlayer::StoppedState // state |
|
485 << QMediaPlayer::InvalidMedia // status |
|
486 << QMediaContent(QUrl("file:///C:/data/testfiles/test_ACC.dat")) // mediaContent |
|
487 << qint64(-1) // duration |
|
488 << qint64(0) // position |
|
489 << false // seekable |
|
490 << false // seekableWhilePlaying |
|
491 << 50 // volume |
|
492 << false // videoAvailable |
|
493 << false // audioAvailable |
|
494 << qreal(0) // playbackRate |
|
495 << QMediaPlayer::ResourceError // error |
|
496 << QString(); // errorString |
|
497 |
|
498 QTest::newRow("test_WAV.dat") |
|
499 << true // valid |
|
500 << QMediaPlayer::StoppedState // state |
|
501 << QMediaPlayer::LoadedMedia // status |
|
502 << QMediaContent(QUrl("file:///C:/data/testfiles/test_WAV.dat")) // mediaContent |
|
503 << qint64(2864) // duration |
|
504 << qint64(1432) // position |
|
505 << true // seekable |
|
506 << true // seekableWhilePlaying |
|
507 << 50 // volume |
|
508 << false // videoAvailable |
|
509 << true // audioAvailable |
|
510 << qreal(0) // playbackRate |
|
511 << QMediaPlayer::NoError // error |
|
512 << QString(); // errorString |
|
513 |
|
514 QTest::newRow("test_stream") |
|
515 << false // valid |
|
516 << QMediaPlayer::StoppedState // state |
|
517 << QMediaPlayer::InvalidMedia // status |
|
518 << QMediaContent(QUrl("rtsp://v3.cache4.c.youtube.com/CkgLENy73wIaPwlU2rm7yu8PFhMYESARFEIJbXYtZ29vZ2xlSARSB3JlbGF0ZWRaDkNsaWNrVGh1bWJuYWlsYPi6_IXT2rvpSgw=/0/0/0/video.3gp")) // mediaContent |
|
519 << qint64(-1) // duration |
|
520 << qint64(0) // position |
|
521 << false // seekable |
|
522 << false // seekableWhilePlaying |
|
523 << 50 // volume |
|
524 << true // videoAvailable |
|
525 << false // audioAvailable |
|
526 << qreal(0) // playbackRate |
|
527 << QMediaPlayer::AccessDeniedError // error |
|
528 << QString(); // errorString |
|
529 } |
|
530 |
|
531 void tst_QMediaPlayer::initTestCase_data_50_armv5() |
|
532 { |
|
533 //TODO: add data |
|
534 } |
|
535 |
|
536 void tst_QMediaPlayer::initTestCase_data_32_winscw() |
|
537 { |
|
538 //TODO: add data |
|
539 } |
|
540 |
|
541 void tst_QMediaPlayer::initTestCase_data_32_armv5() |
|
542 { |
|
543 //TODO: add data |
|
544 } |
|
545 |
|
546 void tst_QMediaPlayer::initTestCase_data_31_winscw() |
|
547 { |
|
548 //backend does not compile on winscw due missing libs. |
|
549 } |
|
550 |
|
551 void tst_QMediaPlayer::initTestCase_data_31_armv5() |
|
552 { |
|
553 //TODO: add data |
|
554 } |
|
555 |
|
556 void tst_QMediaPlayer::initTestCase() |
|
557 { |
|
558 m_player = new QMediaPlayer(); |
|
559 |
|
560 // Symbian back end needs coecontrol for creation. |
|
561 m_widget = new QVideoWidget(); |
|
562 m_widget->setMediaObject(m_player); |
|
563 m_widget->show(); |
|
564 runonce = false; |
|
565 } |
|
566 |
|
567 void tst_QMediaPlayer::cleanupTestCase() |
|
568 { |
|
569 delete m_player; |
|
570 delete m_widget; |
|
571 } |
|
572 |
|
573 void tst_QMediaPlayer::init() |
|
574 { |
|
575 qRegisterMetaType<QMediaPlayer::State>("QMediaPlayer::State"); |
|
576 qRegisterMetaType<QMediaPlayer::Error>("QMediaPlayer::Error"); |
|
577 qRegisterMetaType<QMediaPlayer::MediaStatus>("QMediaPlayer::MediaStatus"); |
|
578 qRegisterMetaType<QMediaContent>("QMediaContent"); |
|
579 } |
|
580 |
|
581 void tst_QMediaPlayer::cleanup() |
|
582 { |
|
583 } |
|
584 |
|
585 void tst_QMediaPlayer::testNullService() |
|
586 { |
|
587 if(runonce) |
|
588 return; |
|
589 MockProvider provider(0); |
|
590 QMediaPlayer player(0, 0, &provider); |
|
591 |
|
592 const QIODevice *nullDevice = 0; |
|
593 |
|
594 QCOMPARE(player.media(), QMediaContent()); |
|
595 QCOMPARE(player.mediaStream(), nullDevice); |
|
596 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
597 QCOMPARE(player.mediaStatus(), QMediaPlayer::UnknownMediaStatus); |
|
598 QCOMPARE(player.duration(), qint64(-1)); |
|
599 QCOMPARE(player.position(), qint64(0)); |
|
600 QCOMPARE(player.volume(), 0); |
|
601 QCOMPARE(player.isMuted(), false); |
|
602 QCOMPARE(player.isVideoAvailable(), false); |
|
603 QCOMPARE(player.bufferStatus(), 0); |
|
604 QCOMPARE(player.isSeekable(), false); |
|
605 QCOMPARE(player.playbackRate(), qreal(0)); |
|
606 QCOMPARE(player.error(), QMediaPlayer::ServiceMissingError); |
|
607 |
|
608 { |
|
609 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
610 |
|
611 QSignalSpy spy(&player, SIGNAL(mediaChanged(QMediaContent))); |
|
612 QFile file; |
|
613 |
|
614 player.setMedia(mediaContent, &file); |
|
615 QCOMPARE(player.media(), QMediaContent()); |
|
616 QCOMPARE(player.mediaStream(), nullDevice); |
|
617 QCOMPARE(spy.count(), 0); |
|
618 } { |
|
619 QSignalSpy stateSpy(&player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
620 QSignalSpy statusSpy(&player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); |
|
621 |
|
622 player.play(); |
|
623 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
624 QCOMPARE(player.mediaStatus(), QMediaPlayer::UnknownMediaStatus); |
|
625 QCOMPARE(stateSpy.count(), 0); |
|
626 QCOMPARE(statusSpy.count(), 0); |
|
627 |
|
628 player.pause(); |
|
629 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
630 QCOMPARE(player.mediaStatus(), QMediaPlayer::UnknownMediaStatus); |
|
631 QCOMPARE(stateSpy.count(), 0); |
|
632 QCOMPARE(statusSpy.count(), 0); |
|
633 |
|
634 player.stop(); |
|
635 QCOMPARE(player.state(), QMediaPlayer::StoppedState); |
|
636 QCOMPARE(player.mediaStatus(), QMediaPlayer::UnknownMediaStatus); |
|
637 QCOMPARE(stateSpy.count(), 0); |
|
638 QCOMPARE(statusSpy.count(), 0); |
|
639 } { |
|
640 QFETCH_GLOBAL(int, volume); |
|
641 |
|
642 QSignalSpy volumeSpy(&player, SIGNAL(volumeChanged(int))); |
|
643 QSignalSpy mutingSpy(&player, SIGNAL(mutedChanged(bool))); |
|
644 |
|
645 player.setVolume(volume); |
|
646 QCOMPARE(player.volume(), 0); |
|
647 QCOMPARE(volumeSpy.count(), 0); |
|
648 |
|
649 player.setMuted(false); |
|
650 QCOMPARE(player.isMuted(), false); |
|
651 QCOMPARE(mutingSpy.count(), 0); |
|
652 } { |
|
653 QFETCH_GLOBAL(qint64, position); |
|
654 |
|
655 QSignalSpy spy(&player, SIGNAL(positionChanged(qint64))); |
|
656 |
|
657 player.setPosition(position); |
|
658 QCOMPARE(player.position(), qint64(0)); |
|
659 QCOMPARE(spy.count(), 0); |
|
660 } { |
|
661 QFETCH_GLOBAL(qreal, playbackRate); |
|
662 |
|
663 QSignalSpy spy(&player, SIGNAL(playbackRateChanged(qreal))); |
|
664 |
|
665 player.setPlaybackRate(playbackRate); |
|
666 QCOMPARE(player.playbackRate(), qreal(0)); |
|
667 QCOMPARE(spy.count(), 0); |
|
668 } { |
|
669 QMediaPlaylist playlist; |
|
670 playlist.setMediaObject(&player); |
|
671 |
|
672 QSignalSpy mediaSpy(&player, SIGNAL(mediaChanged(QMediaContent))); |
|
673 QSignalSpy statusSpy(&player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); |
|
674 |
|
675 playlist.addMedia(QUrl("http://example.com/stream")); |
|
676 playlist.addMedia(QUrl("file:///some.mp3")); |
|
677 |
|
678 playlist.setCurrentIndex(0); |
|
679 QCOMPARE(playlist.currentIndex(), 0); |
|
680 QCOMPARE(player.media(), QMediaContent()); |
|
681 QCOMPARE(mediaSpy.count(), 0); |
|
682 QCOMPARE(statusSpy.count(), 0); |
|
683 |
|
684 playlist.next(); |
|
685 QCOMPARE(playlist.currentIndex(), 1); |
|
686 QCOMPARE(player.media(), QMediaContent()); |
|
687 QCOMPARE(mediaSpy.count(), 0); |
|
688 QCOMPARE(statusSpy.count(), 0); |
|
689 } |
|
690 runonce = true; |
|
691 } |
|
692 |
|
693 void tst_QMediaPlayer::testMedia() |
|
694 { |
|
695 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
696 m_player->setMedia(mediaContent); |
|
697 QTest::qWait(500); |
|
698 QCOMPARE(m_player->media(), mediaContent); |
|
699 } |
|
700 |
|
701 |
|
702 void tst_QMediaPlayer::testDuration() |
|
703 { |
|
704 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
705 QFETCH_GLOBAL(qint64, duration); |
|
706 QFETCH_GLOBAL(bool, valid); |
|
707 |
|
708 QSignalSpy spy(m_player, SIGNAL(durationChanged(qint64))); |
|
709 m_player->setMedia(mediaContent); |
|
710 |
|
711 if(valid) { |
|
712 WAIT_FOR_CONDITION(spy.count(), 1); |
|
713 } else { |
|
714 WAIT_FOR_CONDITION(m_player->mediaStatus(), (QMediaPlayer::NoMedia || QMediaPlayer::InvalidMedia)); |
|
715 } |
|
716 |
|
717 QVERIFY(m_player->duration() == duration); |
|
718 //qDebug()<<m_player->duration()<<m_player->error();; |
|
719 } |
|
720 |
|
721 void tst_QMediaPlayer::testPosition() |
|
722 { |
|
723 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
724 QFETCH_GLOBAL(qint64, duration); |
|
725 QFETCH_GLOBAL(bool, valid); |
|
726 QFETCH_GLOBAL(bool, seekable); |
|
727 QFETCH_GLOBAL(qint64, position); |
|
728 QFETCH_GLOBAL(QMediaPlayer::MediaStatus, status); |
|
729 |
|
730 m_player->setMedia(mediaContent); |
|
731 |
|
732 if (valid) { |
|
733 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::LoadedMedia); |
|
734 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
735 |
|
736 QCOMPARE(m_player->isSeekable(), seekable); |
|
737 QCOMPARE(m_player->mediaStatus(), status); |
|
738 |
|
739 // preset position |
|
740 { QSignalSpy spy(m_player, SIGNAL(positionChanged(qint64))); |
|
741 m_player->setPosition(position); |
|
742 QCOMPARE(m_player->position(), position); |
|
743 QCOMPARE(spy.count(), 1); |
|
744 QCOMPARE(spy.at(0).at(0).toLongLong(), position);} |
|
745 |
|
746 // same pos second time |
|
747 { QSignalSpy spy(m_player, SIGNAL(positionChanged(qint64))); |
|
748 m_player->setPosition(position); |
|
749 QCOMPARE(m_player->position(), position); |
|
750 QCOMPARE(spy.count(), 0);} |
|
751 |
|
752 //zero pos |
|
753 { QSignalSpy spy(m_player, SIGNAL(positionChanged(qint64))); |
|
754 m_player->setPosition(0); |
|
755 QCOMPARE(m_player->position(), qint64(0)); |
|
756 QCOMPARE(spy.count(), 1); |
|
757 QCOMPARE(spy.at(0).at(0).toLongLong(), qint64(0));} |
|
758 |
|
759 //end pos |
|
760 { QSignalSpy spy(m_player, SIGNAL(positionChanged(qint64))); |
|
761 m_player->setPosition(duration); |
|
762 QCOMPARE(m_player->position(), duration); |
|
763 QCOMPARE(spy.count(), 1); |
|
764 QCOMPARE(spy.at(0).at(0).toLongLong(), duration);} |
|
765 |
|
766 //negative pos |
|
767 { QSignalSpy spy(m_player, SIGNAL(positionChanged(qint64))); |
|
768 m_player->setPosition(qint64(-1)); |
|
769 QCOMPARE(m_player->position(), qint64(0)); |
|
770 QCOMPARE(spy.count(), 1); |
|
771 QCOMPARE(spy.at(0).at(0).toLongLong(), qint64(0));} |
|
772 |
|
773 //over duration |
|
774 { QSignalSpy spy(m_player, SIGNAL(positionChanged(qint64))); |
|
775 m_player->setPosition(duration+1); |
|
776 QCOMPARE(m_player->position(), duration); |
|
777 QCOMPARE(spy.count(), 1); |
|
778 QCOMPARE(spy.at(0).at(0).toLongLong(), duration);} |
|
779 |
|
780 } else { |
|
781 WAIT_FOR_CONDITION(m_player->mediaStatus(), (QMediaPlayer::NoMedia || QMediaPlayer::InvalidMedia)); |
|
782 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
783 QCOMPARE(m_player->isSeekable(), seekable); |
|
784 QCOMPARE(m_player->mediaStatus(), status); |
|
785 } |
|
786 } |
|
787 |
|
788 void tst_QMediaPlayer::testPositionWhilePlaying() |
|
789 { |
|
790 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
791 QFETCH_GLOBAL(qint64, duration); |
|
792 QFETCH_GLOBAL(bool, seekableWhilePlaying); |
|
793 QFETCH_GLOBAL(bool, seekable); |
|
794 QFETCH_GLOBAL(qint64, position); |
|
795 QFETCH_GLOBAL(bool, valid); |
|
796 QFETCH_GLOBAL(QMediaPlayer::MediaStatus, status); |
|
797 |
|
798 m_player->setMedia(mediaContent); |
|
799 WAIT_FOR_CONDITION(m_player->mediaStatus(), (QMediaPlayer::NoMedia || QMediaPlayer::InvalidMedia || QMediaPlayer::LoadedMedia)); |
|
800 |
|
801 //qDebug()<<""; |
|
802 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
803 QCOMPARE(m_player->isSeekable(), seekable); |
|
804 QCOMPARE(m_player->mediaStatus(), status); |
|
805 |
|
806 if (seekableWhilePlaying) { |
|
807 QCOMPARE(m_player->isSeekable(), seekableWhilePlaying); |
|
808 |
|
809 // preset position |
|
810 //qDebug()<<"preset"; |
|
811 { QSignalSpy spy(m_player, SIGNAL(positionChanged(qint64))); |
|
812 m_player->play(); |
|
813 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
814 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
815 m_player->setPosition(position); |
|
816 WAIT_FOR_CONDITION(spy.count(), 2); |
|
817 QVERIFY(m_player->mediaStatus() == QMediaPlayer::BufferingMedia || |
|
818 m_player->mediaStatus() == QMediaPlayer::BufferedMedia); |
|
819 |
|
820 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
821 QVERIFY(m_player->position()>=position); |
|
822 QVERIFY(spy.count()!=0);} |
|
823 |
|
824 //reset position |
|
825 m_player->stop(); |
|
826 m_player->setPosition(position); |
|
827 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
828 |
|
829 //zero pos |
|
830 //qDebug()<<"zero"; |
|
831 { QSignalSpy spy(m_player, SIGNAL(positionChanged(qint64))); |
|
832 m_player->play(); |
|
833 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
834 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
835 m_player->setPosition(0); |
|
836 WAIT_FOR_CONDITION(spy.count(), 2); |
|
837 QVERIFY(m_player->mediaStatus() == QMediaPlayer::BufferingMedia || |
|
838 m_player->mediaStatus() == QMediaPlayer::BufferedMedia); |
|
839 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
840 QVERIFY(m_player->position() >= qint64(0)); |
|
841 QVERIFY(spy.count()!=0);} |
|
842 |
|
843 //reset position |
|
844 m_player->stop(); |
|
845 m_player->setPosition(position); |
|
846 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
847 |
|
848 //end pos |
|
849 //qDebug()<<"dur"; |
|
850 { QSignalSpy spy(m_player, SIGNAL(positionChanged(qint64))); |
|
851 m_player->play(); |
|
852 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
853 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
854 m_player->setPosition(duration); |
|
855 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::EndOfMedia); |
|
856 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::EndOfMedia); |
|
857 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
858 QCOMPARE(m_player->position(), qint64(0)); |
|
859 QVERIFY(spy.count()!=0);} |
|
860 |
|
861 //reset position |
|
862 m_player->stop(); |
|
863 m_player->setPosition(position); |
|
864 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
865 |
|
866 //negative pos |
|
867 //qDebug()<<"negavite"; |
|
868 { QSignalSpy spy(m_player, SIGNAL(positionChanged(qint64))); |
|
869 m_player->play(); |
|
870 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
871 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
872 m_player->setPosition(qint64(-1)); |
|
873 WAIT_FOR_CONDITION(spy.count(), 2); |
|
874 QVERIFY(m_player->mediaStatus() == QMediaPlayer::BufferingMedia || |
|
875 m_player->mediaStatus() == QMediaPlayer::BufferedMedia); |
|
876 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
877 QVERIFY(m_player->position() >= qint64(0)); |
|
878 QVERIFY(spy.count()!=0);} |
|
879 |
|
880 //reset position |
|
881 m_player->stop(); |
|
882 m_player->setPosition(position); |
|
883 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
884 |
|
885 //over duration |
|
886 //qDebug()<<"over"; |
|
887 { QSignalSpy spy(m_player, SIGNAL(positionChanged(qint64))); |
|
888 m_player->play(); |
|
889 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
890 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
891 m_player->setPosition(duration+1); |
|
892 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::EndOfMedia); |
|
893 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::EndOfMedia); |
|
894 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
895 QCOMPARE(m_player->position(), qint64(0)); |
|
896 QVERIFY(spy.count()!=0);} |
|
897 |
|
898 } else |
|
899 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
900 |
|
901 m_player->stop(); |
|
902 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
903 //qDebug()<<"end"; |
|
904 } |
|
905 |
|
906 |
|
907 void tst_QMediaPlayer::testVolume() |
|
908 { |
|
909 QFETCH_GLOBAL(int, volume); |
|
910 |
|
911 // preset volume |
|
912 { QSignalSpy spy(m_player, SIGNAL(volumeChanged(int))); |
|
913 m_player->setVolume(volume); |
|
914 QCOMPARE(m_player->volume(), volume); |
|
915 QCOMPARE(m_player->isMuted(), false); |
|
916 QCOMPARE(spy.count(), 1);} |
|
917 |
|
918 // same volume |
|
919 { QSignalSpy spy(m_player, SIGNAL(volumeChanged(int))); |
|
920 int currentVolume = m_player->volume(); |
|
921 m_player->setVolume(currentVolume); |
|
922 QCOMPARE(m_player->volume(), currentVolume); |
|
923 QCOMPARE(m_player->isMuted(), false); |
|
924 QCOMPARE(spy.count(), 0);} |
|
925 |
|
926 // zero volume |
|
927 { QSignalSpy spy(m_player, SIGNAL(volumeChanged(int))); |
|
928 m_player->setVolume(0); |
|
929 QCOMPARE(m_player->volume(), 0); |
|
930 QCOMPARE(m_player->isMuted(), false); |
|
931 QCOMPARE(spy.count(), 1);} |
|
932 |
|
933 // max volume |
|
934 { QSignalSpy spy(m_player, SIGNAL(volumeChanged(int))); |
|
935 m_player->setVolume(100); |
|
936 QCOMPARE(m_player->volume(), 100); |
|
937 QCOMPARE(m_player->isMuted(), false); |
|
938 QCOMPARE(spy.count(), 1);} |
|
939 |
|
940 // negative volume |
|
941 { QSignalSpy spy(m_player, SIGNAL(volumeChanged(int))); |
|
942 m_player->setVolume(int(-1)); |
|
943 QCOMPARE(m_player->volume(), 0); |
|
944 QCOMPARE(m_player->isMuted(), false); |
|
945 QCOMPARE(spy.count(), 1);} |
|
946 |
|
947 // over max volume |
|
948 { QSignalSpy spy(m_player, SIGNAL(volumeChanged(int))); |
|
949 m_player->setVolume(1000); |
|
950 QCOMPARE(m_player->volume(), 100); |
|
951 QCOMPARE(m_player->isMuted(), false); |
|
952 QCOMPARE(spy.count(), 1);} |
|
953 } |
|
954 |
|
955 void tst_QMediaPlayer::testVolumeWhilePlaying() |
|
956 { |
|
957 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
958 QFETCH_GLOBAL(int, volume); |
|
959 QFETCH_GLOBAL(bool, valid); |
|
960 |
|
961 if (valid) { |
|
962 m_player->setMedia(mediaContent); |
|
963 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::LoadedMedia); |
|
964 |
|
965 m_player->play(); |
|
966 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
967 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
968 |
|
969 // preset volume |
|
970 { QSignalSpy spy(m_player, SIGNAL(volumeChanged(int))); |
|
971 m_player->setVolume(volume); |
|
972 QCOMPARE(m_player->volume(), volume); |
|
973 QCOMPARE(m_player->isMuted(), false); |
|
974 QCOMPARE(spy.count(), 1);} |
|
975 |
|
976 // same volume |
|
977 { QSignalSpy spy(m_player, SIGNAL(volumeChanged(int))); |
|
978 int currentVolume = m_player->volume(); |
|
979 m_player->setVolume(currentVolume); |
|
980 QCOMPARE(m_player->volume(), currentVolume); |
|
981 QCOMPARE(m_player->isMuted(), false); |
|
982 QCOMPARE(spy.count(), 0);} |
|
983 |
|
984 // zero volume |
|
985 { QSignalSpy spy(m_player, SIGNAL(volumeChanged(int))); |
|
986 m_player->setVolume(0); |
|
987 QCOMPARE(m_player->volume(), 0); |
|
988 QCOMPARE(m_player->isMuted(), false); |
|
989 QCOMPARE(spy.count(), 1);} |
|
990 |
|
991 // max volume |
|
992 { QSignalSpy spy(m_player, SIGNAL(volumeChanged(int))); |
|
993 m_player->setVolume(100); |
|
994 QCOMPARE(m_player->volume(), 100); |
|
995 QCOMPARE(m_player->isMuted(), false); |
|
996 QCOMPARE(spy.count(), 1);} |
|
997 |
|
998 // negative volume |
|
999 { QSignalSpy spy(m_player, SIGNAL(volumeChanged(int))); |
|
1000 m_player->setVolume(int(-1)); |
|
1001 QCOMPARE(m_player->volume(), 0); |
|
1002 QCOMPARE(m_player->isMuted(), false); |
|
1003 QCOMPARE(spy.count(), 1);} |
|
1004 |
|
1005 // over max volume |
|
1006 { QSignalSpy spy(m_player, SIGNAL(volumeChanged(int))); |
|
1007 m_player->setVolume(1000); |
|
1008 QCOMPARE(m_player->volume(), 100); |
|
1009 QCOMPARE(m_player->isMuted(), false); |
|
1010 QCOMPARE(spy.count(), 1);} |
|
1011 |
|
1012 m_player->stop(); |
|
1013 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1014 } |
|
1015 } |
|
1016 |
|
1017 |
|
1018 void tst_QMediaPlayer::testMuted() |
|
1019 { |
|
1020 QFETCH_GLOBAL(int, volume); |
|
1021 |
|
1022 //reset mute & volume |
|
1023 m_player->setMuted(false); |
|
1024 m_player->setVolume(0); |
|
1025 QVERIFY(m_player->isMuted() == false); |
|
1026 QCOMPARE(m_player->volume(), 0); |
|
1027 |
|
1028 // set muted |
|
1029 {QSignalSpy spy(m_player, SIGNAL(mutedChanged(bool))); |
|
1030 m_player->setMuted(true); |
|
1031 QCOMPARE(spy.count(), 1); |
|
1032 QVERIFY(m_player->isMuted() == true);} |
|
1033 |
|
1034 // set muted again |
|
1035 {QSignalSpy spy(m_player, SIGNAL(mutedChanged(bool))); |
|
1036 m_player->setMuted(true); |
|
1037 QCOMPARE(spy.count(), 0); |
|
1038 QVERIFY(m_player->isMuted() == true);} |
|
1039 |
|
1040 // unmute |
|
1041 {QSignalSpy spy(m_player, SIGNAL(mutedChanged(bool))); |
|
1042 m_player->setMuted(false); |
|
1043 QCOMPARE(spy.count(), 1); |
|
1044 QVERIFY(m_player->isMuted() == false);} |
|
1045 |
|
1046 // set volume while muted |
|
1047 {QSignalSpy muteSpy(m_player, SIGNAL(mutedChanged(bool))); |
|
1048 QSignalSpy volumeSpy(m_player, SIGNAL(volumeChanged(int))); |
|
1049 m_player->setMuted(true); |
|
1050 m_player->setVolume(volume); |
|
1051 QCOMPARE(m_player->volume(), volume); |
|
1052 QCOMPARE(muteSpy.count(), 1); |
|
1053 QCOMPARE(volumeSpy.count(), 1); |
|
1054 QVERIFY(m_player->isMuted() == true);} |
|
1055 } |
|
1056 |
|
1057 void tst_QMediaPlayer::testMutedWhilePlaying() |
|
1058 { |
|
1059 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
1060 QFETCH_GLOBAL(int, volume); |
|
1061 QFETCH_GLOBAL(bool, valid); |
|
1062 |
|
1063 if (valid) { |
|
1064 m_player->setMedia(mediaContent); |
|
1065 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::LoadedMedia); |
|
1066 |
|
1067 //reset mute & volume |
|
1068 m_player->setMuted(false); |
|
1069 m_player->setVolume(65); |
|
1070 QVERIFY(m_player->isMuted() == false); |
|
1071 QCOMPARE(m_player->volume(), 65); |
|
1072 |
|
1073 m_player->play(); |
|
1074 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
1075 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
1076 |
|
1077 // set muted |
|
1078 {QSignalSpy spy(m_player, SIGNAL(mutedChanged(bool))); |
|
1079 m_player->setMuted(true); |
|
1080 QCOMPARE(spy.count(), 1); |
|
1081 QVERIFY(m_player->isMuted() == true);} |
|
1082 |
|
1083 // set muted again |
|
1084 {QSignalSpy spy(m_player, SIGNAL(mutedChanged(bool))); |
|
1085 m_player->setMuted(true); |
|
1086 QCOMPARE(spy.count(), 0); |
|
1087 QVERIFY(m_player->isMuted() == true);} |
|
1088 |
|
1089 // unmute |
|
1090 {QSignalSpy spy(m_player, SIGNAL(mutedChanged(bool))); |
|
1091 m_player->setMuted(false); |
|
1092 QCOMPARE(spy.count(), 1); |
|
1093 QVERIFY(m_player->isMuted() == false);} |
|
1094 |
|
1095 // set volume while muted |
|
1096 {QSignalSpy muteSpy(m_player, SIGNAL(mutedChanged(bool))); |
|
1097 QSignalSpy volumeSpy(m_player, SIGNAL(volumeChanged(int))); |
|
1098 m_player->setMuted(true); |
|
1099 m_player->setVolume(volume); |
|
1100 QCOMPARE(m_player->volume(), volume); |
|
1101 QCOMPARE(muteSpy.count(), 1); |
|
1102 QCOMPARE(volumeSpy.count(), 1); |
|
1103 QVERIFY(m_player->isMuted() == true);} |
|
1104 |
|
1105 m_player->stop(); |
|
1106 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1107 } |
|
1108 } |
|
1109 |
|
1110 |
|
1111 void tst_QMediaPlayer::testVideoAndAudioAvailability() |
|
1112 { |
|
1113 QFETCH_GLOBAL(bool, videoAvailable); |
|
1114 QFETCH_GLOBAL(bool, audioAvailable); |
|
1115 QFETCH_GLOBAL(bool, valid); |
|
1116 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
1117 |
|
1118 if(valid) { |
|
1119 QSignalSpy audioAvailableSpy(m_player, SIGNAL(audioAvailableChanged(bool))); |
|
1120 QSignalSpy videoAvailableSpy(m_player, SIGNAL(videoAvailableChanged(bool))); |
|
1121 |
|
1122 m_player->setMedia(mediaContent); |
|
1123 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::LoadedMedia); |
|
1124 |
|
1125 QVERIFY(m_player->isVideoAvailable() == videoAvailable); |
|
1126 QVERIFY(m_player->isAudioAvailable() == audioAvailable); |
|
1127 |
|
1128 QCOMPARE(audioAvailableSpy.count(), 1); |
|
1129 QCOMPARE(videoAvailableSpy.count(), 1); |
|
1130 } |
|
1131 } |
|
1132 |
|
1133 void tst_QMediaPlayer::testError() |
|
1134 { |
|
1135 QFETCH_GLOBAL(QMediaPlayer::Error, error); |
|
1136 QFETCH_GLOBAL(bool, videoAvailable); |
|
1137 QFETCH_GLOBAL(bool, audioAvailable); |
|
1138 QFETCH_GLOBAL(bool, valid); |
|
1139 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
1140 QFETCH_GLOBAL(QMediaPlayer::State, state); |
|
1141 QFETCH_GLOBAL(QMediaPlayer::MediaStatus, status); |
|
1142 |
|
1143 QSignalSpy errorSpy(m_player, SIGNAL(error(QMediaPlayer::Error))); |
|
1144 m_player->setMedia(mediaContent); |
|
1145 WAIT_FOR_CONDITION(m_player->mediaStatus(), (QMediaPlayer::NoMedia || QMediaPlayer::InvalidMedia || QMediaPlayer::LoadedMedia)); |
|
1146 QVERIFY(m_player->mediaStatus() == status); |
|
1147 QVERIFY(m_player->state() == state); |
|
1148 QVERIFY(m_player->error() == error); |
|
1149 QVERIFY(m_player->isVideoAvailable() == videoAvailable); |
|
1150 QVERIFY(m_player->isAudioAvailable() == audioAvailable); |
|
1151 if (error != QMediaPlayer::NoError) { |
|
1152 QVERIFY(errorSpy.count()!=0); |
|
1153 } |
|
1154 } |
|
1155 |
|
1156 void tst_QMediaPlayer::testPlay() |
|
1157 { |
|
1158 QFETCH_GLOBAL(bool, valid); |
|
1159 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
1160 QFETCH_GLOBAL(QMediaPlayer::State, state); |
|
1161 |
|
1162 m_player->setMedia(mediaContent); |
|
1163 WAIT_FOR_CONDITION(m_player->mediaStatus(), (QMediaPlayer::NoMedia || QMediaPlayer::InvalidMedia || QMediaPlayer::LoadedMedia)); |
|
1164 QVERIFY(m_player->state() == state); |
|
1165 QVERIFY(m_player->media() == mediaContent); |
|
1166 QSignalSpy spy(m_player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
1167 m_player->play(); |
|
1168 |
|
1169 if(valid) { |
|
1170 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
1171 |
|
1172 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
1173 QCOMPARE(spy.count(), state == QMediaPlayer::PlayingState ? 0 : 1); |
|
1174 |
|
1175 //Play->Play |
|
1176 {QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
1177 QSignalSpy stateSpy(m_player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
1178 m_player->play(); |
|
1179 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
1180 QCOMPARE(stateSpy.count(), 0);} |
|
1181 |
|
1182 //Play->Pause |
|
1183 {QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
1184 QSignalSpy stateSpy(m_player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
1185 m_player->pause(); |
|
1186 QCOMPARE(m_player->state(), QMediaPlayer::PausedState); |
|
1187 QCOMPARE(stateSpy.count(), 1);} |
|
1188 |
|
1189 //Play->Stop |
|
1190 {m_player->play(); |
|
1191 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
1192 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
1193 QSignalSpy stateSpy(m_player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
1194 m_player->stop(); |
|
1195 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1196 QCOMPARE(stateSpy.count(), 1);} |
|
1197 |
|
1198 } else { |
|
1199 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1200 QCOMPARE(spy.count(), 0); |
|
1201 } |
|
1202 |
|
1203 m_player->stop(); |
|
1204 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1205 } |
|
1206 |
|
1207 void tst_QMediaPlayer::testPause() |
|
1208 { |
|
1209 QFETCH_GLOBAL(bool, valid); |
|
1210 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
1211 QFETCH_GLOBAL(QMediaPlayer::State, state); |
|
1212 |
|
1213 m_player->setMedia(mediaContent); |
|
1214 WAIT_FOR_CONDITION(m_player->mediaStatus(), (QMediaPlayer::NoMedia || QMediaPlayer::InvalidMedia || QMediaPlayer::LoadedMedia)); |
|
1215 QVERIFY(m_player->state() == state); |
|
1216 QVERIFY(m_player->media() == mediaContent); |
|
1217 QSignalSpy spy(m_player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
1218 m_player->pause(); |
|
1219 |
|
1220 if(valid) { |
|
1221 QCOMPARE(m_player->state(), QMediaPlayer::PausedState); |
|
1222 QCOMPARE(spy.count(), 1); |
|
1223 |
|
1224 //Pause->Play |
|
1225 {QCOMPARE(m_player->state(), QMediaPlayer::PausedState); |
|
1226 QSignalSpy stateSpy(m_player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
1227 m_player->play(); |
|
1228 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
1229 QCOMPARE(stateSpy.count(), 1);} |
|
1230 |
|
1231 //Pause->Pause |
|
1232 {m_player->pause(); |
|
1233 QCOMPARE(m_player->state(), QMediaPlayer::PausedState); |
|
1234 QSignalSpy stateSpy(m_player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
1235 m_player->pause(); |
|
1236 QCOMPARE(m_player->state(), QMediaPlayer::PausedState); |
|
1237 QCOMPARE(stateSpy.count(), 0);} |
|
1238 |
|
1239 //Pause->Stop |
|
1240 {QCOMPARE(m_player->state(), QMediaPlayer::PausedState); |
|
1241 QSignalSpy stateSpy(m_player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
1242 m_player->stop(); |
|
1243 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1244 QCOMPARE(stateSpy.count(), 1);} |
|
1245 } else { |
|
1246 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1247 QCOMPARE(spy.count(), 0); |
|
1248 } |
|
1249 m_player->stop(); |
|
1250 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1251 } |
|
1252 |
|
1253 void tst_QMediaPlayer::testStop() |
|
1254 { |
|
1255 QFETCH_GLOBAL(bool, valid); |
|
1256 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
1257 QFETCH_GLOBAL(QMediaPlayer::State, state); |
|
1258 |
|
1259 m_player->setMedia(mediaContent); |
|
1260 WAIT_FOR_CONDITION(m_player->mediaStatus(), (QMediaPlayer::NoMedia || QMediaPlayer::InvalidMedia || QMediaPlayer::LoadedMedia)); |
|
1261 QVERIFY(m_player->state() == state); |
|
1262 QVERIFY(m_player->media() == mediaContent); |
|
1263 |
|
1264 QSignalSpy spy(m_player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
1265 m_player->stop(); |
|
1266 |
|
1267 if(valid) { |
|
1268 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1269 QCOMPARE(spy.count(), 0); |
|
1270 |
|
1271 //Stop->Play |
|
1272 {QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1273 QSignalSpy stateSpy(m_player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
1274 m_player->play(); |
|
1275 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
1276 QCOMPARE(stateSpy.count(), 1);} |
|
1277 |
|
1278 //Stop->Pause |
|
1279 {m_player->stop(); |
|
1280 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1281 QSignalSpy stateSpy(m_player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
1282 m_player->pause(); |
|
1283 QCOMPARE(m_player->state(), QMediaPlayer::PausedState); |
|
1284 QCOMPARE(stateSpy.count(), 1);} |
|
1285 |
|
1286 //Stop->Stop |
|
1287 {m_player->stop(); |
|
1288 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1289 QSignalSpy stateSpy(m_player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
1290 m_player->stop(); |
|
1291 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1292 QCOMPARE(stateSpy.count(), 0);} |
|
1293 } else { |
|
1294 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1295 QCOMPARE(spy.count(), 0); |
|
1296 } |
|
1297 |
|
1298 m_player->stop(); |
|
1299 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1300 } |
|
1301 |
|
1302 void tst_QMediaPlayer::testMediaStatus() |
|
1303 { |
|
1304 QFETCH_GLOBAL(bool, valid); |
|
1305 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
1306 |
|
1307 QSignalSpy statusSpy(m_player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); |
|
1308 mediaStatusList list(m_player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); |
|
1309 m_player->setMedia(mediaContent); |
|
1310 WAIT_FOR_CONDITION(m_player->mediaStatus(), (QMediaPlayer::NoMedia || QMediaPlayer::InvalidMedia || QMediaPlayer::LoadedMedia)); |
|
1311 |
|
1312 if(valid) { |
|
1313 QCOMPARE(statusSpy.count(), 3); |
|
1314 QCOMPARE(list.count(), 3); |
|
1315 QCOMPARE(list.at(0), QMediaPlayer::UnknownMediaStatus); |
|
1316 QCOMPARE(list.at(1), QMediaPlayer::LoadingMedia); |
|
1317 QCOMPARE(list.at(2), QMediaPlayer::LoadedMedia); |
|
1318 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::LoadedMedia); |
|
1319 |
|
1320 m_player->play(); |
|
1321 {WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia);} |
|
1322 QCOMPARE(statusSpy.count(), 5); |
|
1323 QCOMPARE(list.count(), 5); |
|
1324 QCOMPARE(list.at(3), QMediaPlayer::BufferingMedia); |
|
1325 QCOMPARE(list.at(4), QMediaPlayer::BufferedMedia); |
|
1326 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
1327 |
|
1328 {WAIT_LONG_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::EndOfMedia);} |
|
1329 QVERIFY(statusSpy.count() > 4); |
|
1330 QVERIFY(list.count() > 4); |
|
1331 QCOMPARE(list.last(), QMediaPlayer::EndOfMedia); |
|
1332 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::EndOfMedia); |
|
1333 } else if (mediaContent.isNull()) { |
|
1334 QCOMPARE(statusSpy.count(), 2); |
|
1335 QCOMPARE(list.count(), 2); |
|
1336 QCOMPARE(list.at(0), QMediaPlayer::UnknownMediaStatus); |
|
1337 QCOMPARE(list.at(1), QMediaPlayer::NoMedia); |
|
1338 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::NoMedia); |
|
1339 m_player->play(); |
|
1340 QCOMPARE(statusSpy.count(), 2); |
|
1341 QCOMPARE(list.count(), 2); |
|
1342 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::NoMedia); |
|
1343 } else if(statusSpy.count() > 2) { |
|
1344 QCOMPARE(statusSpy.count(), 3); |
|
1345 QCOMPARE(list.count(), 3); |
|
1346 QCOMPARE(list.at(0), QMediaPlayer::UnknownMediaStatus); |
|
1347 QCOMPARE(list.at(1), QMediaPlayer::LoadingMedia); |
|
1348 QCOMPARE(list.at(2), QMediaPlayer::InvalidMedia); |
|
1349 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::InvalidMedia); |
|
1350 m_player->play(); |
|
1351 QCOMPARE(statusSpy.count(), 3); |
|
1352 QCOMPARE(list.count(), 3); |
|
1353 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::InvalidMedia); |
|
1354 } else { |
|
1355 QCOMPARE(statusSpy.count(), 2); |
|
1356 QCOMPARE(list.count(), 2); |
|
1357 QCOMPARE(list.at(0), QMediaPlayer::UnknownMediaStatus); |
|
1358 QCOMPARE(list.at(1), QMediaPlayer::InvalidMedia); |
|
1359 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::InvalidMedia); |
|
1360 m_player->play(); |
|
1361 QCOMPARE(statusSpy.count(), 2); |
|
1362 QCOMPARE(list.count(), 2); |
|
1363 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::InvalidMedia); |
|
1364 } |
|
1365 |
|
1366 m_player->stop(); |
|
1367 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1368 } |
|
1369 |
|
1370 void tst_QMediaPlayer::testPlaylist() |
|
1371 { |
|
1372 if(!runonce) { |
|
1373 QMediaContent content0(QUrl(QLatin1String("file:///C:/data/testfiles/test_mp4.mp4"))); |
|
1374 QMediaContent content1(QUrl(QLatin1String("file:///C:/data/testfiles/test_WAV.dat"))); |
|
1375 QMediaContent content2(QUrl(QLatin1String("file:///C:/data/testfiles/test_mp4.mp4"))); |
|
1376 QMediaContent content3(QUrl(QLatin1String("file:///C:/data/testfiles/test_WAV.dat"))); |
|
1377 QMediaContent content4(QUrl(QLatin1String("file:///C:/data/testfiles/test_MIDI.dat"))); |
|
1378 |
|
1379 QMediaPlaylist *playlist = new QMediaPlaylist(m_player); |
|
1380 playlist->setMediaObject(m_player); |
|
1381 |
|
1382 QSignalSpy stateSpy(m_player, SIGNAL(stateChanged(QMediaPlayer::State))); |
|
1383 QSignalSpy mediaSpy(m_player, SIGNAL(mediaChanged(QMediaContent))); |
|
1384 |
|
1385 // Test the player does nothing with an empty playlist attached. |
|
1386 m_player->play(); |
|
1387 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1388 QCOMPARE(m_player->media(), QMediaContent()); |
|
1389 QCOMPARE(stateSpy.count(), 0); |
|
1390 QCOMPARE(mediaSpy.count(), 0); |
|
1391 |
|
1392 playlist->addMedia(content0); |
|
1393 playlist->addMedia(content1); |
|
1394 playlist->addMedia(content2); |
|
1395 playlist->addMedia(content3); |
|
1396 |
|
1397 // Test changing the playlist position, changes the current media, but not the playing state. |
|
1398 playlist->setCurrentIndex(1); |
|
1399 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::LoadedMedia); |
|
1400 QCOMPARE(m_player->media(), content1); |
|
1401 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1402 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::LoadedMedia); |
|
1403 QCOMPARE(stateSpy.count(), 0); |
|
1404 QCOMPARE(mediaSpy.count(), 1); |
|
1405 |
|
1406 // Test playing starts with the current media. |
|
1407 m_player->play(); |
|
1408 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
1409 QCOMPARE(m_player->media(), content1); |
|
1410 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
1411 QVERIFY(m_player->mediaStatus() == (QMediaPlayer::BufferedMedia||QMediaPlayer::BufferingMedia)); |
|
1412 QCOMPARE(stateSpy.count(), 1); |
|
1413 QCOMPARE(mediaSpy.count(), 1); |
|
1414 |
|
1415 // Test pausing doesn't change the current media. |
|
1416 m_player->pause(); |
|
1417 QCOMPARE(m_player->media(), content1); |
|
1418 QCOMPARE(m_player->state(), QMediaPlayer::PausedState); |
|
1419 QVERIFY(m_player->mediaStatus() == (QMediaPlayer::BufferedMedia||QMediaPlayer::BufferingMedia)); |
|
1420 QCOMPARE(stateSpy.count(), 2); |
|
1421 QCOMPARE(mediaSpy.count(), 1); |
|
1422 |
|
1423 // Test stopping doesn't change the current media. |
|
1424 m_player->stop(); |
|
1425 QCOMPARE(m_player->media(), content1); |
|
1426 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1427 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::LoadedMedia); |
|
1428 QCOMPARE(stateSpy.count(), 3); |
|
1429 QCOMPARE(mediaSpy.count(), 1); |
|
1430 |
|
1431 // Test when the player service reaches the end of the current media, the player moves onto |
|
1432 // the next item without stopping. |
|
1433 m_player->play(); |
|
1434 QCOMPARE(m_player->media(), content1); |
|
1435 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
1436 QCOMPARE(stateSpy.count(), 4); |
|
1437 QCOMPARE(mediaSpy.count(), 1); |
|
1438 |
|
1439 WAIT_FOR_CONDITION(mediaSpy.count(), 2); |
|
1440 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
1441 QCOMPARE(m_player->media(), content2); |
|
1442 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
1443 QVERIFY(m_player->mediaStatus() == (QMediaPlayer::BufferedMedia||QMediaPlayer::BufferingMedia)); |
|
1444 QCOMPARE(stateSpy.count(), 6); |
|
1445 QCOMPARE(mediaSpy.count(), 2); |
|
1446 |
|
1447 // Test skipping the current media doesn't change the state. |
|
1448 playlist->next(); |
|
1449 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
1450 QCOMPARE(m_player->media(), content3); |
|
1451 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
1452 QVERIFY(m_player->mediaStatus() == (QMediaPlayer::BufferedMedia||QMediaPlayer::BufferingMedia)); |
|
1453 QCOMPARE(stateSpy.count(), 6); |
|
1454 QCOMPARE(mediaSpy.count(), 3); |
|
1455 |
|
1456 // Test changing the current media while paused doesn't change the state. |
|
1457 m_player->pause(); |
|
1458 QCOMPARE(m_player->media(), content3); |
|
1459 QCOMPARE(m_player->state(), QMediaPlayer::PausedState); |
|
1460 QVERIFY(m_player->mediaStatus() == (QMediaPlayer::BufferedMedia||QMediaPlayer::BufferingMedia)); |
|
1461 QCOMPARE(stateSpy.count(), 7); |
|
1462 QCOMPARE(mediaSpy.count(), 3); |
|
1463 |
|
1464 playlist->previous(); |
|
1465 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::LoadedMedia); |
|
1466 QCOMPARE(m_player->media(), content2); |
|
1467 QCOMPARE(m_player->state(), QMediaPlayer::PausedState); |
|
1468 QVERIFY(m_player->mediaStatus() == (QMediaPlayer::BufferedMedia||QMediaPlayer::BufferingMedia)); |
|
1469 QCOMPARE(stateSpy.count(), 7); |
|
1470 QCOMPARE(mediaSpy.count(), 4); |
|
1471 |
|
1472 // Test changing the current media while stopped doesn't change the state. |
|
1473 m_player->stop(); |
|
1474 QCOMPARE(m_player->media(), content2); |
|
1475 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1476 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::LoadedMedia); |
|
1477 QCOMPARE(stateSpy.count(), 8); |
|
1478 QCOMPARE(mediaSpy.count(), 4); |
|
1479 |
|
1480 playlist->next(); |
|
1481 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::LoadedMedia); |
|
1482 QCOMPARE(m_player->media(), content3); |
|
1483 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1484 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::LoadedMedia); |
|
1485 QCOMPARE(stateSpy.count(), 8); |
|
1486 QCOMPARE(mediaSpy.count(), 5); |
|
1487 |
|
1488 // Test the player is stopped and the current media cleared when it reaches the end of the last |
|
1489 // item in the playlist. |
|
1490 m_player->play(); |
|
1491 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
1492 QCOMPARE(m_player->media(), content3); |
|
1493 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
1494 QVERIFY(m_player->mediaStatus() == (QMediaPlayer::BufferedMedia||QMediaPlayer::BufferingMedia)); |
|
1495 QCOMPARE(stateSpy.count(), 9); |
|
1496 QCOMPARE(mediaSpy.count(), 5); |
|
1497 |
|
1498 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::EndOfMedia); |
|
1499 QCOMPARE(m_player->media(), QMediaContent()); |
|
1500 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1501 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::NoMedia); |
|
1502 QCOMPARE(stateSpy.count(), 10); |
|
1503 QCOMPARE(mediaSpy.count(), 6); |
|
1504 |
|
1505 // Test starts playing from the start of the playlist if there is no current media selected. |
|
1506 m_player->play(); |
|
1507 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
1508 QCOMPARE(m_player->media(), content0); |
|
1509 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
1510 QVERIFY(m_player->mediaStatus() == (QMediaPlayer::BufferedMedia||QMediaPlayer::BufferingMedia)); |
|
1511 QCOMPARE(stateSpy.count(), 11); |
|
1512 QCOMPARE(mediaSpy.count(), 7); |
|
1513 |
|
1514 // Test deleting the playlist stops the player and clears the media it set. |
|
1515 delete playlist; |
|
1516 QCOMPARE(m_player->media(), QMediaContent()); |
|
1517 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1518 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::NoMedia); |
|
1519 QCOMPARE(stateSpy.count(), 12); |
|
1520 QCOMPARE(mediaSpy.count(), 8); |
|
1521 |
|
1522 // Test the player works as normal with the playlist removed. |
|
1523 m_player->play(); |
|
1524 QCOMPARE(m_player->media(), QMediaContent()); |
|
1525 QCOMPARE(m_player->state(), QMediaPlayer::StoppedState); |
|
1526 QCOMPARE(m_player->mediaStatus(), QMediaPlayer::NoMedia); |
|
1527 QCOMPARE(stateSpy.count(), 12); |
|
1528 QCOMPARE(mediaSpy.count(), 8); |
|
1529 |
|
1530 m_player->setMedia(content1); |
|
1531 m_player->play(); |
|
1532 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia) |
|
1533 QCOMPARE(m_player->media(), content1); |
|
1534 QCOMPARE(m_player->state(), QMediaPlayer::PlayingState); |
|
1535 QVERIFY(m_player->mediaStatus() == (QMediaPlayer::BufferedMedia||QMediaPlayer::BufferingMedia)); |
|
1536 QCOMPARE(stateSpy.count(), 13); |
|
1537 QCOMPARE(mediaSpy.count(), 9); |
|
1538 m_player->stop(); |
|
1539 runonce = true; |
|
1540 } |
|
1541 } |
|
1542 |
|
1543 void tst_QMediaPlayer::testPlaybackRate() |
|
1544 { |
|
1545 QFETCH_GLOBAL(bool, valid); |
|
1546 QFETCH_GLOBAL(qreal, playbackRate); |
|
1547 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
1548 |
|
1549 m_player->setMedia(mediaContent); |
|
1550 WAIT_FOR_CONDITION(m_player->mediaStatus(), (QMediaPlayer::NoMedia || QMediaPlayer::InvalidMedia || QMediaPlayer::LoadedMedia)); |
|
1551 |
|
1552 if (valid) { |
|
1553 m_player->setPlaybackRate(playbackRate); |
|
1554 QVERIFY(m_player->playbackRate() == playbackRate); |
|
1555 |
|
1556 QSignalSpy spy(m_player, SIGNAL(playbackRateChanged(qreal))); |
|
1557 m_player->setPlaybackRate(playbackRate + 0.5f); |
|
1558 QCOMPARE(m_player->playbackRate(), playbackRate + 0.5f); |
|
1559 QCOMPARE(spy.count(), 1); |
|
1560 } |
|
1561 } |
|
1562 |
|
1563 void tst_QMediaPlayer::testPlaybackRateWhilePlaying() |
|
1564 { |
|
1565 QFETCH_GLOBAL(bool, valid); |
|
1566 QFETCH_GLOBAL(qreal, playbackRate); |
|
1567 QFETCH_GLOBAL(QMediaContent, mediaContent); |
|
1568 |
|
1569 m_player->setMedia(mediaContent); |
|
1570 WAIT_FOR_CONDITION(m_player->mediaStatus(), (QMediaPlayer::NoMedia || QMediaPlayer::InvalidMedia || QMediaPlayer::LoadedMedia)); |
|
1571 |
|
1572 if (valid) { |
|
1573 m_player->play(); |
|
1574 WAIT_FOR_CONDITION(m_player->mediaStatus(), QMediaPlayer::BufferedMedia); |
|
1575 |
|
1576 m_player->setPlaybackRate(playbackRate); |
|
1577 QVERIFY(m_player->playbackRate() == playbackRate); |
|
1578 |
|
1579 QSignalSpy spy(m_player, SIGNAL(playbackRateChanged(qreal))); |
|
1580 m_player->setPlaybackRate(playbackRate + 0.5f); |
|
1581 QCOMPARE(m_player->playbackRate(), playbackRate + 0.5f); |
|
1582 QCOMPARE(spy.count(), 1); |
|
1583 } |
|
1584 } |
|
1585 |
|
1586 QTEST_MAIN(tst_QMediaPlayer) |
|
1587 |
|
1588 #include "tst_qmediaplayer_s60.moc" |