1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39#include <QtQml/qqmlinfo.h>
40
41#include "qdeclarativeaudio_p.h"
42
43#include <qmediaplayercontrol.h>
44#include <qmediaavailabilitycontrol.h>
45
46#include <qmediaservice.h>
47#include <private/qmediaserviceprovider_p.h>
48#include <private/qdeclarativevideooutput_p.h>
49#include <qmetadatareadercontrol.h>
50#include <qmediaavailabilitycontrol.h>
51
52#include "qdeclarativeplaylist_p.h"
53#include "qdeclarativemediametadata_p.h"
54
55#include <QAbstractVideoSurface>
56#include <QTimerEvent>
57#include <QtQml/qqmlengine.h>
58
59QT_BEGIN_NAMESPACE
60
61/*!
62 \qmltype Audio
63 \instantiates QDeclarativeAudio
64 \brief Add audio playback to a scene.
65
66 \inqmlmodule QtMultimedia
67 \ingroup multimedia_qml
68 \ingroup multimedia_audio_qml
69
70 \qml
71 Text {
72 text: "Click Me!";
73 font.pointSize: 24;
74 width: 150; height: 50;
75
76 Audio {
77 id: playMusic
78 source: "music.wav"
79 }
80 MouseArea {
81 id: playArea
82 anchors.fill: parent
83 onPressed: { playMusic.play() }
84 }
85 }
86 \endqml
87
88 \sa Video
89*/
90
91void QDeclarativeAudio::_q_error(QMediaPlayer::Error errorCode)
92{
93 m_error = errorCode;
94 m_errorString = m_player->errorString();
95
96 emit error(error: Error(errorCode), errorString: m_errorString);
97 emit errorChanged();
98}
99
100void QDeclarativeAudio::_q_availabilityChanged(QMultimedia::AvailabilityStatus)
101{
102 emit availabilityChanged(availability: availability());
103}
104
105QDeclarativeAudio::QDeclarativeAudio(QObject *parent)
106 : QObject(parent)
107 , m_playlist(0)
108 , m_autoPlay(false)
109 , m_autoLoad(true)
110 , m_loaded(false)
111 , m_muted(false)
112 , m_complete(false)
113 , m_emitPlaylistChanged(false)
114 , m_loopCount(1)
115 , m_runningCount(0)
116 , m_position(0)
117 , m_vol(1.0)
118 , m_playbackRate(1.0)
119 , m_audioRole(UnknownRole)
120 , m_playbackState(QMediaPlayer::StoppedState)
121 , m_status(QMediaPlayer::NoMedia)
122 , m_error(QMediaPlayer::ServiceMissingError)
123 , m_player(0)
124 , m_notifyInterval(1000)
125{
126}
127
128QDeclarativeAudio::~QDeclarativeAudio()
129{
130 m_metaData.reset();
131 delete m_player;
132}
133
134/*!
135 \since 5.15
136 \qmlproperty url QtMultimedia::MediaPlayer::videoOutput
137
138 This property holds the target video output.
139 Accepts one or an array of QAbstractVideoSurface or VideoOutput elements.
140
141 \snippet multimedia-snippets/multiple-videooutputs.qml complete
142
143 \sa QMediaPlayer::setVideoOutput()
144*/
145
146QVariant QDeclarativeAudio::videoOutput() const
147{
148 return m_videoOutput;
149}
150
151void QDeclarativeAudio::setVideoOutput(const QVariant &v)
152{
153 if (m_videoOutput == v)
154 return;
155
156 QAbstractVideoSurface *surface = nullptr;
157 auto vo = v.value<QDeclarativeVideoOutput *>();
158 if (vo)
159 surface = vo->videoSurface();
160 else
161 surface = v.value<QAbstractVideoSurface *>();
162
163 // If only one object has been passed.
164 if (surface) {
165 m_player->setVideoOutput(surface);
166 } else {
167 QVector<QAbstractVideoSurface *> surfaces;
168 // Check if it is an array.
169 auto arr = v.value<QJSValue>();
170 if (!arr.isNull()) {
171 const int len = arr.property(name: "length").toInt();
172 for (int i = 0; i < len; ++i) {
173 auto &&v = arr.property(arrayIndex: i);
174 if (v.isQObject()) {
175 auto obj = v.toQObject();
176 vo = qobject_cast<QDeclarativeVideoOutput *>(object: obj);
177 surface = vo ? vo->videoSurface() : qobject_cast<QAbstractVideoSurface *>(object: obj);
178 if (surface)
179 surfaces.append(t: surface);
180 }
181 }
182 }
183
184 m_player->setVideoOutput(surfaces);
185 }
186
187 m_videoOutput = v;
188 emit videoOutputChanged();
189}
190
191/*!
192 \qmlproperty enumeration QtMultimedia::Audio::availability
193
194 Returns the availability state of the media player.
195
196 This is one of:
197 \table
198 \header \li Value \li Description
199 \row \li Available
200 \li The media player is available to use.
201 \row \li Busy
202 \li The media player is usually available, but some other
203 process is utilizing the hardware necessary to play media.
204 \row \li Unavailable
205 \li There are no supported media playback facilities.
206 \row \li ResourceMissing
207 \li There is one or more resources missing, so the media player cannot
208 be used. It may be possible to try again at a later time.
209 \endtable
210 */
211QDeclarativeAudio::Availability QDeclarativeAudio::availability() const
212{
213 if (!m_player)
214 return Unavailable;
215 return Availability(m_player->availability());
216}
217
218/*!
219 \qmlproperty enumeration QtMultimedia::Audio::audioRole
220
221 This property holds the role of the audio stream. It can be set to specify the type of audio
222 being played, allowing the system to make appropriate decisions when it comes to volume,
223 routing or post-processing.
224
225 The audio role must be set before setting the source property.
226
227 Supported values can be retrieved with supportedAudioRoles().
228
229 The value can be one of:
230 \list
231 \li UnknownRole - the role is unknown or undefined.
232 \li MusicRole - music.
233 \li VideoRole - soundtrack from a movie or a video.
234 \li VoiceCommunicationRole - voice communications, such as telephony.
235 \li AlarmRole - alarm.
236 \li NotificationRole - notification, such as an incoming e-mail or a chat request.
237 \li RingtoneRole - ringtone.
238 \li AccessibilityRole - for accessibility, such as with a screen reader.
239 \li SonificationRole - sonification, such as with user interface sounds.
240 \li GameRole - game audio.
241 \li CustomRole - The role is specified by customAudioRole.
242 \endlist
243
244 customAudioRole is cleared when this property is set to anything other than CustomRole.
245
246 \since 5.6
247*/
248QDeclarativeAudio::AudioRole QDeclarativeAudio::audioRole() const
249{
250 return !m_complete ? m_audioRole : AudioRole(m_player->audioRole());
251}
252
253void QDeclarativeAudio::setAudioRole(QDeclarativeAudio::AudioRole audioRole)
254{
255 if (this->audioRole() == audioRole)
256 return;
257
258 if (m_complete) {
259 m_player->setAudioRole(QAudio::Role(audioRole));
260 } else {
261 if (!m_customAudioRole.isEmpty()) {
262 m_customAudioRole.clear();
263 emit customAudioRoleChanged();
264 }
265 m_audioRole = audioRole;
266 emit audioRoleChanged();
267 }
268}
269
270/*!
271 \qmlproperty string QtMultimedia::Audio::customAudioRole
272
273 This property holds the role of the audio stream when the backend supports audio
274 roles unknown to Qt. It can be set to specify the type of audio being played,
275 allowing the system to make appropriate decisions when it comes to volume,
276 routing or post-processing.
277
278 The audio role must be set before setting the source property.
279
280 audioRole is set to CustomRole when this property is set.
281
282 \since 5.11
283*/
284QString QDeclarativeAudio::customAudioRole() const
285{
286 return !m_complete ? m_customAudioRole : m_player->customAudioRole();
287}
288
289void QDeclarativeAudio::setCustomAudioRole(const QString &audioRole)
290{
291 if (this->customAudioRole() == audioRole)
292 return;
293
294 if (m_complete) {
295 m_player->setCustomAudioRole(audioRole);
296 } else {
297 setAudioRole(QDeclarativeAudio::CustomRole);
298 m_customAudioRole = audioRole;
299 emit customAudioRoleChanged();
300 }
301}
302
303/*!
304 \qmlproperty int QtMultimedia::Audio::notifyInterval
305
306 The interval at which notifiable properties will update.
307
308 The notifiable properties are \l position and \l bufferProgress.
309
310 The interval is expressed in milliseconds, the default value is 1000.
311
312 \since 5.9
313*/
314int QDeclarativeAudio::notifyInterval() const
315{
316 return m_complete ? m_player->notifyInterval() : m_notifyInterval;
317}
318
319void QDeclarativeAudio::setNotifyInterval(int value)
320{
321 if (notifyInterval() == value)
322 return;
323 if (m_complete) {
324 m_player->setNotifyInterval(value);
325 return;
326 }
327 m_notifyInterval = value;
328 emit notifyIntervalChanged();
329}
330
331/*!
332 \qmlmethod list<int> QtMultimedia::Audio::supportedAudioRoles()
333
334 Returns a list of supported audio roles.
335
336 If setting the audio role is not supported, an empty list is returned.
337
338 \since 5.6
339 \sa audioRole
340*/
341QJSValue QDeclarativeAudio::supportedAudioRoles() const
342{
343 QJSEngine *engine = qmlEngine(this);
344
345 if (!m_complete)
346 return engine->newArray();
347
348 QList<QAudio::Role> roles = m_player->supportedAudioRoles();
349 int size = roles.size();
350
351 QJSValue result = engine->newArray(length: size);
352 for (int i = 0; i < size; ++i)
353 result.setProperty(arrayIndex: i, value: roles.at(i));
354
355 return result;
356}
357
358QUrl QDeclarativeAudio::source() const
359{
360 return m_source;
361}
362
363QDeclarativePlaylist *QDeclarativeAudio::playlist() const
364{
365 return m_playlist;
366}
367
368void QDeclarativeAudio::setPlaylist(QDeclarativePlaylist *playlist)
369{
370 if (playlist == m_playlist && m_source.isEmpty())
371 return;
372
373 if (!m_source.isEmpty()) {
374 m_source.clear();
375 emit sourceChanged();
376 }
377
378 m_playlist = playlist;
379 m_content = m_playlist ?
380 QMediaContent(m_playlist->mediaPlaylist(), QUrl(), false) : QMediaContent();
381 m_loaded = false;
382 if (m_complete && (m_autoLoad || m_content.isNull() || m_autoPlay)) {
383 if (m_error != QMediaPlayer::ServiceMissingError && m_error != QMediaPlayer::NoError) {
384 m_error = QMediaPlayer::NoError;
385 m_errorString = QString();
386
387 emit errorChanged();
388 }
389
390 if (!playlist)
391 m_emitPlaylistChanged = true;
392 m_player->setMedia(media: m_content, stream: 0);
393 m_loaded = true;
394 }
395 else
396 emit playlistChanged();
397
398 if (m_autoPlay)
399 m_player->play();
400}
401
402bool QDeclarativeAudio::autoPlay() const
403{
404 return m_autoPlay;
405}
406
407void QDeclarativeAudio::setAutoPlay(bool autoplay)
408{
409 if (m_autoPlay == autoplay)
410 return;
411
412 m_autoPlay = autoplay;
413 emit autoPlayChanged();
414}
415
416
417void QDeclarativeAudio::setSource(const QUrl &url)
418{
419 if (url == m_source && m_playlist == NULL)
420 return;
421
422 if (m_playlist) {
423 m_playlist = NULL;
424 emit playlistChanged();
425 }
426
427 m_source = url;
428 m_content = m_source.isEmpty() ? QMediaContent() : m_source;
429 m_loaded = false;
430 if (m_complete && (m_autoLoad || m_content.isNull() || m_autoPlay)) {
431 if (m_error != QMediaPlayer::ServiceMissingError && m_error != QMediaPlayer::NoError) {
432 m_error = QMediaPlayer::NoError;
433 m_errorString = QString();
434
435 emit errorChanged();
436 }
437
438 m_player->setMedia(media: m_content, stream: 0);
439 m_loaded = true;
440 }
441 else
442 emit sourceChanged();
443
444 if (m_autoPlay)
445 m_player->play();
446}
447
448bool QDeclarativeAudio::isAutoLoad() const
449{
450 return m_autoLoad;
451}
452
453void QDeclarativeAudio::setAutoLoad(bool autoLoad)
454{
455 if (m_autoLoad == autoLoad)
456 return;
457
458 m_autoLoad = autoLoad;
459 emit autoLoadChanged();
460}
461
462int QDeclarativeAudio::loopCount() const
463{
464 return m_loopCount;
465}
466
467void QDeclarativeAudio::setLoopCount(int loopCount)
468{
469 if (loopCount == 0)
470 loopCount = 1;
471 else if (loopCount < -1)
472 loopCount = -1;
473
474 if (m_loopCount == loopCount) {
475 return;
476 }
477 m_loopCount = loopCount;
478 m_runningCount = loopCount - 1;
479 emit loopCountChanged();
480}
481
482void QDeclarativeAudio::setPlaybackState(QMediaPlayer::State playbackState)
483{
484 if (m_playbackState == playbackState)
485 return;
486
487 if (m_complete) {
488 switch (playbackState){
489 case (QMediaPlayer::PlayingState):
490 if (!m_loaded) {
491 m_player->setMedia(media: m_content, stream: 0);
492 m_player->setPosition(m_position);
493 m_loaded = true;
494 }
495 m_player->play();
496 break;
497
498 case (QMediaPlayer::PausedState):
499 if (!m_loaded) {
500 m_player->setMedia(media: m_content, stream: 0);
501 m_player->setPosition(m_position);
502 m_loaded = true;
503 }
504 m_player->pause();
505 break;
506
507 case (QMediaPlayer::StoppedState):
508 m_player->stop();
509 }
510 }
511}
512
513int QDeclarativeAudio::duration() const
514{
515 return !m_complete ? 0 : m_player->duration();
516}
517
518int QDeclarativeAudio::position() const
519{
520 return !m_complete ? m_position : m_player->position();
521}
522
523qreal QDeclarativeAudio::volume() const
524{
525 return !m_complete ? m_vol : qreal(m_player->volume()) / 100;
526}
527
528void QDeclarativeAudio::setVolume(qreal volume)
529{
530 if (volume < 0 || volume > 1) {
531 qmlWarning(me: this) << tr(s: "volume should be between 0.0 and 1.0");
532 return;
533 }
534
535 if (this->volume() == volume)
536 return;
537
538 if (m_complete) {
539 m_player->setVolume(qRound(d: volume * 100));
540 } else {
541 m_vol = volume;
542 emit volumeChanged();
543 }
544}
545
546bool QDeclarativeAudio::isMuted() const
547{
548 return !m_complete ? m_muted : m_player->isMuted();
549}
550
551void QDeclarativeAudio::setMuted(bool muted)
552{
553 if (isMuted() == muted)
554 return;
555
556 if (m_complete) {
557 m_player->setMuted(muted);
558 } else {
559 m_muted = muted;
560 emit mutedChanged();
561 }
562}
563
564qreal QDeclarativeAudio::bufferProgress() const
565{
566 return !m_complete ? 0 : qreal(m_player->bufferStatus()) / 100;
567}
568
569bool QDeclarativeAudio::isSeekable() const
570{
571 return !m_complete ? false : m_player->isSeekable();
572}
573
574qreal QDeclarativeAudio::playbackRate() const
575{
576 return m_complete ? m_player->playbackRate() : m_playbackRate;
577}
578
579void QDeclarativeAudio::setPlaybackRate(qreal rate)
580{
581 if (playbackRate() == rate)
582 return;
583
584 if (m_complete) {
585 m_player->setPlaybackRate(rate);
586 } else {
587 m_playbackRate = rate;
588 emit playbackRateChanged();
589 }
590}
591
592QString QDeclarativeAudio::errorString() const
593{
594 return m_errorString;
595}
596
597QDeclarativeMediaMetaData *QDeclarativeAudio::metaData() const
598{
599 return m_metaData.data();
600}
601
602
603/*!
604 \qmlmethod QtMultimedia::Audio::play()
605
606 Starts playback of the media.
607
608 Sets the \l playbackState property to PlayingState.
609*/
610
611void QDeclarativeAudio::play()
612{
613 if (!m_complete)
614 return;
615
616 setPlaybackState(QMediaPlayer::PlayingState);
617}
618
619/*!
620 \qmlmethod QtMultimedia::Audio::pause()
621
622 Pauses playback of the media.
623
624 Sets the \l playbackState property to PausedState.
625*/
626
627void QDeclarativeAudio::pause()
628{
629 if (!m_complete)
630 return;
631
632 setPlaybackState(QMediaPlayer::PausedState);
633}
634
635/*!
636 \qmlmethod QtMultimedia::Audio::stop()
637
638 Stops playback of the media.
639
640 Sets the \l playbackState property to StoppedState.
641*/
642
643void QDeclarativeAudio::stop()
644{
645 if (!m_complete)
646 return;
647
648 setPlaybackState(QMediaPlayer::StoppedState);
649}
650
651/*!
652 \qmlmethod QtMultimedia::Audio::seek(offset)
653
654 If the \l seekable property is true, seeks the current
655 playback position to \a offset.
656
657 Seeking may be asynchronous, so the \l position property
658 may not be updated immediately.
659
660 \sa seekable, position
661*/
662void QDeclarativeAudio::seek(int position)
663{
664 // QMediaPlayer clamps this to positive numbers
665 if (position < 0)
666 position = 0;
667
668 if (this->position() == position)
669 return;
670
671 if (m_complete) {
672 m_player->setPosition(position);
673 } else {
674 m_position = position;
675 emit positionChanged();
676 }
677}
678
679/*!
680 \qmlproperty url QtMultimedia::Audio::source
681
682 This property holds the source URL of the media.
683
684 Setting the \l source property clears the current \l playlist, if any.
685*/
686
687/*!
688 \qmlproperty Playlist QtMultimedia::Audio::playlist
689
690 This property holds the playlist used by the media player.
691
692 Setting the \l playlist property resets the \l source to an empty string.
693
694 \since 5.6
695*/
696
697/*!
698 \qmlproperty int QtMultimedia::Audio::loops
699
700 This property holds the number of times the media is played. A value of \c 0 or \c 1 means
701 the media will be played only once; set to \c Audio.Infinite to enable infinite looping.
702
703 The value can be changed while the media is playing, in which case it will update
704 the remaining loops to the new value.
705
706 The default is \c 1.
707*/
708
709/*!
710 \qmlproperty bool QtMultimedia::Audio::autoLoad
711
712 This property indicates if loading of media should begin immediately.
713
714 Defaults to \c true. If \c false, the media will not be loaded until playback is started.
715*/
716
717/*!
718 \qmlsignal QtMultimedia::Audio::playbackStateChanged()
719
720 This signal is emitted when the \l playbackState property is altered.
721
722 The corresponding handler is \c onPlaybackStateChanged.
723*/
724
725
726/*!
727 \qmlsignal QtMultimedia::Audio::paused()
728
729 This signal is emitted when playback is paused.
730
731 The corresponding handler is \c onPaused.
732*/
733
734/*!
735 \qmlsignal QtMultimedia::Audio::stopped()
736
737 This signal is emitted when playback is stopped.
738
739 The corresponding handler is \c onStopped.
740*/
741
742/*!
743 \qmlsignal QtMultimedia::Audio::playing()
744
745 This signal is emitted when playback is started or resumed.
746
747 The corresponding handler is \c onPlaying.
748*/
749
750/*!
751 \qmlproperty enumeration QtMultimedia::Audio::status
752
753 This property holds the status of media loading. It can be one of:
754
755 \list
756 \li NoMedia - no media has been set.
757 \li Loading - the media is currently being loaded.
758 \li Loaded - the media has been loaded.
759 \li Buffering - the media is buffering data.
760 \li Stalled - playback has been interrupted while the media is buffering data.
761 \li Buffered - the media has buffered data.
762 \li EndOfMedia - the media has played to the end.
763 \li InvalidMedia - the media cannot be played.
764 \li UnknownStatus - the status of the media is unknown.
765 \endlist
766*/
767
768QDeclarativeAudio::Status QDeclarativeAudio::status() const
769{
770 return Status(m_status);
771}
772
773
774/*!
775 \qmlproperty enumeration QtMultimedia::Audio::playbackState
776
777 This property holds the state of media playback. It can be one of:
778
779 \list
780 \li PlayingState - the media is currently playing.
781 \li PausedState - playback of the media has been suspended.
782 \li StoppedState - playback of the media is yet to begin.
783 \endlist
784*/
785
786QDeclarativeAudio::PlaybackState QDeclarativeAudio::playbackState() const
787{
788 return PlaybackState(m_playbackState);
789}
790
791/*!
792 \qmlproperty bool QtMultimedia::Audio::autoPlay
793
794 This property controls whether the media will begin to play on start up.
795
796 Defaults to \c false. If set to \c true, the value of autoLoad will be overwritten to \c true.
797*/
798
799/*!
800 \qmlproperty int QtMultimedia::Audio::duration
801
802 This property holds the duration of the media in milliseconds.
803
804 If the media doesn't have a fixed duration (a live stream for example) this will be 0.
805*/
806
807/*!
808 \qmlproperty int QtMultimedia::Audio::position
809
810 This property holds the current playback position in milliseconds.
811
812 To change this position, use the \l seek() method.
813
814 \sa seek()
815*/
816
817/*!
818 \qmlproperty real QtMultimedia::Audio::volume
819
820 This property holds the audio volume.
821
822 The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume). Values outside this
823 range will be clamped.
824
825 The default volume is \c 1.0.
826
827 UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale
828 will produce linear changes in perceived loudness, which is what a user would normally expect
829 from a volume control. See \l {QtMultimedia::QtMultimedia::convertVolume()}{QtMultimedia.convertVolume()}
830 for more details.
831*/
832
833/*!
834 \qmlproperty bool QtMultimedia::Audio::muted
835
836 This property holds whether the audio output is muted.
837
838 Defaults to false.
839*/
840
841/*!
842 \qmlproperty bool QtMultimedia::Audio::hasAudio
843
844 This property holds whether the media contains audio.
845*/
846
847bool QDeclarativeAudio::hasAudio() const
848{
849 return !m_complete ? false : m_player->isAudioAvailable();
850}
851
852/*!
853 \qmlproperty bool QtMultimedia::Audio::hasVideo
854
855 This property holds whether the media contains video.
856*/
857
858bool QDeclarativeAudio::hasVideo() const
859{
860 return !m_complete ? false : m_player->isVideoAvailable();
861}
862
863/*!
864 \qmlproperty real QtMultimedia::Audio::bufferProgress
865
866 This property holds how much of the data buffer is currently filled, from \c 0.0 (empty) to
867 \c 1.0 (full).
868
869 Playback can start or resume only when the buffer is entirely filled, in which case the
870 status is \c Audio.Buffered or \c Audio.Buffering. A value lower than \c 1.0 implies that
871 the status is \c Audio.Stalled.
872
873 \sa status
874*/
875
876/*!
877 \qmlproperty bool QtMultimedia::Audio::seekable
878
879 This property holds whether position of the audio can be changed.
880
881 If true, calling the \l seek() method will cause playback to seek to the new position.
882*/
883
884/*!
885 \qmlproperty real QtMultimedia::Audio::playbackRate
886
887 This property holds the rate at which audio is played at as a multiple of the normal rate.
888
889 Defaults to 1.0.
890*/
891
892/*!
893 \qmlproperty enumeration QtMultimedia::Audio::error
894
895 This property holds the error state of the audio. It can be one of:
896
897 \table
898 \header \li Value \li Description
899 \row \li NoError
900 \li There is no current error.
901 \row \li ResourceError
902 \li The audio cannot be played due to a problem allocating resources.
903 \row \li FormatError
904 \li The audio format is not supported.
905 \row \li NetworkError
906 \li The audio cannot be played due to network issues.
907 \row \li AccessDenied
908 \li The audio cannot be played due to insufficient permissions.
909 \row \li ServiceMissing
910 \li The audio cannot be played because the media service could not be
911 instantiated.
912 \endtable
913*/
914
915QDeclarativeAudio::Error QDeclarativeAudio::error() const
916{
917 return Error(m_error);
918}
919
920void QDeclarativeAudio::classBegin()
921{
922 m_player = new QMediaPlayer(this);
923
924 connect(sender: m_player, SIGNAL(stateChanged(QMediaPlayer::State)),
925 receiver: this, SLOT(_q_statusChanged()));
926 connect(sender: m_player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
927 receiver: this, SLOT(_q_statusChanged()));
928 connect(sender: m_player, SIGNAL(mediaChanged(const QMediaContent&)),
929 receiver: this, SLOT(_q_mediaChanged(const QMediaContent&)));
930 connect(sender: m_player, SIGNAL(durationChanged(qint64)),
931 receiver: this, SIGNAL(durationChanged()));
932 connect(sender: m_player, SIGNAL(positionChanged(qint64)),
933 receiver: this, SIGNAL(positionChanged()));
934 connect(sender: m_player, SIGNAL(volumeChanged(int)),
935 receiver: this, SIGNAL(volumeChanged()));
936 connect(sender: m_player, SIGNAL(mutedChanged(bool)),
937 receiver: this, SIGNAL(mutedChanged()));
938 connect(sender: m_player, SIGNAL(bufferStatusChanged(int)),
939 receiver: this, SIGNAL(bufferProgressChanged()));
940 connect(sender: m_player, SIGNAL(seekableChanged(bool)),
941 receiver: this, SIGNAL(seekableChanged()));
942 connect(sender: m_player, SIGNAL(playbackRateChanged(qreal)),
943 receiver: this, SIGNAL(playbackRateChanged()));
944 connect(sender: m_player, SIGNAL(error(QMediaPlayer::Error)),
945 receiver: this, SLOT(_q_error(QMediaPlayer::Error)));
946 connect(sender: m_player, SIGNAL(audioAvailableChanged(bool)),
947 receiver: this, SIGNAL(hasAudioChanged()));
948 connect(sender: m_player, SIGNAL(videoAvailableChanged(bool)),
949 receiver: this, SIGNAL(hasVideoChanged()));
950 connect(sender: m_player, SIGNAL(audioRoleChanged(QAudio::Role)),
951 receiver: this, SIGNAL(audioRoleChanged()));
952 connect(sender: m_player, SIGNAL(customAudioRoleChanged(const QString &)),
953 receiver: this, SIGNAL(customAudioRoleChanged()));
954 connect(sender: m_player, SIGNAL(notifyIntervalChanged(int)),
955 receiver: this, SIGNAL(notifyIntervalChanged()));
956
957 m_error = m_player->availability() == QMultimedia::ServiceMissing ? QMediaPlayer::ServiceMissingError : QMediaPlayer::NoError;
958
959 connect(sender: m_player, SIGNAL(availabilityChanged(QMultimedia::AvailabilityStatus)),
960 receiver: this, SLOT(_q_availabilityChanged(QMultimedia::AvailabilityStatus)));
961
962 m_metaData.reset(other: new QDeclarativeMediaMetaData(m_player));
963
964 connect(sender: m_player, SIGNAL(metaDataChanged()),
965 receiver: m_metaData.data(), SIGNAL(metaDataChanged()));
966
967 emit mediaObjectChanged();
968}
969
970void QDeclarativeAudio::componentComplete()
971{
972 if (!qFuzzyCompare(p1: m_vol, p2: qreal(1.0)))
973 m_player->setVolume(m_vol * 100);
974 if (m_muted)
975 m_player->setMuted(m_muted);
976 if (!qFuzzyCompare(p1: m_playbackRate, p2: qreal(1.0)))
977 m_player->setPlaybackRate(m_playbackRate);
978 if (m_audioRole != UnknownRole)
979 m_player->setAudioRole(QAudio::Role(m_audioRole));
980 if (!m_customAudioRole.isEmpty())
981 m_player->setCustomAudioRole(m_customAudioRole);
982 if (m_notifyInterval != m_player->notifyInterval())
983 m_player->setNotifyInterval(m_notifyInterval);
984
985 if (!m_content.isNull() && (m_autoLoad || m_autoPlay)) {
986 m_player->setMedia(media: m_content, stream: 0);
987 m_loaded = true;
988 if (m_position > 0)
989 m_player->setPosition(m_position);
990 }
991
992 m_complete = true;
993
994 if (m_autoPlay) {
995 if (m_content.isNull()) {
996 m_player->stop();
997 } else {
998 m_player->play();
999 }
1000 }
1001}
1002
1003void QDeclarativeAudio::_q_statusChanged()
1004{
1005 if (m_player->mediaStatus() == QMediaPlayer::EndOfMedia && m_runningCount != 0) {
1006 m_runningCount = std::max(a: m_runningCount - 1, b: -2);
1007 m_player->play();
1008 }
1009 const QMediaPlayer::MediaStatus oldStatus = m_status;
1010 const QMediaPlayer::State lastPlaybackState = m_playbackState;
1011
1012 const QMediaPlayer::State state = m_player->state();
1013
1014 m_playbackState = state;
1015
1016 m_status = m_player->mediaStatus();
1017
1018 if (m_status != oldStatus)
1019 emit statusChanged();
1020
1021 if (lastPlaybackState != state) {
1022
1023 if (lastPlaybackState == QMediaPlayer::StoppedState)
1024 m_runningCount = m_loopCount - 1;
1025
1026 switch (state) {
1027 case QMediaPlayer::StoppedState:
1028 emit stopped();
1029 break;
1030 case QMediaPlayer::PausedState:
1031 emit paused();
1032 break;
1033 case QMediaPlayer::PlayingState:
1034 emit playing();
1035 break;
1036 }
1037
1038 emit playbackStateChanged();
1039 }
1040}
1041
1042void QDeclarativeAudio::_q_mediaChanged(const QMediaContent &media)
1043{
1044 if (!media.playlist() && !m_emitPlaylistChanged) {
1045 emit sourceChanged();
1046 } else {
1047 m_emitPlaylistChanged = false;
1048 emit playlistChanged();
1049 }
1050}
1051
1052/*!
1053 \qmlproperty string QtMultimedia::Audio::errorString
1054
1055 This property holds a string describing the current error condition in more detail.
1056*/
1057
1058/*!
1059 \qmlsignal QtMultimedia::Audio::error(error, errorString)
1060
1061 This signal is emitted when an \a error has
1062 occurred. The \a errorString parameter may contain more detailed
1063 information about the error.
1064
1065 The corresponding handler is \c onError.
1066
1067 \sa QMediaPlayer::Error
1068*/
1069
1070/*!
1071 \qmlproperty variant QtMultimedia::Audio::mediaObject
1072
1073 This property holds the native media object.
1074
1075 It can be used to get a pointer to a QMediaPlayer object in order to integrate with C++ code.
1076
1077 \code
1078 QObject *qmlAudio; // The QML Audio object
1079 QMediaPlayer *player = qvariant_cast<QMediaPlayer *>(qmlAudio->property("mediaObject"));
1080 \endcode
1081
1082 \note This property is not accessible from QML.
1083*/
1084
1085/*!
1086 \qmlpropertygroup QtMultimedia::Audio::metaData
1087 \qmlproperty variant QtMultimedia::Audio::metaData.title
1088 \qmlproperty variant QtMultimedia::Audio::metaData.subTitle
1089 \qmlproperty variant QtMultimedia::Audio::metaData.author
1090 \qmlproperty variant QtMultimedia::Audio::metaData.comment
1091 \qmlproperty variant QtMultimedia::Audio::metaData.description
1092 \qmlproperty variant QtMultimedia::Audio::metaData.category
1093 \qmlproperty variant QtMultimedia::Audio::metaData.genre
1094 \qmlproperty variant QtMultimedia::Audio::metaData.year
1095 \qmlproperty variant QtMultimedia::Audio::metaData.date
1096 \qmlproperty variant QtMultimedia::Audio::metaData.userRating
1097 \qmlproperty variant QtMultimedia::Audio::metaData.keywords
1098 \qmlproperty variant QtMultimedia::Audio::metaData.language
1099 \qmlproperty variant QtMultimedia::Audio::metaData.publisher
1100 \qmlproperty variant QtMultimedia::Audio::metaData.copyright
1101 \qmlproperty variant QtMultimedia::Audio::metaData.parentalRating
1102 \qmlproperty variant QtMultimedia::Audio::metaData.ratingOrganization
1103 \qmlproperty variant QtMultimedia::Audio::metaData.size
1104 \qmlproperty variant QtMultimedia::Audio::metaData.mediaType
1105 \qmlproperty variant QtMultimedia::Audio::metaData.audioBitRate
1106 \qmlproperty variant QtMultimedia::Audio::metaData.audioCodec
1107 \qmlproperty variant QtMultimedia::Audio::metaData.averageLevel
1108 \qmlproperty variant QtMultimedia::Audio::metaData.channelCount
1109 \qmlproperty variant QtMultimedia::Audio::metaData.peakValue
1110 \qmlproperty variant QtMultimedia::Audio::metaData.sampleRate
1111 \qmlproperty variant QtMultimedia::Audio::metaData.albumTitle
1112 \qmlproperty variant QtMultimedia::Audio::metaData.albumArtist
1113 \qmlproperty variant QtMultimedia::Audio::metaData.contributingArtist
1114 \qmlproperty variant QtMultimedia::Audio::metaData.composer
1115 \qmlproperty variant QtMultimedia::Audio::metaData.conductor
1116 \qmlproperty variant QtMultimedia::Audio::metaData.lyrics
1117 \qmlproperty variant QtMultimedia::Audio::metaData.mood
1118 \qmlproperty variant QtMultimedia::Audio::metaData.trackNumber
1119 \qmlproperty variant QtMultimedia::Audio::metaData.trackCount
1120 \qmlproperty variant QtMultimedia::Audio::metaData.coverArtUrlSmall
1121 \qmlproperty variant QtMultimedia::Audio::metaData.coverArtUrlLarge
1122 \qmlproperty variant QtMultimedia::Audio::metaData.resolution
1123 \qmlproperty variant QtMultimedia::Audio::metaData.pixelAspectRatio
1124 \qmlproperty variant QtMultimedia::Audio::metaData.videoFrameRate
1125 \qmlproperty variant QtMultimedia::Audio::metaData.videoBitRate
1126 \qmlproperty variant QtMultimedia::Audio::metaData.videoCodec
1127 \qmlproperty variant QtMultimedia::Audio::metaData.posterUrl
1128 \qmlproperty variant QtMultimedia::Audio::metaData.chapterNumber
1129 \qmlproperty variant QtMultimedia::Audio::metaData.director
1130 \qmlproperty variant QtMultimedia::Audio::metaData.leadPerformer
1131 \qmlproperty variant QtMultimedia::Audio::metaData.writer
1132
1133 These properties hold the meta data for the current media.
1134
1135 \list
1136 \li \c metaData.title - the title of the media.
1137 \li \c metaData.subTitle - the sub-title of the media.
1138 \li \c metaData.author - the author of the media.
1139 \li \c metaData.comment - a user comment about the media.
1140 \li \c metaData.description - a description of the media.
1141 \li \c metaData.category - the category of the media.
1142 \li \c metaData.genre - the genre of the media.
1143 \li \c metaData.year - the year of release of the media.
1144 \li \c metaData.date - the date of the media.
1145 \li \c metaData.userRating - a user rating of the media in the range of 0 to 100.
1146 \li \c metaData.keywords - a list of keywords describing the media.
1147 \li \c metaData.language - the language of the media, as an ISO 639-2 code.
1148 \li \c metaData.publisher - the publisher of the media.
1149 \li \c metaData.copyright - the media's copyright notice.
1150 \li \c metaData.parentalRating - the parental rating of the media.
1151 \li \c metaData.ratingOrganization - the name of the rating organization responsible for the
1152 parental rating of the media.
1153 \li \c metaData.size - the size of the media in bytes.
1154 \li \c metaData.mediaType - the type of the media.
1155 \li \c metaData.audioBitRate - the bit rate of the media's audio stream in bits per second.
1156 \li \c metaData.audioCodec - the encoding of the media audio stream.
1157 \li \c metaData.averageLevel - the average volume level of the media.
1158 \li \c metaData.channelCount - the number of channels in the media's audio stream.
1159 \li \c metaData.peakValue - the peak volume of media's audio stream.
1160 \li \c metaData.sampleRate - the sample rate of the media's audio stream in hertz.
1161 \li \c metaData.albumTitle - the title of the album the media belongs to.
1162 \li \c metaData.albumArtist - the name of the principal artist of the album the media
1163 belongs to.
1164 \li \c metaData.contributingArtist - the names of artists contributing to the media.
1165 \li \c metaData.composer - the composer of the media.
1166 \li \c metaData.conductor - the conductor of the media.
1167 \li \c metaData.lyrics - the lyrics to the media.
1168 \li \c metaData.mood - the mood of the media.
1169 \li \c metaData.trackNumber - the track number of the media.
1170 \li \c metaData.trackCount - the number of tracks on the album containing the media.
1171 \li \c metaData.coverArtUrlSmall - the URL of a small cover art image.
1172 \li \c metaData.coverArtUrlLarge - the URL of a large cover art image.
1173 \li \c metaData.resolution - the dimension of an image or video.
1174 \li \c metaData.pixelAspectRatio - the pixel aspect ratio of an image or video.
1175 \li \c metaData.videoFrameRate - the frame rate of the media's video stream.
1176 \li \c metaData.videoBitRate - the bit rate of the media's video stream in bits per second.
1177 \li \c metaData.videoCodec - the encoding of the media's video stream.
1178 \li \c metaData.posterUrl - the URL of a poster image.
1179 \li \c metaData.chapterNumber - the chapter number of the media.
1180 \li \c metaData.director - the director of the media.
1181 \li \c metaData.leadPerformer - the lead performer in the media.
1182 \li \c metaData.writer - the writer of the media.
1183 \endlist
1184
1185 \sa {QMediaMetaData}
1186*/
1187
1188
1189///////////// MediaPlayer Docs /////////////
1190
1191/*!
1192 \qmltype MediaPlayer
1193 \instantiates QDeclarativeAudio
1194 \brief Add media playback to a scene.
1195
1196 \inqmlmodule QtMultimedia
1197 \ingroup multimedia_qml
1198 \ingroup multimedia_audio_qml
1199 \ingroup multimedia_video_qml
1200
1201 \qml
1202 Text {
1203 text: "Click Me!";
1204 font.pointSize: 24;
1205 width: 150; height: 50;
1206
1207 MediaPlayer {
1208 id: playMusic
1209 source: "music.wav"
1210 }
1211 MouseArea {
1212 id: playArea
1213 anchors.fill: parent
1214 onPressed: { playMusic.play() }
1215 }
1216 }
1217 \endqml
1218
1219 You can use MediaPlayer by itself to play audio content (like \l Audio),
1220 or you can use it in conjunction with a \l VideoOutput for rendering video.
1221
1222 \qml
1223 Item {
1224 MediaPlayer {
1225 id: mediaplayer
1226 source: "groovy_video.mp4"
1227 }
1228
1229 VideoOutput {
1230 anchors.fill: parent
1231 source: mediaplayer
1232 }
1233
1234 MouseArea {
1235 id: playArea
1236 anchors.fill: parent
1237 onPressed: mediaplayer.play();
1238 }
1239 }
1240 \endqml
1241
1242 \sa VideoOutput
1243*/
1244
1245/*!
1246 \qmlproperty enumeration QtMultimedia::MediaPlayer::availability
1247
1248 Returns the availability state of the media player.
1249
1250 This is one of:
1251 \table
1252 \header \li Value \li Description
1253 \row \li Available
1254 \li The media player is available to use.
1255 \row \li Busy
1256 \li The media player is usually available, but some other
1257 process is utilizing the hardware necessary to play media.
1258 \row \li Unavailable
1259 \li There are no supported media playback facilities.
1260 \row \li ResourceMissing
1261 \li There is one or more resources missing, so the media player cannot
1262 be used. It may be possible to try again at a later time.
1263 \endtable
1264 */
1265
1266/*!
1267 \qmlproperty enumeration QtMultimedia::MediaPlayer::audioRole
1268
1269 This property holds the role of the audio stream. It can be set to specify the type of audio
1270 being played, allowing the system to make appropriate decisions when it comes to volume,
1271 routing or post-processing.
1272
1273 The audio role must be set before setting the source property.
1274
1275 Supported values can be retrieved with supportedAudioRoles().
1276
1277 The value can be one of:
1278 \list
1279 \li UnknownRole - the role is unknown or undefined.
1280 \li MusicRole - music.
1281 \li VideoRole - soundtrack from a movie or a video.
1282 \li VoiceCommunicationRole - voice communications, such as telephony.
1283 \li AlarmRole - alarm.
1284 \li NotificationRole - notification, such as an incoming e-mail or a chat request.
1285 \li RingtoneRole - ringtone.
1286 \li AccessibilityRole - for accessibility, such as with a screen reader.
1287 \li SonificationRole - sonification, such as with user interface sounds.
1288 \li GameRole - game audio.
1289 \li CustomRole - The role is specified by customAudioRole.
1290 \endlist
1291
1292 customAudioRole is cleared when this property is set to anything other than CustomRole.
1293
1294 \since 5.6
1295*/
1296
1297/*!
1298 \qmlproperty string QtMultimedia::MediaPlayer::customAudioRole
1299
1300 This property holds the role of the audio stream when the backend supports audio
1301 roles unknown to Qt. It can be set to specify the type of audio being played,
1302 allowing the system to make appropriate decisions when it comes to volume,
1303 routing or post-processing.
1304
1305 The audio role must be set before setting the source property.
1306
1307 audioRole is set to CustomRole when this property is set.
1308
1309 \since 5.11
1310*/
1311
1312/*!
1313 \qmlmethod list<int> QtMultimedia::MediaPlayer::supportedAudioRoles()
1314
1315 Returns a list of supported audio roles.
1316
1317 If setting the audio role is not supported, an empty list is returned.
1318
1319 \since 5.6
1320 \sa audioRole
1321*/
1322
1323/*!
1324 \qmlproperty int QtMultimedia::MediaPlayer::notifyInterval
1325
1326 The interval at which notifiable properties will update.
1327
1328 The notifiable properties are \l position and \l bufferProgress.
1329
1330 The interval is expressed in milliseconds, the default value is 1000.
1331
1332 \since 5.9
1333*/
1334
1335/*!
1336 \qmlmethod QtMultimedia::MediaPlayer::play()
1337
1338 Starts playback of the media.
1339
1340 Sets the \l playbackState property to PlayingState.
1341*/
1342
1343/*!
1344 \qmlmethod QtMultimedia::MediaPlayer::pause()
1345
1346 Pauses playback of the media.
1347
1348 Sets the \l playbackState property to PausedState.
1349*/
1350
1351/*!
1352 \qmlmethod QtMultimedia::MediaPlayer::stop()
1353
1354 Stops playback of the media.
1355
1356 Sets the \l playbackState property to StoppedState.
1357*/
1358
1359/*!
1360 \qmlproperty url QtMultimedia::MediaPlayer::source
1361
1362 This property holds the source URL of the media.
1363
1364 Setting the \l source property clears the current \l playlist, if any.
1365
1366 Since Qt 5.12.2, the url scheme \c gst-pipeline provides custom pipelines
1367 for the GStreamer backend.
1368
1369 If the pipeline contains a \c qtvideosink element,
1370 the current VideoOutput will be used for rendering video.
1371
1372 \snippet multimedia-snippets/qtvideosink.qml complete
1373
1374 \sa QMediaPlayer::setMedia()
1375*/
1376
1377/*!
1378 \qmlproperty Playlist QtMultimedia::MediaPlayer::playlist
1379
1380 This property holds the playlist used by the media player.
1381
1382 Setting the \l playlist property resets the \l source to an empty string.
1383
1384 \since 5.6
1385*/
1386
1387/*!
1388 \qmlproperty int QtMultimedia::MediaPlayer::loops
1389
1390 This property holds the number of times the media is played. A value of \c 0 or \c 1 means
1391 the media will be played only once; set to \c MediaPlayer.Infinite to enable infinite looping.
1392
1393 The value can be changed while the media is playing, in which case it will update
1394 the remaining loops to the new value.
1395
1396 The default is \c 1.
1397*/
1398
1399/*!
1400 \qmlproperty bool QtMultimedia::MediaPlayer::autoLoad
1401
1402 This property indicates if loading of media should begin immediately.
1403
1404 Defaults to true, if false media will not be loaded until playback is started.
1405*/
1406
1407/*!
1408 \qmlsignal QtMultimedia::MediaPlayer::playbackStateChanged()
1409
1410 This signal is emitted when the \l playbackState property is altered.
1411
1412 The corresponding handler is \c onPlaybackStateChanged.
1413*/
1414
1415
1416/*!
1417 \qmlsignal QtMultimedia::MediaPlayer::paused()
1418
1419 This signal is emitted when playback is paused.
1420
1421 The corresponding handler is \c onPaused.
1422*/
1423
1424/*!
1425 \qmlsignal QtMultimedia::MediaPlayer::stopped()
1426
1427 This signal is emitted when playback is stopped.
1428
1429 The corresponding handler is \c onStopped.
1430*/
1431
1432/*!
1433 \qmlsignal QtMultimedia::MediaPlayer::playing()
1434
1435 This signal is emitted when playback is started or resumed.
1436
1437 The corresponding handler is \c onPlaying.
1438*/
1439
1440/*!
1441 \qmlproperty enumeration QtMultimedia::MediaPlayer::status
1442
1443 This property holds the status of media loading. It can be one of:
1444
1445 \list
1446 \li NoMedia - no media has been set.
1447 \li Loading - the media is currently being loaded.
1448 \li Loaded - the media has been loaded.
1449 \li Buffering - the media is buffering data.
1450 \li Stalled - playback has been interrupted while the media is buffering data.
1451 \li Buffered - the media has buffered data.
1452 \li EndOfMedia - the media has played to the end.
1453 \li InvalidMedia - the media cannot be played.
1454 \li UnknownStatus - the status of the media is unknown.
1455 \endlist
1456*/
1457
1458/*!
1459 \qmlproperty enumeration QtMultimedia::MediaPlayer::playbackState
1460
1461 This property holds the state of media playback. It can be one of:
1462
1463 \list
1464 \li PlayingState - the media is currently playing.
1465 \li PausedState - playback of the media has been suspended.
1466 \li StoppedState - playback of the media is yet to begin.
1467 \endlist
1468*/
1469
1470/*!
1471 \qmlproperty bool QtMultimedia::MediaPlayer::autoPlay
1472
1473 This property controls whether the media will begin to play on start up.
1474
1475 Defaults to \c false. If set to \c true, the value of autoLoad will be overwritten to \c true.
1476*/
1477
1478/*!
1479 \qmlproperty int QtMultimedia::MediaPlayer::duration
1480
1481 This property holds the duration of the media in milliseconds.
1482
1483 If the media doesn't have a fixed duration (a live stream for example) this will be 0.
1484*/
1485
1486/*!
1487 \qmlproperty int QtMultimedia::MediaPlayer::position
1488
1489 This property holds the current playback position in milliseconds.
1490
1491 To change this position, use the \l seek() method.
1492
1493 \sa seek()
1494*/
1495
1496/*!
1497 \qmlproperty real QtMultimedia::MediaPlayer::volume
1498
1499 This property holds the audio volume of the media player.
1500
1501 The volume is scaled linearly from \c 0.0 (silence) to \c 1.0 (full volume). Values outside this
1502 range will be clamped.
1503
1504 The default volume is \c 1.0.
1505
1506 UI volume controls should usually be scaled nonlinearly. For example, using a logarithmic scale
1507 will produce linear changes in perceived loudness, which is what a user would normally expect
1508 from a volume control. See \l {QtMultimedia::QtMultimedia::convertVolume()}{QtMultimedia.convertVolume()}
1509 for more details.
1510*/
1511
1512/*!
1513 \qmlproperty bool QtMultimedia::MediaPlayer::muted
1514
1515 This property holds whether the audio output is muted.
1516
1517 Defaults to false.
1518*/
1519
1520/*!
1521 \qmlproperty bool QtMultimedia::MediaPlayer::hasAudio
1522
1523 This property holds whether the media contains audio.
1524*/
1525
1526/*!
1527 \qmlproperty bool QtMultimedia::MediaPlayer::hasVideo
1528
1529 This property holds whether the media contains video.
1530*/
1531
1532/*!
1533 \qmlproperty real QtMultimedia::MediaPlayer::bufferProgress
1534
1535 This property holds how much of the data buffer is currently filled, from \c 0.0 (empty) to
1536 \c 1.0 (full).
1537
1538 Playback can start or resume only when the buffer is entirely filled, in which case the
1539 status is \c MediaPlayer.Buffered or \c MediaPlayer.Buffering. A value lower than \c 1.0
1540 implies that the status is \c MediaPlayer.Stalled.
1541
1542 \sa status
1543*/
1544
1545/*!
1546 \qmlproperty bool QtMultimedia::MediaPlayer::seekable
1547
1548 This property holds whether position of the audio can be changed.
1549
1550 If true, calling the \l seek() method will cause playback to seek to the new position.
1551*/
1552
1553/*!
1554 \qmlmethod QtMultimedia::MediaPlayer::seek(offset)
1555
1556 If the \l seekable property is true, seeks the current
1557 playback position to \a offset.
1558
1559 Seeking may be asynchronous, so the \l position property
1560 may not be updated immediately.
1561
1562 \sa seekable, position
1563*/
1564
1565/*!
1566 \qmlproperty real QtMultimedia::MediaPlayer::playbackRate
1567
1568 This property holds the rate at which audio is played at as a multiple of the normal rate.
1569
1570 Defaults to 1.0.
1571*/
1572
1573/*!
1574 \qmlproperty enumeration QtMultimedia::MediaPlayer::error
1575
1576 This property holds the error state of the audio. It can be one of:
1577
1578 \table
1579 \header \li Value \li Description
1580 \row \li NoError
1581 \li There is no current error.
1582 \row \li ResourceError
1583 \li The audio cannot be played due to a problem allocating resources.
1584 \row \li FormatError
1585 \li The audio format is not supported.
1586 \row \li NetworkError
1587 \li The audio cannot be played due to network issues.
1588 \row \li AccessDenied
1589 \li The audio cannot be played due to insufficient permissions.
1590 \row \li ServiceMissing
1591 \li The audio cannot be played because the media service could not be
1592 instantiated.
1593 \endtable
1594*/
1595
1596/*!
1597 \qmlproperty string QtMultimedia::MediaPlayer::errorString
1598
1599 This property holds a string describing the current error condition in more detail.
1600*/
1601
1602/*!
1603 \qmlsignal QtMultimedia::MediaPlayer::error(error, errorString)
1604
1605 This signal is emitted when an \a error has
1606 occurred. The \a errorString parameter may contain more detailed
1607 information about the error.
1608
1609 The corresponding handler is \c onError.
1610
1611 \sa QMediaPlayer::Error
1612*/
1613
1614/*!
1615 \qmlproperty variant QtMultimedia::MediaPlayer::mediaObject
1616
1617 This property holds the native media object.
1618
1619 It can be used to get a pointer to a QMediaPlayer object in order to integrate with C++ code.
1620
1621 \code
1622 QObject *qmlMediaPlayer; // The QML MediaPlayer object
1623 QMediaPlayer *player = qvariant_cast<QMediaPlayer *>(qmlMediaPlayer->property("mediaObject"));
1624 \endcode
1625
1626 \note This property is not accessible from QML.
1627*/
1628
1629/*!
1630 \qmlpropertygroup QtMultimedia::MediaPlayer::metaData
1631 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.title
1632 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.subTitle
1633 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.author
1634 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.comment
1635 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.description
1636 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.category
1637 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.genre
1638 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.year
1639 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.date
1640 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.userRating
1641 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.keywords
1642 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.language
1643 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.publisher
1644 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.copyright
1645 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.parentalRating
1646 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.ratingOrganization
1647 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.size
1648 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.mediaType
1649 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.audioBitRate
1650 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.audioCodec
1651 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.averageLevel
1652 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.channelCount
1653 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.peakValue
1654 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.sampleRate
1655 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.albumTitle
1656 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.albumArtist
1657 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.contributingArtist
1658 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.composer
1659 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.conductor
1660 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.lyrics
1661 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.mood
1662 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.trackNumber
1663 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.trackCount
1664 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.coverArtUrlSmall
1665 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.coverArtUrlLarge
1666 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.resolution
1667 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.pixelAspectRatio
1668 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.videoFrameRate
1669 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.videoBitRate
1670 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.videoCodec
1671 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.posterUrl
1672 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.chapterNumber
1673 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.director
1674 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.leadPerformer
1675 \qmlproperty variant QtMultimedia::MediaPlayer::metaData.writer
1676
1677 These properties hold the meta data for the current media.
1678
1679 \list
1680 \li \c metaData.title - the title of the media.
1681 \li \c metaData.subTitle - the sub-title of the media.
1682 \li \c metaData.author - the author of the media.
1683 \li \c metaData.comment - a user comment about the media.
1684 \li \c metaData.description - a description of the media.
1685 \li \c metaData.category - the category of the media.
1686 \li \c metaData.genre - the genre of the media.
1687 \li \c metaData.year - the year of release of the media.
1688 \li \c metaData.date - the date of the media.
1689 \li \c metaData.userRating - a user rating of the media in the range of 0 to 100.
1690 \li \c metaData.keywords - a list of keywords describing the media.
1691 \li \c metaData.language - the language of the media, as an ISO 639-2 code.
1692 \li \c metaData.publisher - the publisher of the media.
1693 \li \c metaData.copyright - the media's copyright notice.
1694 \li \c metaData.parentalRating - the parental rating of the media.
1695 \li \c metaData.ratingOrganization - the name of the rating organization responsible for the
1696 parental rating of the media.
1697 \li \c metaData.size - the size of the media in bytes.
1698 \li \c metaData.mediaType - the type of the media.
1699 \li \c metaData.audioBitRate - the bit rate of the media's audio stream in bits per second.
1700 \li \c metaData.audioCodec - the encoding of the media audio stream.
1701 \li \c metaData.averageLevel - the average volume level of the media.
1702 \li \c metaData.channelCount - the number of channels in the media's audio stream.
1703 \li \c metaData.peakValue - the peak volume of media's audio stream.
1704 \li \c metaData.sampleRate - the sample rate of the media's audio stream in hertz.
1705 \li \c metaData.albumTitle - the title of the album the media belongs to.
1706 \li \c metaData.albumArtist - the name of the principal artist of the album the media
1707 belongs to.
1708 \li \c metaData.contributingArtist - the names of artists contributing to the media.
1709 \li \c metaData.composer - the composer of the media.
1710 \li \c metaData.conductor - the conductor of the media.
1711 \li \c metaData.lyrics - the lyrics to the media.
1712 \li \c metaData.mood - the mood of the media.
1713 \li \c metaData.trackNumber - the track number of the media.
1714 \li \c metaData.trackCount - the number of tracks on the album containing the media.
1715 \li \c metaData.coverArtUrlSmall - the URL of a small cover art image.
1716 \li \c metaData.coverArtUrlLarge - the URL of a large cover art image.
1717 \li \c metaData.resolution - the dimension of an image or video.
1718 \li \c metaData.pixelAspectRatio - the pixel aspect ratio of an image or video.
1719 \li \c metaData.videoFrameRate - the frame rate of the media's video stream.
1720 \li \c metaData.videoBitRate - the bit rate of the media's video stream in bits per second.
1721 \li \c metaData.videoCodec - the encoding of the media's video stream.
1722 \li \c metaData.posterUrl - the URL of a poster image.
1723 \li \c metaData.chapterNumber - the chapter number of the media.
1724 \li \c metaData.director - the director of the media.
1725 \li \c metaData.leadPerformer - the lead performer in the media.
1726 \li \c metaData.writer - the writer of the media.
1727 \endlist
1728
1729 \sa {QMediaMetaData}
1730*/
1731
1732QT_END_NAMESPACE
1733
1734#include "moc_qdeclarativeaudio_p.cpp"
1735
1736
1737

source code of qtmultimedia/src/imports/multimedia/qdeclarativeaudio.cpp