summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngus Cummings <angus.cummings@nokia.com>2012-02-03 11:49:47 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-08 03:48:51 +0100
commita94c8a1ac26f4a5a79d63672d21538d016bc09f4 (patch)
treeaaadf76db98dbf9d1ba228c7e0c68868242f0355
parent66b86ba5812ba15c177f7c6b2916bca4376749ce (diff)
API changes to QML element MediaPlayer aka Audio
Changed Video.qml for new API Removed lowercase enum copies, replaced with calling parent (VideoOutput, MediaPlayer) enums Removed properties playing, paused Removed signals started, resumed Added readonly property playbackState Added signal playing Added autoPlay property Fixed unit tests for new API Added backwards compatibility for QtMultimedia 4 Change-Id: I27c91cd46d91402b8c4c42bb7d4961ad67909aeb Reviewed-by: Michael Goddard <michael.goddard@nokia.com> Reviewed-by: Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com>
-rw-r--r--src/imports/multimedia/Video.qml92
-rw-r--r--src/imports/multimedia/Video_4.qml99
-rw-r--r--src/imports/multimedia/multimedia.cpp5
-rw-r--r--src/imports/multimedia/multimedia.pro11
-rw-r--r--src/imports/multimedia/qdeclarativeaudio.cpp72
-rw-r--r--src/imports/multimedia/qdeclarativeaudio_4.cpp729
-rw-r--r--src/imports/multimedia/qdeclarativeaudio_p.h23
-rw-r--r--src/imports/multimedia/qdeclarativeaudio_p_4.h190
-rw-r--r--src/imports/multimedia/qdeclarativemediabase.cpp165
-rw-r--r--src/imports/multimedia/qdeclarativemediabase_4.cpp567
-rw-r--r--src/imports/multimedia/qdeclarativemediabase_p.h32
-rw-r--r--src/imports/multimedia/qdeclarativemediabase_p_4.h188
-rw-r--r--src/imports/multimedia/qmldir1
-rw-r--r--tests/auto/unit/multimedia.pro12
-rw-r--r--tests/auto/unit/qdeclarativeaudio/tst_qdeclarativeaudio.cpp467
-rw-r--r--tests/auto/unit/qdeclarativeaudio_4/qdeclarativeaudio_4.pro17
-rw-r--r--tests/auto/unit/qdeclarativeaudio_4/tst_qdeclarativeaudio_4.cpp1300
17 files changed, 3385 insertions, 585 deletions
diff --git a/src/imports/multimedia/Video.qml b/src/imports/multimedia/Video.qml
index e62e98a8..a8f67e79 100644
--- a/src/imports/multimedia/Video.qml
+++ b/src/imports/multimedia/Video.qml
@@ -95,17 +95,16 @@ Item {
area.
\list
- \o stretch - the video is scaled to fit.
- \o preserveAspectFit - the video is scaled uniformly to fit without
+ \o VideoOutput.Stretch - the video is scaled to fit
+ \o VideoOutput.PreserveAspectFit - the video is scaled uniformly to fit without
cropping
- \o preserveAspectCrop - the video is scaled uniformly to fill, cropping
+ \o VideoOuput.PreserveAspectCrop - the video is scaled uniformly to fill, cropping
if necessary
\endlist
Because this element is a convenience element in QML, it does not
- support enumerations directly. In contrast to \l VideoOutput and other
- elements, the values to set for fillMode all start with lowercase
- letters to work around this.
+ support enumerations directly, so enumerations from VideoOuput are
+ used to access the available fill modes.
The default fill mode is preserveAspectFit.
*/
@@ -119,15 +118,24 @@ Item {
*/
property alias orientation: videoOut.orientation
- /* Properties to emulate enumeration for fillMode, documented above */
- /*! \internal */
- readonly property int stretch: VideoOutput.Stretch
- /*! \internal */
- readonly property int preserveAspectFit: VideoOutput.PreserveAspectFit
- /*! \internal */
- readonly property int preserveAspectCrop: VideoOutput.PreserveAspectCrop
/*** Properties of MediaPlayer ***/
+
+ /*!
+ \qmlproperty enumeration Video::playbackState
+
+ This read only property indicates the playback state of the media.
+
+ \list
+ \o MediaPlayer.PlayingState - the media is playing
+ \o MediaPlayer.PausedState - the media is paused
+ \o MediaPlayer.StoppedState - the media is stopped
+ \endlist
+
+ The default state is MediaPlayer.StoppedState.
+ */
+ property alias playbackState: player.playbackState
+
/*!
\qmlproperty bool Video::autoLoad
@@ -195,15 +203,6 @@ Item {
property alias muted: player.muted
/*!
- \qmlproperty bool Video::paused
-
- This property holds whether the media is paused.
-
- Defaults to false, and can be set to true to pause playback.
- */
- property alias paused: player.paused
-
- /*!
\qmlproperty real Video::playbackRate
This property holds the rate at which video is played at as a multiple
@@ -212,15 +211,6 @@ Item {
property alias playbackRate: player.playbackRate
/*!
- \qmlproperty bool Video::playing
-
- This property holds whether the media is playing.
-
- Defaults to false, and can be set to true to start playback.
- */
- property alias playing: player.playing
-
- /*!
\qmlproperty int Video::position
This property holds the current playback position in milliseconds.
@@ -269,17 +259,19 @@ Item {
property alias volume: player.volume
/*!
- \qmlsignal Video::resumed()
+ \qmlproperty bool Video::autoPlay
- This signal is emitted when playback is resumed from the paused state.
+ This property determines whether the media should begin playback automatically.
*/
- signal resumed
+ property alias autoPlay: player.autoPlay
+
/*!
- \qmlsignal Video::started()
+ \qmlsignal Video::paused()
- This signal is emitted when playback is started.
+ This signal is emitted when playback is paused.
*/
- signal started
+ signal paused
+
/*!
\qmlsignal Video::stopped()
@@ -287,6 +279,19 @@ Item {
*/
signal stopped
+ /*!
+ \qmlsignal Video::playing()
+
+ This signal is emitted when playback is started or continued.
+ */
+ signal playing
+
+ /*!
+ \qmlsignal Video::playbackStateChanged()
+
+ This signal is emitted whenever the state of playback changes.
+ */
+ signal playbackStateChanged
VideoOutput {
id: videoOut
@@ -296,18 +301,17 @@ Item {
MediaPlayer {
id: player
- onResumed: video.resumed()
- onStarted: video.started()
+ onPaused: video.paused()
onStopped: video.stopped()
+ onPlaying: video.playing()
+
+ onPlaybackStateChanged: video.playbackStateChanged()
}
/*!
\qmlmethod Video::play()
Starts playback of the media.
-
- Sets the \l playing property to true, and the \l paused property to
- false.
*/
function play() {
player.play();
@@ -317,8 +321,6 @@ Item {
\qmlmethod Video::pause()
Pauses playback of the media.
-
- Sets the \l playing and \l paused properties to true.
*/
function pause() {
player.pause();
@@ -328,8 +330,6 @@ Item {
\qmlmethod Video::stop()
Stops playback of the media.
-
- Sets the \l playing and \l paused properties to false.
*/
function stop() {
player.stop();
diff --git a/src/imports/multimedia/Video_4.qml b/src/imports/multimedia/Video_4.qml
new file mode 100644
index 00000000..aab44515
--- /dev/null
+++ b/src/imports/multimedia/Video_4.qml
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtMultimedia 4.0
+
+Item {
+ id: video
+
+ property alias fillMode: videoOut.fillMode
+ property alias orientation: videoOut.orientation
+
+ readonly property int stretch: VideoOutput.Stretch
+ readonly property int preserveAspectFit: VideoOutput.PreserveAspectFit
+ readonly property int preserveAspectCrop: VideoOutput.PreserveAspectCrop
+
+ property alias autoLoad: player.autoLoad
+ property alias bufferProgress: player.bufferProgress
+ property alias duration: player.duration
+ property alias error: player.error
+ property alias errorString: player.errorString
+ property alias metaData: player.metaData
+ property alias muted: player.muted
+ property alias paused: player.paused
+ property alias playbackRate: player.playbackRate
+ property alias playing: player.playing
+ property alias position: player.position
+ property alias seekable: player.seekable
+ property alias source: player.source
+ property alias status: player.status
+ property alias volume: player.volume
+
+ signal resumed
+ signal started
+ signal stopped
+
+ VideoOutput {
+ id: videoOut
+ anchors.fill: video
+ source: player
+ }
+
+ MediaPlayer {
+ id: player
+ onResumed: video.resumed()
+ onStarted: video.started()
+ onStopped: video.stopped()
+ }
+
+ function play() {
+ player.play();
+ }
+
+ function pause() {
+ player.pause();
+ }
+
+ function stop() {
+ player.stop();
+ }
+}
diff --git a/src/imports/multimedia/multimedia.cpp b/src/imports/multimedia/multimedia.cpp
index 46e6a938..7a7a7986 100644
--- a/src/imports/multimedia/multimedia.cpp
+++ b/src/imports/multimedia/multimedia.cpp
@@ -47,6 +47,7 @@
#include "qdeclarativemediametadata_p.h"
#include "qdeclarativeaudio_p.h"
+#include "qdeclarativeaudio_p_4.h"
#include "qdeclarativevideooutput_p.h"
#include "qdeclarativeradio_p.h"
#include "qdeclarativeradiodata_p.h"
@@ -74,8 +75,8 @@ public:
|| QLatin1String(uri) == QLatin1String("Qt.multimediakit"));
qmlRegisterType<QSoundEffect>(uri, 4, 0, "SoundEffect");
- qmlRegisterType<QDeclarativeAudio>(uri, 4, 0, "Audio");
- qmlRegisterType<QDeclarativeAudio>(uri, 4, 0, "MediaPlayer");
+ qmlRegisterType<QDeclarativeAudio_4>(uri, 4, 0, "Audio");
+ qmlRegisterType<QDeclarativeAudio_4>(uri, 4, 0, "MediaPlayer");
qmlRegisterType<QDeclarativeVideoOutput>(uri, 4, 0, "VideoOutput");
qmlRegisterType<QDeclarativeRadio>(uri, 4, 0, "Radio");
qmlRegisterType<QDeclarativeRadioData>(uri, 4, 0, "RadioData");
diff --git a/src/imports/multimedia/multimedia.pro b/src/imports/multimedia/multimedia.pro
index f9c7f6e8..df01cc6b 100644
--- a/src/imports/multimedia/multimedia.pro
+++ b/src/imports/multimedia/multimedia.pro
@@ -27,7 +27,9 @@ HEADERS += \
qdeclarativecamerafocus_p.h \
qdeclarativecameraimageprocessing_p.h \
qdeclarativecamerapreviewprovider_p.h \
- qdeclarativetorch_p.h
+ qdeclarativetorch_p.h \
+ qdeclarativeaudio_p_4.h \
+ qdeclarativemediabase_p_4.h
SOURCES += \
multimedia.cpp \
@@ -48,10 +50,13 @@ SOURCES += \
qdeclarativecamerafocus.cpp \
qdeclarativecameraimageprocessing.cpp \
qdeclarativecamerapreviewprovider.cpp \
- qdeclarativetorch.cpp
+ qdeclarativetorch.cpp \
+ qdeclarativemediabase_4.cpp \
+ qdeclarativeaudio_4.cpp
OTHER_FILES += \
- Video.qml
+ Video_4.qml \
+ Video.qml
qmldir.files += $$PWD/qmldir $$PWD/Video.qml
qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
diff --git a/src/imports/multimedia/qdeclarativeaudio.cpp b/src/imports/multimedia/qdeclarativeaudio.cpp
index 3fb4ae7e..4e84f557 100644
--- a/src/imports/multimedia/qdeclarativeaudio.cpp
+++ b/src/imports/multimedia/qdeclarativeaudio.cpp
@@ -166,7 +166,7 @@ QDeclarativeAudio::~QDeclarativeAudio()
Starts playback of the media.
- Sets the \l playing property to true, and the \l paused property to false.
+ Sets the \l playbackState property to PlayingState.
*/
void QDeclarativeAudio::play()
@@ -174,8 +174,7 @@ void QDeclarativeAudio::play()
if (!m_complete)
return;
- setPaused(false);
- setPlaying(true);
+ setPlaybackState(QMediaPlayer::PlayingState);
}
/*!
@@ -183,7 +182,7 @@ void QDeclarativeAudio::play()
Pauses playback of the media.
- Sets the \l playing and \l paused properties to true.
+ Sets the \l playbackState property to PausedState.
*/
void QDeclarativeAudio::pause()
@@ -191,8 +190,7 @@ void QDeclarativeAudio::pause()
if (!m_complete)
return;
- setPaused(true);
- setPlaying(true);
+ setPlaybackState(QMediaPlayer::PausedState);
}
/*!
@@ -200,7 +198,7 @@ void QDeclarativeAudio::pause()
Stops playback of the media.
- Sets the \l playing and \l paused properties to false.
+ Sets the \l playbackState property to StoppedState.
*/
void QDeclarativeAudio::stop()
@@ -208,8 +206,7 @@ void QDeclarativeAudio::stop()
if (!m_complete)
return;
- setPlaying(false);
- setPaused(false);
+ setPlaybackState(QMediaPlayer::StoppedState);
}
/*!
@@ -227,43 +224,28 @@ void QDeclarativeAudio::stop()
*/
/*!
- \qmlproperty bool Audio::playing
+ \qmlsignal Audio::playbackStateChanged()
- This property holds whether the media is playing.
-
- Defaults to false, and can be set to true to start playback.
+ This handler is called when the \l playbackState property is altered.
*/
-/*!
- \qmlproperty bool Audio::paused
-
- This property holds whether the media is paused.
-
- Defaults to false, and can be set to true to pause playback.
-*/
/*!
- \qmlsignal Audio::onStarted()
-
- This handler is called when playback is started.
-*/
+ \qmlsignal Audio::paused()
-/*!
- \qmlsignal Audio::onResumed()
-
- This handler is called when playback is resumed from the paused state.
+ This handler is called when playback is paused.
*/
/*!
- \qmlsignal Audio::onPaused()
+ \qmlsignal Audio::stopped()
- This handler is called when playback is paused.
+ This handler is called when playback is stopped.
*/
/*!
- \qmlsignal Audio::onStopped()
+ \qmlsignal Audio::playing()
- This handler is called when playback is stopped.
+ This handler is called when playback is started or resumed.
*/
/*!
@@ -289,6 +271,32 @@ QDeclarativeAudio::Status QDeclarativeAudio::status() const
return Status(m_status);
}
+
+/*!
+ \qmlproperty enumeration Audio::playbackState
+
+ This property holds the state of media playback. It can be one of:
+
+ \list
+ \o PlayingState - the media is currently playing.
+ \o PausedState - playback of the media has been suspended.
+ \o StoppedState - playback of the media is yet to begin.
+ \endlist
+*/
+
+QDeclarativeAudio::PlaybackState QDeclarativeAudio::playbackState() const
+{
+ return PlaybackState(m_playbackState);
+}
+
+/*!
+ \qmlproperty int Audio::autoPlay
+
+ This property controls whether the media will begin to play on start up.
+
+ Defaults to false, if set true the value of autoLoad will be overwritten to true.
+*/
+
/*!
\qmlproperty int Audio::duration
diff --git a/src/imports/multimedia/qdeclarativeaudio_4.cpp b/src/imports/multimedia/qdeclarativeaudio_4.cpp
new file mode 100644
index 00000000..5cff803c
--- /dev/null
+++ b/src/imports/multimedia/qdeclarativeaudio_4.cpp
@@ -0,0 +1,729 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdeclarativeaudio_p_4.h"
+
+#include <qmediaplayercontrol.h>
+
+QT_BEGIN_NAMESPACE
+
+
+/*!
+ \qmlclass Audio QDeclarativeAudio
+ \brief The Audio element allows you to add audio playback to a scene.
+
+ \ingroup multimedia_qml
+
+ This element is part of the \bold{QtMultimedia 5.0} module.
+
+ \qml
+ import QtQuick 2.0
+ import QtMultimedia 5.0
+
+ Text {
+ text: "Click Me!";
+ font.pointSize: 24;
+ width: 150; height: 50;
+
+ Audio {
+ id: playMusic
+ source: "music.wav"
+ }
+ MouseArea {
+ id: playArea
+ anchors.fill: parent
+ onPressed: { playMusic.play() }
+ }
+ }
+ \endqml
+
+ \sa Video
+*/
+
+/*!
+ \internal
+ \class QDeclarativeAudio
+ \brief The QDeclarativeAudio class provides an audio item that you can add to a QDeclarativeView.
+*/
+
+void QDeclarativeAudio_4::_q_error(int errorCode, const QString &errorString)
+{
+ m_error = QMediaPlayer::Error(errorCode);
+ m_errorString = errorString;
+
+ emit error(Error(errorCode), errorString);
+ emit errorChanged();
+}
+
+
+QDeclarativeAudio_4::QDeclarativeAudio_4(QObject *parent)
+ : QObject(parent)
+{
+}
+
+QDeclarativeAudio_4::~QDeclarativeAudio_4()
+{
+ shutdown();
+}
+
+/*!
+ \qmlmethod Audio::play()
+
+ Starts playback of the media.
+
+ Sets the \l playing property to true, and the \l paused property to false.
+*/
+
+void QDeclarativeAudio_4::play()
+{
+ if (!m_complete)
+ return;
+
+ setPaused(false);
+ setPlaying(true);
+}
+
+/*!
+ \qmlmethod Audio::pause()
+
+ Pauses playback of the media.
+
+ Sets the \l playing and \l paused properties to true.
+*/
+
+void QDeclarativeAudio_4::pause()
+{
+ if (!m_complete)
+ return;
+
+ setPaused(true);
+ setPlaying(true);
+}
+
+/*!
+ \qmlmethod Audio::stop()
+
+ Stops playback of the media.
+
+ Sets the \l playing and \l paused properties to false.
+*/
+
+void QDeclarativeAudio_4::stop()
+{
+ if (!m_complete)
+ return;
+
+ setPlaying(false);
+ setPaused(false);
+}
+
+/*!
+ \qmlproperty url Audio::source
+
+ This property holds the source URL of the media.
+*/
+
+/*!
+ \qmlproperty url Audio::autoLoad
+
+ This property indicates if loading of media should begin immediately.
+
+ Defaults to true, if false media will not be loaded until playback is started.
+*/
+
+/*!
+ \qmlproperty bool Audio::playing
+
+ This property holds whether the media is playing.
+
+ Defaults to false, and can be set to true to start playback.
+*/
+
+/*!
+ \qmlproperty bool Audio::paused
+
+ This property holds whether the media is paused.
+
+ Defaults to false, and can be set to true to pause playback.
+*/
+
+/*!
+ \qmlsignal Audio::onStarted()
+
+ This handler is called when playback is started.
+*/
+
+/*!
+ \qmlsignal Audio::onResumed()
+
+ This handler is called when playback is resumed from the paused state.
+*/
+
+/*!
+ \qmlsignal Audio::onPaused()
+
+ This handler is called when playback is paused.
+*/
+
+/*!
+ \qmlsignal Audio::onStopped()
+
+ This handler is called when playback is stopped.
+*/
+
+/*!
+ \qmlproperty enumeration Audio::status
+
+ This property holds the status of media loading. It can be one of:
+
+ \list
+ \o NoMedia - no media has been set.
+ \o Loading - the media is currently being loaded.
+ \o Loaded - the media has been loaded.
+ \o Buffering - the media is buffering data.
+ \o Stalled - playback has been interrupted while the media is buffering data.
+ \o Buffered - the media has buffered data.
+ \o EndOfMedia - the media has played to the end.
+ \o InvalidMedia - the media cannot be played.
+ \o UnknownStatus - the status of the media is unknown.
+ \endlist
+*/
+
+QDeclarativeAudio_4::Status QDeclarativeAudio_4::status() const
+{
+ return Status(m_status);
+}
+
+/*!
+ \qmlproperty int Audio::duration
+
+ This property holds the duration of the media in milliseconds.
+
+ If the media doesn't have a fixed duration (a live stream for example) this will be 0.
+*/
+
+/*!
+ \qmlproperty int Audio::position
+
+ This property holds the current playback position in milliseconds.
+
+ If the \l seekable property is true, this property can be set to seek to a new position.
+*/
+
+/*!
+ \qmlproperty real Audio::volume
+
+ This property holds the volume of the audio output, from 0.0 (silent) to 1.0 (maximum volume).
+*/
+
+/*!
+ \qmlproperty bool Audio::muted
+
+ This property holds whether the audio output is muted.
+*/
+
+/*!
+ \qmlproperty bool Audio::hasAudio
+
+ This property holds whether the media contains audio.
+*/
+
+bool QDeclarativeAudio_4::hasAudio() const
+{
+ return !m_complete ? false : m_playerControl->isAudioAvailable();
+}
+
+/*!
+ \qmlproperty bool Audio::hasVideo
+
+ This property holds whether the media contains video.
+*/
+
+bool QDeclarativeAudio_4::hasVideo() const
+{
+ return !m_complete ? false : m_playerControl->isVideoAvailable();
+}
+
+/*!
+ \qmlproperty real Audio::bufferProgress
+
+ This property holds how much of the data buffer is currently filled, from 0.0 (empty) to 1.0
+ (full).
+*/
+
+/*!
+ \qmlproperty bool Audio::seekable
+
+ This property holds whether position of the audio can be changed.
+
+ If true; setting a \l position value will cause playback to seek to the new position.
+*/
+
+/*!
+ \qmlproperty real Audio::playbackRate
+
+ This property holds the rate at which audio is played at as a multiple of the normal rate.
+*/
+
+/*!
+ \qmlproperty enumeration Audio::error
+
+ This property holds the error state of the audio. It can be one of:
+
+ \list
+ \o NoError - there is no current error.
+ \o ResourceError - the audio cannot be played due to a problem allocating resources.
+ \o FormatError - the audio format is not supported.
+ \o NetworkError - the audio cannot be played due to network issues.
+ \o AccessDenied - the audio cannot be played due to insufficient permissions.
+ \o ServiceMissing - the audio cannot be played because the media service could not be
+ instantiated.
+ \endlist
+*/
+
+QDeclarativeAudio_4::Error QDeclarativeAudio_4::error() const
+{
+ return Error(m_error);
+}
+
+void QDeclarativeAudio_4::classBegin()
+{
+ setObject(this);
+
+ if (m_mediaService) {
+ connect(m_playerControl, SIGNAL(audioAvailableChanged(bool)),
+ this, SIGNAL(hasAudioChanged()));
+ connect(m_playerControl, SIGNAL(videoAvailableChanged(bool)),
+ this, SIGNAL(hasVideoChanged()));
+ }
+
+ emit mediaObjectChanged();
+}
+
+void QDeclarativeAudio_4::componentComplete()
+{
+ QDeclarativeMediaBase_4::componentComplete();
+}
+
+
+/*!
+ \qmlproperty string Audio::errorString
+
+ This property holds a string describing the current error condition in more detail.
+*/
+
+/*!
+ \qmlsignal Audio::onError(error, errorString)
+
+ This handler is called when an \l {QMediaPlayer::Error}{error} has
+ occurred. The errorString parameter may contain more detailed
+ information about the error.
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.title
+
+ This property holds the tile of the media.
+
+ \sa {QtMultimedia::MetaData::Title}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.subTitle
+
+ This property holds the sub-title of the media.
+
+ \sa {QtMultimedia::MetaData::SubTitle}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.author
+
+ This property holds the author of the media.
+
+ \sa {QtMultimedia::MetaData::Author}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.comment
+
+ This property holds a user comment about the media.
+
+ \sa {QtMultimedia::MetaData::Comment}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.description
+
+ This property holds a description of the media.
+
+ \sa {QtMultimedia::MetaData::Description}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.category
+
+ This property holds the category of the media
+
+ \sa {QtMultimedia::MetaData::Category}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.genre
+
+ This property holds the genre of the media.
+
+ \sa {QtMultimedia::MetaData::Genre}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.year
+
+ This property holds the year of release of the media.
+
+ \sa {QtMultimedia::MetaData::Year}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.date
+
+ This property holds the date of the media.
+
+ \sa {QtMultimedia::MetaData::Date}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.userRating
+
+ This property holds a user rating of the media in the range of 0 to 100.
+
+ \sa {QtMultimedia::MetaData::UserRating}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.keywords
+
+ This property holds a list of keywords describing the media.
+
+ \sa {QtMultimedia::MetaData::Keywords}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.language
+
+ This property holds the language of the media, as an ISO 639-2 code.
+
+ \sa {QtMultimedia::MetaData::Language}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.publisher
+
+ This property holds the publisher of the media.
+
+ \sa {QtMultimedia::MetaData::Publisher}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.copyright
+
+ This property holds the media's copyright notice.
+
+ \sa {QtMultimedia::MetaData::Copyright}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.parentalRating
+
+ This property holds the parental rating of the media.
+
+ \sa {QtMultimedia::MetaData::ParentalRating}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.ratingOrganization
+
+ This property holds the name of the rating organization responsible for the
+ parental rating of the media.
+
+ \sa {QtMultimedia::MetaData::RatingOrganization}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.size
+
+ This property property holds the size of the media in bytes.
+
+ \sa {QtMultimedia::MetaData::Size}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.mediaType
+
+ This property holds the type of the media.
+
+ \sa {QtMultimedia::MetaData::MediaType}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.audioBitRate
+
+ This property holds the bit rate of the media's audio stream ni bits per
+ second.
+
+ \sa {QtMultimedia::MetaData::AudioBitRate}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.audioCodec
+
+ This property holds the encoding of the media audio stream.
+
+ \sa {QtMultimedia::MetaData::AudioCodec}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.averageLevel
+
+ This property holds the average volume level of the media.
+
+ \sa {QtMultimedia::MetaData::AverageLevel}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.channelCount
+
+ This property holds the number of channels in the media's audio stream.
+
+ \sa {QtMultimedia::MetaData::ChannelCount}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.peakValue
+
+ This property holds the peak volume of media's audio stream.
+
+ \sa {QtMultimedia::MetaData::PeakValue}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.sampleRate
+
+ This property holds the sample rate of the media's audio stream in hertz.
+
+ \sa {QtMultimedia::MetaData::SampleRate}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.albumTitle
+
+ This property holds the title of the album the media belongs to.
+
+ \sa {QtMultimedia::MetaData::AlbumTitle}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.albumArtist
+
+ This property holds the name of the principal artist of the album the media
+ belongs to.
+
+ \sa {QtMultimedia::MetaData::AlbumArtist}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.contributingArtist
+
+ This property holds the names of artists contributing to the media.
+
+ \sa {QtMultimedia::MetaData::ContributingArtist}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.composer
+
+ This property holds the composer of the media.
+
+ \sa {QtMultimedia::MetaData::Composer}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.conductor
+
+ This property holds the conductor of the media.
+
+ \sa {QtMultimedia::MetaData::Conductor}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.lyrics
+
+ This property holds the lyrics to the media.
+
+ \sa {QtMultimedia::MetaData::Lyrics}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.mood
+
+ This property holds the mood of the media.
+
+ \sa {QtMultimedia::MetaData::Mood}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.trackNumber
+
+ This property holds the track number of the media.
+
+ \sa {QtMultimedia::MetaData::TrackNumber}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.trackCount
+
+ This property holds the number of track on the album containing the media.
+
+ \sa {QtMultimedia::MetaData::TrackNumber}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.coverArtUrlSmall
+
+ This property holds the URL of a small cover art image.
+
+ \sa {QtMultimedia::MetaData::CoverArtUrlSmall}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.coverArtUrlLarge
+
+ This property holds the URL of a large cover art image.
+
+ \sa {QtMultimedia::MetaData::CoverArtUrlLarge}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.resolution
+
+ This property holds the dimension of an image or video.
+
+ \sa {QtMultimedia::MetaData::Resolution}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.pixelAspectRatio
+
+ This property holds the pixel aspect ratio of an image or video.
+
+ \sa {QtMultimedia::MetaData::PixelAspectRatio}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.videoFrameRate
+
+ This property holds the frame rate of the media's video stream.
+
+ \sa {QtMultimedia::MetaData::VideoFrameRate}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.videoBitRate
+
+ This property holds the bit rate of the media's video stream in bits per
+ second.
+
+ \sa {QtMultimedia::MetaData::VideoBitRate}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.videoCodec
+
+ This property holds the encoding of the media's video stream.
+
+ \sa {QtMultimedia::MetaData::VideoCodec}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.posterUrl
+
+ This property holds the URL of a poster image.
+
+ \sa {QtMultimedia::MetaData::PosterUrl}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.chapterNumber
+
+ This property holds the chapter number of the media.
+
+ \sa {QtMultimedia::MetaData::ChapterNumber}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.director
+
+ This property holds the director of the media.
+
+ \sa {QtMultimedia::MetaData::Director}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.leadPerformer
+
+ This property holds the lead performer in the media.
+
+ \sa {QtMultimedia::MetaData::LeadPerformer}
+*/
+
+/*!
+ \qmlproperty variant Audio::metaData.writer
+
+ This property holds the writer of the media.
+
+ \sa {QtMultimedia::MetaData::Writer}
+*/
+
+QT_END_NAMESPACE
+
+#include "moc_qdeclarativeaudio_p_4.cpp"
+
+
diff --git a/src/imports/multimedia/qdeclarativeaudio_p.h b/src/imports/multimedia/qdeclarativeaudio_p.h
index 5976015f..94283289 100644
--- a/src/imports/multimedia/qdeclarativeaudio_p.h
+++ b/src/imports/multimedia/qdeclarativeaudio_p.h
@@ -69,10 +69,10 @@ class QDeclarativeAudio : public QObject, public QDeclarativeMediaBase, public Q
{
Q_OBJECT
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
- Q_PROPERTY(bool autoLoad READ isAutoLoad WRITE setAutoLoad NOTIFY autoLoadChanged)
- Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged)
Q_PROPERTY(int loops READ loopCount WRITE setLoopCount NOTIFY loopCountChanged)
- Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged)
+ Q_PROPERTY(PlaybackState playbackState READ playbackState NOTIFY playbackStateChanged)
+ Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay NOTIFY autoPlayChanged)
+ Q_PROPERTY(bool autoLoad READ isAutoLoad WRITE setAutoLoad NOTIFY autoLoadChanged)
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
Q_PROPERTY(int duration READ duration NOTIFY durationChanged)
Q_PROPERTY(int position READ position WRITE setPosition NOTIFY positionChanged)
@@ -90,6 +90,7 @@ class QDeclarativeAudio : public QObject, public QDeclarativeMediaBase, public Q
Q_ENUMS(Status)
Q_ENUMS(Error)
Q_ENUMS(Loop)
+ Q_ENUMS(PlaybackState)
Q_INTERFACES(QDeclarativeParserStatus)
public:
enum Status
@@ -120,6 +121,13 @@ public:
Infinite = QDeclarativeMediaBase::INFINITE
};
+ enum PlaybackState
+ {
+ PlayingState = QMediaPlayer::PlayingState,
+ PausedState = QMediaPlayer::PausedState,
+ StoppedState = QMediaPlayer::StoppedState
+ };
+
QDeclarativeAudio(QObject *parent = 0);
~QDeclarativeAudio();
@@ -128,6 +136,7 @@ public:
Status status() const;
Error error() const;
+ PlaybackState playbackState() const;
void classBegin();
void componentComplete();
@@ -142,14 +151,14 @@ public Q_SLOTS:
Q_SIGNALS:
void sourceChanged();
void autoLoadChanged();
- void playingChanged();
- void pausedChanged();
void loopCountChanged();
- void started();
- void resumed();
+ void playbackStateChanged();
+ void autoPlayChanged();
+
void paused();
void stopped();
+ void playing();
void statusChanged();
diff --git a/src/imports/multimedia/qdeclarativeaudio_p_4.h b/src/imports/multimedia/qdeclarativeaudio_p_4.h
new file mode 100644
index 00000000..02c873df
--- /dev/null
+++ b/src/imports/multimedia/qdeclarativeaudio_p_4.h
@@ -0,0 +1,190 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVEAUDIO_4_P_H
+#define QDECLARATIVEAUDIO_4_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qbasictimer.h>
+#include <QtDeclarative/qdeclarativeparserstatus.h>
+#include <QtDeclarative/qdeclarative.h>
+
+#include "qdeclarativemediabase_p_4.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QTimerEvent;
+
+class QDeclarativeAudio_4 : public QObject, public QDeclarativeMediaBase_4, public QDeclarativeParserStatus
+{
+ Q_OBJECT
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(bool autoLoad READ isAutoLoad WRITE setAutoLoad NOTIFY autoLoadChanged)
+ Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged)
+ Q_PROPERTY(int loops READ loopCount WRITE setLoopCount NOTIFY loopCountChanged)
+ Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged)
+ Q_PROPERTY(Status status READ status NOTIFY statusChanged)
+ Q_PROPERTY(int duration READ duration NOTIFY durationChanged)
+ Q_PROPERTY(int position READ position WRITE setPosition NOTIFY positionChanged)
+ Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged)
+ Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
+ Q_PROPERTY(bool hasAudio READ hasAudio NOTIFY hasAudioChanged)
+ Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged)
+ Q_PROPERTY(int bufferProgress READ bufferProgress NOTIFY bufferProgressChanged)
+ Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged)
+ Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged)
+ Q_PROPERTY(Error error READ error NOTIFY errorChanged)
+ Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
+ Q_PROPERTY(QDeclarativeMediaMetaData *metaData READ metaData CONSTANT)
+ Q_PROPERTY(QObject *mediaObject READ mediaObject NOTIFY mediaObjectChanged SCRIPTABLE false DESIGNABLE false)
+ Q_ENUMS(Status)
+ Q_ENUMS(Error)
+ Q_ENUMS(Loop)
+ Q_INTERFACES(QDeclarativeParserStatus)
+public:
+ enum Status
+ {
+ UnknownStatus = QMediaPlayer::UnknownMediaStatus,
+ NoMedia = QMediaPlayer::NoMedia,
+ Loading = QMediaPlayer::LoadingMedia,
+ Loaded = QMediaPlayer::LoadedMedia,
+ Stalled = QMediaPlayer::StalledMedia,
+ Buffering = QMediaPlayer::BufferingMedia,
+ Buffered = QMediaPlayer::BufferedMedia,
+ EndOfMedia = QMediaPlayer::EndOfMedia,
+ InvalidMedia = QMediaPlayer::InvalidMedia
+ };
+
+ enum Error
+ {
+ NoError = QMediaPlayer::NoError,
+ ResourceError = QMediaPlayer::ResourceError,
+ FormatError = QMediaPlayer::FormatError,
+ NetworkError = QMediaPlayer::NetworkError,
+ AccessDenied = QMediaPlayer::AccessDeniedError,
+ ServiceMissing = QMediaPlayer::ServiceMissingError
+ };
+
+ enum Loop
+ {
+ Infinite = QDeclarativeMediaBase_4::INFINITE
+ };
+
+ QDeclarativeAudio_4(QObject *parent = 0);
+ ~QDeclarativeAudio_4();
+
+ bool hasAudio() const;
+ bool hasVideo() const;
+
+ Status status() const;
+ Error error() const;
+
+ void classBegin();
+ void componentComplete();
+
+ QObject *mediaObject() { return m_mediaObject; }
+
+public Q_SLOTS:
+ void play();
+ void pause();
+ void stop();
+
+Q_SIGNALS:
+ void sourceChanged();
+ void autoLoadChanged();
+ void playingChanged();
+ void pausedChanged();
+ void loopCountChanged();
+
+ void started();
+ void resumed();
+ void paused();
+ void stopped();
+
+ void statusChanged();
+
+ void durationChanged();
+ void positionChanged();
+
+ void volumeChanged();
+ void mutedChanged();
+ void hasAudioChanged();
+ void hasVideoChanged();
+
+ void bufferProgressChanged();
+
+ void seekableChanged();
+ void playbackRateChanged();
+
+ void errorChanged();
+ void error(QDeclarativeAudio_4::Error error, const QString &errorString);
+
+ void mediaObjectChanged();
+
+private Q_SLOTS:
+ void _q_error(int, const QString &);
+
+private:
+ Q_DISABLE_COPY(QDeclarativeAudio_4)
+ Q_PRIVATE_SLOT(mediaBase(), void _q_statusChanged())
+
+ inline QDeclarativeMediaBase_4 *mediaBase() { return this; }
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeAudio_4))
+
+QT_END_HEADER
+
+#endif
diff --git a/src/imports/multimedia/qdeclarativemediabase.cpp b/src/imports/multimedia/qdeclarativemediabase.cpp
index 593afea3..a1f80f2b 100644
--- a/src/imports/multimedia/qdeclarativemediabase.cpp
+++ b/src/imports/multimedia/qdeclarativemediabase.cpp
@@ -130,7 +130,7 @@ protected:
if (event->timerId() == m_timer.timerId()) {
event->accept();
- if (m_media->m_playing && !m_media->m_paused)
+ if (m_media->m_playbackState == QMediaPlayer::PlayingState)
emit m_media->positionChanged();
if (m_media->m_status == QMediaPlayer::BufferingMedia || QMediaPlayer::StalledMedia)
emit m_media->bufferProgressChanged();
@@ -150,63 +150,40 @@ void QDeclarativeMediaBase::_q_statusChanged()
m_runningCount -= 1;
m_playerControl->play();
}
-
const QMediaPlayer::MediaStatus oldStatus = m_status;
- const bool wasPlaying = m_playing;
- const bool wasPaused = m_paused;
+ const QMediaPlayer::State lastPlaybackState = m_playbackState;
const QMediaPlayer::State state = m_playerControl->state();
- m_status = m_playerControl->mediaStatus();
-
- if (m_complete)
- m_playing = state != QMediaPlayer::StoppedState;
+ m_playbackState = state;
- if (state == QMediaPlayer::PausedState)
- m_paused = true;
- else if (state == QMediaPlayer::PlayingState)
- m_paused = false;
+ m_status = m_playerControl->mediaStatus();
if (m_status != oldStatus)
emit statusChanged();
- switch (state) {
- case QMediaPlayer::StoppedState:
- if (wasPlaying) {
- emit stopped();
+ if (lastPlaybackState != state) {
- if (!m_playing)
- emit playingChanged();
- }
- break;
- case QMediaPlayer::PausedState:
- if (!wasPlaying) {
- emit started();
- if (m_playing)
- emit playingChanged();
- }
- if ((!wasPaused || !wasPlaying) && m_paused)
+ if (lastPlaybackState == QMediaPlayer::StoppedState)
+ m_runningCount = m_loopCount - 1;
+
+ switch (state) {
+ case QMediaPlayer::StoppedState:
+ emit stopped();
+ break;
+ case QMediaPlayer::PausedState:
emit paused();
- if (!wasPaused && m_paused)
- emit pausedChanged();
-
- break;
-
- case QMediaPlayer::PlayingState:
- if (wasPaused && wasPlaying)
- emit resumed();
- else
- emit started();
-
- if (wasPaused && !m_paused)
- emit pausedChanged();
- if (!wasPlaying && m_playing)
- emit playingChanged();
- break;
+ break;
+ case QMediaPlayer::PlayingState:
+ emit playing();
+ break;
+ }
+
+ emit playbackStateChanged();
}
// Check
- if ((m_playing && !m_paused)
+ if ((state == QMediaPlayer::PlayingState)
|| m_status == QMediaPlayer::BufferingMedia
|| m_status == QMediaPlayer::StalledMedia) {
m_animation->start();
@@ -217,8 +194,7 @@ void QDeclarativeMediaBase::_q_statusChanged()
}
QDeclarativeMediaBase::QDeclarativeMediaBase()
- : m_paused(false)
- , m_playing(false)
+ : m_autoPlay(false)
, m_autoLoad(true)
, m_loaded(false)
, m_muted(false)
@@ -235,6 +211,7 @@ QDeclarativeMediaBase::QDeclarativeMediaBase()
, m_mediaProvider(0)
, m_metaDataControl(0)
, m_animation(0)
+ , m_playbackState(QMediaPlayer::StoppedState)
, m_status(QMediaPlayer::NoMedia)
, m_error(QMediaPlayer::ServiceMissingError)
{
@@ -319,21 +296,18 @@ void QDeclarativeMediaBase::componentComplete()
if (!qFuzzyCompare(m_playbackRate, qreal(1.0)))
m_playerControl->setPlaybackRate(m_playbackRate);
- if (!m_source.isEmpty() && (m_autoLoad || m_playing)) // Override autoLoad if playing set
+ if (!m_source.isEmpty() && (m_autoLoad || m_autoPlay)) {
m_playerControl->setMedia(m_source, 0);
-
- m_complete = true;
-
- if (m_playing) {
+ m_loaded = true;
if (m_position > 0)
m_playerControl->setPosition(m_position);
+ }
- if (m_source.isEmpty()) {
- m_playing = false;
+ m_complete = true;
- emit playingChanged();
- } else if (m_paused) {
- m_playerControl->pause();
+ if (m_autoPlay) {
+ if (m_source.isEmpty()) {
+ m_playerControl->stop();
} else {
m_playerControl->play();
}
@@ -347,6 +321,21 @@ QUrl QDeclarativeMediaBase::source() const
return m_source;
}
+bool QDeclarativeMediaBase::autoPlay() const
+{
+ return m_autoPlay;
+}
+
+void QDeclarativeMediaBase::setAutoPlay(bool autoplay)
+{
+ if (m_autoPlay == autoplay)
+ return;
+
+ m_autoPlay = autoplay;
+ emit autoPlayChanged();
+}
+
+
void QDeclarativeMediaBase::setSource(const QUrl &url)
{
if (url == m_source)
@@ -354,7 +343,7 @@ void QDeclarativeMediaBase::setSource(const QUrl &url)
m_source = url;
m_loaded = false;
- if (m_complete && (m_autoLoad || url.isEmpty())) {
+ if (m_complete && (m_autoLoad || url.isEmpty() || m_autoPlay)) {
if (m_error != QMediaPlayer::ServiceMissingError && m_error != QMediaPlayer::NoError) {
m_error = QMediaPlayer::NoError;
m_errorString = QString();
@@ -367,6 +356,8 @@ void QDeclarativeMediaBase::setSource(const QUrl &url)
}
else
emit sourceChanged();
+
+ if (m_autoPlay) m_playerControl->play();
}
bool QDeclarativeMediaBase::isAutoLoad() const
@@ -399,68 +390,46 @@ void QDeclarativeMediaBase::setLoopCount(int loopCount)
return;
}
m_loopCount = loopCount;
+ m_runningCount = loopCount - 1;
emit loopCountChanged();
}
-bool QDeclarativeMediaBase::isPlaying() const
-{
- return m_playing;
-}
-
-void QDeclarativeMediaBase::setPlaying(bool playing)
+void QDeclarativeMediaBase::setPlaybackState(QMediaPlayer::State playbackState)
{
- if (playing == m_playing)
+ if (m_playbackState == playbackState)
return;
if (m_complete) {
- if (playing) {
- if (!m_autoLoad && !m_loaded) {
+ switch (playbackState){
+ case (QMediaPlayer::PlayingState):
+ if (!m_loaded) {
m_playerControl->setMedia(m_source, 0);
m_playerControl->setPosition(m_position);
m_loaded = true;
}
+ m_playerControl->play();
+ break;
- m_runningCount = m_loopCount - 1;
+ case (QMediaPlayer::PausedState):
+ if (!m_loaded) {
+ m_playerControl->setMedia(m_source, 0);
+ m_playerControl->setPosition(m_position);
+ m_loaded = true;
+ }
+ m_playerControl->pause();
+ break;
- if (!m_paused)
- m_playerControl->play();
- else
- m_playerControl->pause();
- } else {
+ case (QMediaPlayer::StoppedState):
m_playerControl->stop();
}
- } else {
- m_playing = playing;
- emit playingChanged();
}
}
-bool QDeclarativeMediaBase::isPaused() const
+QMediaPlayer::State QDeclarativeMediaBase::playbackState() const
{
- return m_paused;
+ return m_playbackState;
}
-void QDeclarativeMediaBase::setPaused(bool paused)
-{
- if (m_paused == paused)
- return;
-
- if (m_complete && m_playing) {
- if (!m_autoLoad && !m_loaded) {
- m_playerControl->setMedia(m_source, 0);
- m_playerControl->setPosition(m_position);
- m_loaded = true;
- }
-
- if (!paused)
- m_playerControl->play();
- else
- m_playerControl->pause();
- } else {
- m_paused = paused;
- emit pausedChanged();
- }
-}
int QDeclarativeMediaBase::duration() const
{
diff --git a/src/imports/multimedia/qdeclarativemediabase_4.cpp b/src/imports/multimedia/qdeclarativemediabase_4.cpp
new file mode 100644
index 00000000..dee5c0c4
--- /dev/null
+++ b/src/imports/multimedia/qdeclarativemediabase_4.cpp
@@ -0,0 +1,567 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdeclarativemediabase_p_4.h"
+
+#include <QtCore/qcoreevent.h>
+#include <QtCore/qurl.h>
+#include <QtDeclarative/qdeclarativeinfo.h>
+
+#include <qmediaplayercontrol.h>
+#include <qmediaservice.h>
+#include <private/qmediaserviceprovider_p.h>
+#include <qmetadatareadercontrol.h>
+
+#include "qdeclarativemediametadata_p.h"
+
+QT_BEGIN_NAMESPACE
+
+
+class QDeclarativeMediaBaseObject : public QMediaObject
+{
+public:
+ QDeclarativeMediaBaseObject(QMediaService *service)
+ : QMediaObject(0, service)
+ {
+ }
+};
+
+class QDeclarativeMediaBasePlayerControl : public QMediaPlayerControl
+{
+public:
+ QDeclarativeMediaBasePlayerControl(QObject *parent)
+ : QMediaPlayerControl(parent)
+ {
+ }
+
+ QMediaPlayer::State state() const { return QMediaPlayer::StoppedState; }
+ QMediaPlayer::MediaStatus mediaStatus() const { return QMediaPlayer::NoMedia; }
+
+ qint64 duration() const { return 0; }
+ qint64 position() const { return 0; }
+ void setPosition(qint64) {}
+ int volume() const { return 0; }
+ void setVolume(int) {}
+ bool isMuted() const { return false; }
+ void setMuted(bool) {}
+ int bufferStatus() const { return 0; }
+ bool isAudioAvailable() const { return false; }
+ bool isVideoAvailable() const { return false; }
+ bool isSeekable() const { return false; }
+ QMediaTimeRange availablePlaybackRanges() const { return QMediaTimeRange(); }
+ qreal playbackRate() const { return 1; }
+ void setPlaybackRate(qreal) {}
+ QMediaContent media() const { return QMediaContent(); }
+ const QIODevice *mediaStream() const { return 0; }
+ void setMedia(const QMediaContent &, QIODevice *) {}
+
+ void play() {}
+ void pause() {}
+ void stop() {}
+};
+
+
+class QDeclarativeMediaBaseMetaDataControl : public QMetaDataReaderControl
+{
+public:
+ QDeclarativeMediaBaseMetaDataControl(QObject *parent)
+ : QMetaDataReaderControl(parent)
+ {
+ }
+
+ bool isMetaDataAvailable() const { return false; }
+
+ QVariant metaData(const QString &) const { return QVariant(); }
+ QStringList availableMetaData() const { return QStringList(); }
+};
+
+class QDeclarativeMediaBaseAnimation : public QObject
+{
+public:
+ QDeclarativeMediaBaseAnimation(QDeclarativeMediaBase_4 *media)
+ : m_media(media)
+ {
+ }
+
+ void start() { if (!m_timer.isActive()) m_timer.start(500, this); }
+ void stop() { m_timer.stop(); }
+
+protected:
+ void timerEvent(QTimerEvent *event)
+ {
+ if (event->timerId() == m_timer.timerId()) {
+ event->accept();
+
+ if (m_media->m_playing && !m_media->m_paused)
+ emit m_media->positionChanged();
+ if (m_media->m_status == QMediaPlayer::BufferingMedia || QMediaPlayer::StalledMedia)
+ emit m_media->bufferProgressChanged();
+ } else {
+ QObject::timerEvent(event);
+ }
+ }
+
+private:
+ QDeclarativeMediaBase_4 *m_media;
+ QBasicTimer m_timer;
+};
+
+void QDeclarativeMediaBase_4::_q_statusChanged()
+{
+ if (m_playerControl->mediaStatus() == QMediaPlayer::EndOfMedia && m_runningCount != 0) {
+ m_runningCount -= 1;
+ m_playerControl->play();
+ }
+
+ const QMediaPlayer::MediaStatus oldStatus = m_status;
+ const bool wasPlaying = m_playing;
+ const bool wasPaused = m_paused;
+
+ const QMediaPlayer::State state = m_playerControl->state();
+
+ m_status = m_playerControl->mediaStatus();
+
+ if (m_complete)
+ m_playing = state != QMediaPlayer::StoppedState;
+
+ if (state == QMediaPlayer::PausedState)
+ m_paused = true;
+ else if (state == QMediaPlayer::PlayingState)
+ m_paused = false;
+
+ if (m_status != oldStatus)
+ emit statusChanged();
+
+ switch (state) {
+ case QMediaPlayer::StoppedState:
+ if (wasPlaying) {
+ emit stopped();
+
+ if (!m_playing)
+ emit playingChanged();
+ }
+ break;
+ case QMediaPlayer::PausedState:
+ if (!wasPlaying) {
+ emit started();
+ if (m_playing)
+ emit playingChanged();
+ }
+ if ((!wasPaused || !wasPlaying) && m_paused)
+ emit paused();
+ if (!wasPaused && m_paused)
+ emit pausedChanged();
+
+ break;
+
+ case QMediaPlayer::PlayingState:
+ if (wasPaused && wasPlaying)
+ emit resumed();
+ else
+ emit started();
+
+ if (wasPaused && !m_paused)
+ emit pausedChanged();
+ if (!wasPlaying && m_playing)
+ emit playingChanged();
+ break;
+ }
+
+ // Check
+ if ((m_playing && !m_paused)
+ || m_status == QMediaPlayer::BufferingMedia
+ || m_status == QMediaPlayer::StalledMedia) {
+ m_animation->start();
+ }
+ else {
+ m_animation->stop();
+ }
+}
+
+QDeclarativeMediaBase_4::QDeclarativeMediaBase_4()
+ : m_paused(false)
+ , m_playing(false)
+ , m_autoLoad(true)
+ , m_loaded(false)
+ , m_muted(false)
+ , m_complete(false)
+ , m_loopCount(1)
+ , m_runningCount(0)
+ , m_position(0)
+ , m_vol(1.0)
+ , m_playbackRate(1.0)
+ , m_mediaService(0)
+ , m_playerControl(0)
+ , m_qmlObject(0)
+ , m_mediaObject(0)
+ , m_mediaProvider(0)
+ , m_metaDataControl(0)
+ , m_animation(0)
+ , m_status(QMediaPlayer::NoMedia)
+ , m_error(QMediaPlayer::ServiceMissingError)
+{
+}
+
+QDeclarativeMediaBase_4::~QDeclarativeMediaBase_4()
+{
+}
+
+void QDeclarativeMediaBase_4::shutdown()
+{
+ delete m_mediaObject;
+ m_metaData.reset();
+
+ if (m_mediaProvider)
+ m_mediaProvider->releaseService(m_mediaService);
+
+ delete m_animation;
+
+}
+
+void QDeclarativeMediaBase_4::setObject(QObject *object, const QByteArray &type)
+{
+ m_qmlObject = object;
+
+ if ((m_mediaProvider = QMediaServiceProvider::defaultServiceProvider()) != 0) {
+ m_mediaService = m_mediaProvider->requestService(type);
+ if (m_mediaService != 0) {
+ m_playerControl = qobject_cast<QMediaPlayerControl *>(
+ m_mediaService->requestControl(QMediaPlayerControl_iid));
+ m_metaDataControl = qobject_cast<QMetaDataReaderControl *>(
+ m_mediaService->requestControl(QMetaDataReaderControl_iid));
+ m_mediaObject = new QDeclarativeMediaBaseObject(m_mediaService);
+ }
+ }
+
+ if (m_playerControl) {
+ QObject::connect(m_playerControl, SIGNAL(stateChanged(QMediaPlayer::State)),
+ object, SLOT(_q_statusChanged()));
+ QObject::connect(m_playerControl, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
+ object, SLOT(_q_statusChanged()));
+ QObject::connect(m_playerControl, SIGNAL(mediaChanged(QMediaContent)),
+ object, SIGNAL(sourceChanged()));
+ QObject::connect(m_playerControl, SIGNAL(durationChanged(qint64)),
+ object, SIGNAL(durationChanged()));
+ QObject::connect(m_playerControl, SIGNAL(positionChanged(qint64)),
+ object, SIGNAL(positionChanged()));
+ QObject::connect(m_playerControl, SIGNAL(volumeChanged(int)),
+ object, SIGNAL(volumeChanged()));
+ QObject::connect(m_playerControl, SIGNAL(mutedChanged(bool)),
+ object, SIGNAL(mutedChanged()));
+ QObject::connect(m_playerControl, SIGNAL(bufferStatusChanged(int)),
+ object, SIGNAL(bufferProgressChanged()));
+ QObject::connect(m_playerControl, SIGNAL(seekableChanged(bool)),
+ object, SIGNAL(seekableChanged()));
+ QObject::connect(m_playerControl, SIGNAL(playbackRateChanged(qreal)),
+ object, SIGNAL(playbackRateChanged()));
+ QObject::connect(m_playerControl, SIGNAL(error(int,QString)),
+ object, SLOT(_q_error(int,QString)));
+
+ m_animation = new QDeclarativeMediaBaseAnimation(this);
+ m_error = QMediaPlayer::NoError;
+ } else {
+ m_playerControl = new QDeclarativeMediaBasePlayerControl(object);
+ }
+
+ if (!m_metaDataControl)
+ m_metaDataControl = new QDeclarativeMediaBaseMetaDataControl(object);
+
+ m_metaData.reset(new QDeclarativeMediaMetaData(m_metaDataControl));
+
+ QObject::connect(m_metaDataControl, SIGNAL(metaDataChanged()),
+ m_metaData.data(), SIGNAL(metaDataChanged()));
+}
+
+void QDeclarativeMediaBase_4::componentComplete()
+{
+ if (!qFuzzyCompare(m_vol, qreal(1.0)))
+ m_playerControl->setVolume(m_vol * 100);
+ if (m_muted)
+ m_playerControl->setMuted(m_muted);
+ if (!qFuzzyCompare(m_playbackRate, qreal(1.0)))
+ m_playerControl->setPlaybackRate(m_playbackRate);
+
+ if (!m_source.isEmpty() && (m_autoLoad || m_playing)) // Override autoLoad if playing set
+ m_playerControl->setMedia(m_source, 0);
+
+ m_complete = true;
+
+ if (m_playing) {
+ if (m_position > 0)
+ m_playerControl->setPosition(m_position);
+
+ if (m_source.isEmpty()) {
+ m_playing = false;
+
+ emit playingChanged();
+ } else if (m_paused) {
+ m_playerControl->pause();
+ } else {
+ m_playerControl->play();
+ }
+ }
+}
+
+// Properties
+
+QUrl QDeclarativeMediaBase_4::source() const
+{
+ return m_source;
+}
+
+void QDeclarativeMediaBase_4::setSource(const QUrl &url)
+{
+ if (url == m_source)
+ return;
+
+ m_source = url;
+ m_loaded = false;
+ if (m_complete && (m_autoLoad || url.isEmpty())) {
+ if (m_error != QMediaPlayer::ServiceMissingError && m_error != QMediaPlayer::NoError) {
+ m_error = QMediaPlayer::NoError;
+ m_errorString = QString();
+
+ emit errorChanged();
+ }
+
+ m_playerControl->setMedia(m_source, 0);
+ m_loaded = true;
+ }
+ else
+ emit sourceChanged();
+}
+
+bool QDeclarativeMediaBase_4::isAutoLoad() const
+{
+ return m_autoLoad;
+}
+
+void QDeclarativeMediaBase_4::setAutoLoad(bool autoLoad)
+{
+ if (m_autoLoad == autoLoad)
+ return;
+
+ m_autoLoad = autoLoad;
+ emit autoLoadChanged();
+}
+
+int QDeclarativeMediaBase_4::loopCount() const
+{
+ return m_loopCount;
+}
+
+void QDeclarativeMediaBase_4::setLoopCount(int loopCount)
+{
+ if (loopCount == 0)
+ loopCount = 1;
+ else if (loopCount < -1)
+ loopCount = -1;
+
+ if (m_loopCount == loopCount) {
+ return;
+ }
+ m_loopCount = loopCount;
+ emit loopCountChanged();
+}
+
+bool QDeclarativeMediaBase_4::isPlaying() const
+{
+ return m_playing;
+}
+
+void QDeclarativeMediaBase_4::setPlaying(bool playing)
+{
+ if (playing == m_playing)
+ return;
+
+ if (m_complete) {
+ if (playing) {
+ if (!m_autoLoad && !m_loaded) {
+ m_playerControl->setMedia(m_source, 0);
+ m_playerControl->setPosition(m_position);
+ m_loaded = true;
+ }
+
+ m_runningCount = m_loopCount - 1;
+
+ if (!m_paused)
+ m_playerControl->play();
+ else
+ m_playerControl->pause();
+ } else {
+ m_playerControl->stop();
+ }
+ } else {
+ m_playing = playing;
+ emit playingChanged();
+ }
+}
+
+bool QDeclarativeMediaBase_4::isPaused() const
+{
+ return m_paused;
+}
+
+void QDeclarativeMediaBase_4::setPaused(bool paused)
+{
+ if (m_paused == paused)
+ return;
+
+ if (m_complete && m_playing) {
+ if (!m_autoLoad && !m_loaded) {
+ m_playerControl->setMedia(m_source, 0);
+ m_playerControl->setPosition(m_position);
+ m_loaded = true;
+ }
+
+ if (!paused)
+ m_playerControl->play();
+ else
+ m_playerControl->pause();
+ } else {
+ m_paused = paused;
+ emit pausedChanged();
+ }
+}
+
+int QDeclarativeMediaBase_4::duration() const
+{
+ return !m_complete ? 0 : m_playerControl->duration();
+}
+
+int QDeclarativeMediaBase_4::position() const
+{
+ return !m_complete ? m_position : m_playerControl->position();
+}
+
+void QDeclarativeMediaBase_4::setPosition(int position)
+{
+ if (this->position() == position)
+ return;
+
+ m_position = position;
+ if (m_complete)
+ m_playerControl->setPosition(m_position);
+ else
+ emit positionChanged();
+}
+
+qreal QDeclarativeMediaBase_4::volume() const
+{
+ return !m_complete ? m_vol : qreal(m_playerControl->volume()) / 100;
+}
+
+void QDeclarativeMediaBase_4::setVolume(qreal volume)
+{
+ if (volume < 0 || volume > 1) {
+ qmlInfo(m_qmlObject) << m_qmlObject->tr("volume should be between 0.0 and 1.0");
+ return;
+ }
+
+ if (m_vol == volume)
+ return;
+
+ m_vol = volume;
+
+ if (m_complete)
+ m_playerControl->setVolume(qRound(volume * 100));
+ else
+ emit volumeChanged();
+}
+
+bool QDeclarativeMediaBase_4::isMuted() const
+{
+ return !m_complete ? m_muted : m_playerControl->isMuted();
+}
+
+void QDeclarativeMediaBase_4::setMuted(bool muted)
+{
+ if (m_muted == muted)
+ return;
+
+ m_muted = muted;
+
+ if (m_complete)
+ m_playerControl->setMuted(muted);
+ else
+ emit mutedChanged();
+}
+
+qreal QDeclarativeMediaBase_4::bufferProgress() const
+{
+ return !m_complete ? 0 : qreal(m_playerControl->bufferStatus()) / 100;
+}
+
+bool QDeclarativeMediaBase_4::isSeekable() const
+{
+ return !m_complete ? false : m_playerControl->isSeekable();
+}
+
+qreal QDeclarativeMediaBase_4::playbackRate() const
+{
+ return m_playbackRate;
+}
+
+void QDeclarativeMediaBase_4::setPlaybackRate(qreal rate)
+{
+ if (m_playbackRate == rate)
+ return;
+
+ m_playbackRate = rate;
+
+ if (m_complete)
+ m_playerControl->setPlaybackRate(m_playbackRate);
+ else
+ emit playbackRateChanged();
+}
+
+QString QDeclarativeMediaBase_4::errorString() const
+{
+ return m_errorString;
+}
+
+QDeclarativeMediaMetaData *QDeclarativeMediaBase_4::metaData() const
+{
+ return m_metaData.data();
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/imports/multimedia/qdeclarativemediabase_p.h b/src/imports/multimedia/qdeclarativemediabase_p.h
index 9df5db1c..78c3524e 100644
--- a/src/imports/multimedia/qdeclarativemediabase_p.h
+++ b/src/imports/multimedia/qdeclarativemediabase_p.h
@@ -81,17 +81,11 @@ public:
QUrl source() const;
void setSource(const QUrl &url);
- bool isAutoLoad() const;
- void setAutoLoad(bool autoLoad);
-
int loopCount() const;
void setLoopCount(int loopCount);
- bool isPlaying() const;
- void setPlaying(bool playing);
-
- bool isPaused() const;
- void setPaused(bool paused);
+ QMediaPlayer::State playbackState() const;
+ void setPlaybackState(QMediaPlayer::State playbackState);
int duration() const;
@@ -121,21 +115,27 @@ public:
void componentComplete();
+ bool isAutoLoad() const;
+ void setAutoLoad(bool autoLoad);
+
+ bool autoPlay() const;
+ void setAutoPlay(bool autoplay);
+
protected:
void shutdown();
void setObject(QObject *object, const QByteArray &type = Q_MEDIASERVICE_MEDIAPLAYER);
virtual void sourceChanged() = 0;
- virtual void autoLoadChanged() = 0;
- virtual void playingChanged() = 0;
- virtual void pausedChanged() = 0;
virtual void loopCountChanged() = 0;
- virtual void started() = 0;
- virtual void resumed() = 0;
virtual void paused() = 0;
virtual void stopped() = 0;
+ virtual void playing() = 0;
+
+ virtual void autoLoadChanged() = 0;
+
+ virtual void playbackStateChanged() = 0;
virtual void statusChanged() = 0;
@@ -152,8 +152,9 @@ protected:
virtual void errorChanged() = 0;
- bool m_paused;
- bool m_playing;
+ virtual void autoPlayChanged() = 0;
+
+ bool m_autoPlay;
bool m_autoLoad;
bool m_loaded;
bool m_muted;
@@ -173,6 +174,7 @@ protected:
QDeclarativeMediaBaseAnimation *m_animation;
QScopedPointer<QDeclarativeMediaMetaData> m_metaData;
+ QMediaPlayer::State m_playbackState;
QMediaPlayer::MediaStatus m_status;
QMediaPlayer::Error m_error;
QString m_errorString;
diff --git a/src/imports/multimedia/qdeclarativemediabase_p_4.h b/src/imports/multimedia/qdeclarativemediabase_p_4.h
new file mode 100644
index 00000000..fab555b9
--- /dev/null
+++ b/src/imports/multimedia/qdeclarativemediabase_p_4.h
@@ -0,0 +1,188 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLARATIVEMEDIABASE_4_P_H
+#define QDECLARATIVEMEDIABASE_4_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qbasictimer.h>
+#include <qmediaplayer.h>
+#include <private/qmediaserviceprovider_p.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QMediaPlayerControl;
+class QMediaService;
+class QMediaServiceProvider;
+class QMetaDataReaderControl;
+class QDeclarativeMediaBaseAnimation;
+class QDeclarativeMediaMetaData;
+
+class QDeclarativeMediaBase_4
+{
+public:
+ enum Loop {
+ INFINITE = -1
+ };
+
+ QDeclarativeMediaBase_4();
+ virtual ~QDeclarativeMediaBase_4();
+
+ QUrl source() const;
+ void setSource(const QUrl &url);
+
+ bool isAutoLoad() const;
+ void setAutoLoad(bool autoLoad);
+
+ int loopCount() const;
+ void setLoopCount(int loopCount);
+
+ bool isPlaying() const;
+ void setPlaying(bool playing);
+
+ bool isPaused() const;
+ void setPaused(bool paused);
+
+ int duration() const;
+
+ int position() const;
+ void setPosition(int position);
+
+ qreal volume() const;
+ void setVolume(qreal volume);
+
+ bool isMuted() const;
+ void setMuted(bool muted);
+
+ qreal bufferProgress() const;
+
+ bool isSeekable() const;
+
+ qreal playbackRate() const;
+ void setPlaybackRate(qreal rate);
+
+ QString errorString() const;
+
+ QDeclarativeMediaMetaData *metaData() const;
+
+ void _q_statusChanged();
+
+ void _q_metaDataChanged();
+
+ void componentComplete();
+
+protected:
+ void shutdown();
+
+ void setObject(QObject *object, const QByteArray &type = Q_MEDIASERVICE_MEDIAPLAYER);
+
+ virtual void sourceChanged() = 0;
+ virtual void autoLoadChanged() = 0;
+ virtual void playingChanged() = 0;
+ virtual void pausedChanged() = 0;
+ virtual void loopCountChanged() = 0;
+
+ virtual void started() = 0;
+ virtual void resumed() = 0;
+ virtual void paused() = 0;
+ virtual void stopped() = 0;
+
+ virtual void statusChanged() = 0;
+
+ virtual void durationChanged() = 0;
+ virtual void positionChanged() = 0;
+
+ virtual void volumeChanged() = 0;
+ virtual void mutedChanged() = 0;
+
+ virtual void bufferProgressChanged() = 0;
+
+ virtual void seekableChanged() = 0;
+ virtual void playbackRateChanged() = 0;
+
+ virtual void errorChanged() = 0;
+
+ bool m_paused;
+ bool m_playing;
+ bool m_autoLoad;
+ bool m_loaded;
+ bool m_muted;
+ bool m_complete;
+ int m_loopCount;
+ int m_runningCount;
+ int m_position;
+ qreal m_vol;
+ qreal m_playbackRate;
+ QMediaService *m_mediaService;
+ QMediaPlayerControl *m_playerControl;
+
+ QObject *m_qmlObject;
+ QMediaObject *m_mediaObject;
+ QMediaServiceProvider *m_mediaProvider;
+ QMetaDataReaderControl *m_metaDataControl;
+ QDeclarativeMediaBaseAnimation *m_animation;
+ QScopedPointer<QDeclarativeMediaMetaData> m_metaData;
+
+ QMediaPlayer::MediaStatus m_status;
+ QMediaPlayer::Error m_error;
+ QString m_errorString;
+ QUrl m_source;
+
+ friend class QDeclarativeMediaBaseAnimation;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/imports/multimedia/qmldir b/src/imports/multimedia/qmldir
index 369d6a65..739b33f6 100644
--- a/src/imports/multimedia/qmldir
+++ b/src/imports/multimedia/qmldir
@@ -1,2 +1,3 @@
plugin declarative_multimedia
Video 5.0 Video.qml
+Video 4.0 Video_4.qml
diff --git a/tests/auto/unit/multimedia.pro b/tests/auto/unit/multimedia.pro
index a662d441..ee5dba82 100644
--- a/tests/auto/unit/multimedia.pro
+++ b/tests/auto/unit/multimedia.pro
@@ -29,12 +29,6 @@ SUBDIRS += \
qvideoframe \
qvideosurfaceformat \
qwavedecoder \
- qaudiobuffer
-
-# Tests depending on private interfaces should only be built if
-# these interfaces are exported.
-contains (QT_CONFIG, private_tests) {
- SUBDIRS += \
- qdeclarativeaudio
-}
-
+ qaudiobuffer \
+ qdeclarativeaudio \
+ qdeclarativeaudio_4
diff --git a/tests/auto/unit/qdeclarativeaudio/tst_qdeclarativeaudio.cpp b/tests/auto/unit/qdeclarativeaudio/tst_qdeclarativeaudio.cpp
index 4176604b..57f0dd10 100644
--- a/tests/auto/unit/qdeclarativeaudio/tst_qdeclarativeaudio.cpp
+++ b/tests/auto/unit/qdeclarativeaudio/tst_qdeclarativeaudio.cpp
@@ -306,18 +306,11 @@ void tst_QDeclarativeAudio::nullPlayerControl()
audio.setSource(QUrl("http://example.com"));
QCOMPARE(audio.source(), QUrl("http://example.com"));
- QCOMPARE(audio.isPlaying(), false);
- audio.setPlaying(true);
- QCOMPARE(audio.isPlaying(), true);
- audio.setPlaying(false);
+ QCOMPARE(audio.playbackState(), audio.StoppedState);
audio.play();
- QCOMPARE(audio.isPlaying(), false);
-
- QCOMPARE(audio.isPaused(), false);
+ QCOMPARE(audio.playbackState(), audio.StoppedState);
audio.pause();
- QCOMPARE(audio.isPaused(), false);
- audio.setPaused(true);
- QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(audio.playbackState(), audio.StoppedState);
QCOMPARE(audio.duration(), 0);
@@ -367,18 +360,11 @@ void tst_QDeclarativeAudio::nullService()
audio.setSource(QUrl("http://example.com"));
QCOMPARE(audio.source(), QUrl("http://example.com"));
- QCOMPARE(audio.isPlaying(), false);
- audio.setPlaying(true);
- QCOMPARE(audio.isPlaying(), true);
- audio.setPlaying(false);
+ QCOMPARE(audio.playbackState(), audio.StoppedState);
audio.play();
- QCOMPARE(audio.isPlaying(), false);
-
- QCOMPARE(audio.isPaused(), false);
+ QCOMPARE(audio.playbackState(), audio.StoppedState);
audio.pause();
- QCOMPARE(audio.isPaused(), false);
- audio.setPaused(true);
- QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(audio.playbackState(), audio.StoppedState);
QCOMPARE(audio.duration(), 0);
@@ -454,14 +440,14 @@ void tst_QDeclarativeAudio::autoLoad()
audio.setSource(QUrl("http://example.com"));
QCOMPARE(audio.source(), QUrl("http://example.com"));
audio.play();
- QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.playbackState(), audio.PlayingState);
audio.stop();
audio.setAutoLoad(true);
audio.setSource(QUrl("http://example.com"));
- audio.setPaused(true);
+ audio.pause();
QCOMPARE(spy.count(), 2);
- QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(audio.playbackState(), audio.PausedState);
}
void tst_QDeclarativeAudio::playing()
@@ -470,88 +456,56 @@ void tst_QDeclarativeAudio::playing()
QDeclarativeAudio audio;
audio.classBegin();
- QSignalSpy playingChangedSpy(&audio, SIGNAL(playingChanged()));
- QSignalSpy startedSpy(&audio, SIGNAL(started()));
+ QSignalSpy stateChangedSpy(&audio, SIGNAL(playbackStateChanged()));
+ QSignalSpy playingSpy(&audio, SIGNAL(playing()));
QSignalSpy stoppedSpy(&audio, SIGNAL(stopped()));
- int playingChanged = 0;
- int started = 0;
+ int stateChanged = 0;
+ int playing = 0;
int stopped = 0;
audio.componentComplete();
audio.setSource(QUrl("http://example.com"));
- QCOMPARE(audio.isPlaying(), false);
-
- // setPlaying(true) when stopped.
- audio.setPlaying(true);
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(startedSpy.count(), ++started);
- QCOMPARE(stoppedSpy.count(), stopped);
-
- // setPlaying(false) when playing.
- audio.setPlaying(false);
- QCOMPARE(audio.isPlaying(), false);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(stoppedSpy.count(), ++stopped);
+ QCOMPARE(audio.playbackState(), audio.StoppedState);
// play() when stopped.
audio.play();
- QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.playbackState(), audio.PlayingState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(startedSpy.count(), ++started);
+ QCOMPARE(stateChangedSpy.count(), ++stateChanged);
+ QCOMPARE(playingSpy.count(), ++playing);
QCOMPARE(stoppedSpy.count(), stopped);
// stop() when playing.
audio.stop();
- QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(audio.playbackState(), audio.StoppedState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(stateChangedSpy.count(), ++stateChanged);
+ QCOMPARE(playingSpy.count(), playing);
QCOMPARE(stoppedSpy.count(), ++stopped);
// stop() when stopped.
audio.stop();
- QCOMPARE(audio.isPlaying(), false);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(stoppedSpy.count(), stopped);
-
- // setPlaying(false) when stopped.
- audio.setPlaying(false);
- QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(audio.playbackState(), audio.StoppedState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(stateChangedSpy.count(), stateChanged);
+ QCOMPARE(playingSpy.count(), playing);
QCOMPARE(stoppedSpy.count(), stopped);
- audio.setPlaying(true);
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(startedSpy.count(), ++started);
- QCOMPARE(stoppedSpy.count(), stopped);
-
- // setPlaying(true) when playing.
- audio.setPlaying(true);
- QCOMPARE(audio.isPlaying(), true);
+ audio.play();
+ QCOMPARE(audio.playbackState(), audio.PlayingState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(stateChangedSpy.count(), ++stateChanged);
+ QCOMPARE(playingSpy.count(), ++playing);
QCOMPARE(stoppedSpy.count(), stopped);
// play() when playing.
audio.play();
- QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.playbackState(), audio.PlayingState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(stateChangedSpy.count(), stateChanged);
+ QCOMPARE(playingSpy.count(), playing);
QCOMPARE(stoppedSpy.count(), stopped);
}
@@ -561,289 +515,57 @@ void tst_QDeclarativeAudio::paused()
QDeclarativeAudio audio;
audio.classBegin();
- QSignalSpy playingChangedSpy(&audio, SIGNAL(playingChanged()));
- QSignalSpy pausedChangedSpy(&audio, SIGNAL(pausedChanged()));
- QSignalSpy startedSpy(&audio, SIGNAL(started()));
+ QSignalSpy stateChangedSpy(&audio, SIGNAL(playbackStateChanged()));
QSignalSpy pausedSpy(&audio, SIGNAL(paused()));
- QSignalSpy resumedSpy(&audio, SIGNAL(resumed()));
- QSignalSpy stoppedSpy(&audio, SIGNAL(stopped()));
-
- int playingChanged = 0;
- int pausedChanged = 0;
- int started = 0;
- int paused = 0;
- int resumed = 0;
- int stopped = 0;
+ int stateChanged = 0;
+ int pausedCount = 0;
audio.componentComplete();
audio.setSource(QUrl("http://example.com"));
- QCOMPARE(audio.isPlaying(), false);
- QCOMPARE(audio.isPaused(), false);
-
- // setPlaying(true) when stopped.
- audio.setPlaying(true);
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(audio.isPaused(), false);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(pausedChangedSpy.count(), pausedChanged);
- QCOMPARE(startedSpy.count(), ++started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
-
- // setPaused(true) when playing.
- audio.setPaused(true);
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(audio.isPaused(), true);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), ++paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
-
- // setPaused(true) when paused.
- audio.setPaused(true);
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(audio.isPaused(), true);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(pausedChangedSpy.count(), pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
+ QCOMPARE(audio.playbackState(), audio.StoppedState);
- // pause() when paused.
- audio.pause();
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(audio.isPaused(), true);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(pausedChangedSpy.count(), pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
-
- // setPaused(false) when paused.
- audio.setPaused(false);
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(audio.isPaused(), false);
+ // play() when stopped.
+ audio.play();
+ QCOMPARE(audio.playbackState(), audio.PlayingState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), ++resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
-
- // setPaused(false) when playing.
- audio.setPaused(false);
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(audio.isPaused(), false);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(pausedChangedSpy.count(), pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
+ QCOMPARE(stateChangedSpy.count(), ++stateChanged);
+ QCOMPARE(pausedSpy.count(), pausedCount);
// pause() when playing.
audio.pause();
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(audio.playbackState(), audio.PausedState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), ++paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
-
- // setPlaying(false) when paused.
- audio.setPlaying(false);
- QCOMPARE(audio.isPlaying(), false);
- QCOMPARE(audio.isPaused(), true);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(pausedChangedSpy.count(), pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), ++stopped);
-
- // setPaused(true) when stopped and paused.
- audio.setPaused(true);
- QCOMPARE(audio.isPlaying(), false);
- QCOMPARE(audio.isPaused(), true);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(pausedChangedSpy.count(), pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
-
- // setPaused(false) when stopped and paused.
- audio.setPaused(false);
- QCOMPARE(audio.isPlaying(), false);
- QCOMPARE(audio.isPaused(), false);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
+ QCOMPARE(stateChangedSpy.count(), ++stateChanged);
+ QCOMPARE(pausedSpy.count(), ++pausedCount);
- // setPaused(true) when stopped.
- audio.setPaused(true);
- QCOMPARE(audio.isPlaying(), false);
- QCOMPARE(audio.isPaused(), true);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
-
- // setPlaying(true) when stopped and paused.
- audio.setPlaying(true);
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(audio.isPaused(), true);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(pausedChangedSpy.count(), pausedChanged);
- QCOMPARE(startedSpy.count(), ++started);
- QCOMPARE(pausedSpy.count(), ++paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
-
- // play() when paused.
- audio.play();
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(audio.isPaused(), false);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), ++resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
-
- // setPaused(true) when playing.
- audio.setPaused(true);
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(audio.isPaused(), true);
+ // pause() when paused.
+ audio.pause();
+ QCOMPARE(audio.playbackState(), audio.PausedState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), ++paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
+ QCOMPARE(stateChangedSpy.count(), stateChanged);
+ QCOMPARE(pausedSpy.count(), pausedCount);
// stop() when paused.
audio.stop();
- QCOMPARE(audio.isPlaying(), false);
- QCOMPARE(audio.isPaused(), false);
+ QCOMPARE(audio.playbackState(), audio.StoppedState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), ++stopped);
-
- // setPaused(true) when stopped.
- audio.setPaused(true);
- QCOMPARE(audio.isPlaying(), false);
- QCOMPARE(audio.isPaused(), true);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
-
- // stop() when stopped and paused.
- audio.stop();
- QCOMPARE(audio.isPlaying(), false);
- QCOMPARE(audio.isPaused(), false);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
+ QCOMPARE(stateChangedSpy.count(), ++stateChanged);
+ QCOMPARE(pausedSpy.count(), pausedCount);
// pause() when stopped.
audio.pause();
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(audio.playbackState(), audio.PausedState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
- QCOMPARE(startedSpy.count(), ++started);
- QCOMPARE(pausedSpy.count(), ++paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
-
- // setPlaying(false) when paused.
- audio.setPlaying(false);
- QCOMPARE(audio.isPlaying(), false);
- QCOMPARE(audio.isPaused(), true);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(pausedChangedSpy.count(), pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), ++stopped);
+ QCOMPARE(stateChangedSpy.count(), ++stateChanged);
+ QCOMPARE(pausedSpy.count(), ++pausedCount);
- // pause() when stopped and paused.
- audio.pause();
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(audio.isPaused(), true);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(pausedChangedSpy.count(), pausedChanged);
- QCOMPARE(startedSpy.count(), ++started);
- QCOMPARE(pausedSpy.count(), ++paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
-
- // setPlaying(false) when paused.
- audio.setPlaying(false);
- QCOMPARE(audio.isPlaying(), false);
- QCOMPARE(audio.isPaused(), true);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(pausedChangedSpy.count(), pausedChanged);
- QCOMPARE(startedSpy.count(), started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), ++stopped);
-
- // play() when stopped and paused.
+ // play() when paused.
audio.play();
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(audio.isPaused(), false);
+ QCOMPARE(audio.playbackState(), audio.PlayingState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
- QCOMPARE(startedSpy.count(), ++started);
- QCOMPARE(pausedSpy.count(), paused);
- QCOMPARE(resumedSpy.count(), resumed);
- QCOMPARE(stoppedSpy.count(), stopped);
+ QCOMPARE(stateChangedSpy.count(), ++stateChanged);
+ QCOMPARE(pausedSpy.count(), pausedCount);
}
void tst_QDeclarativeAudio::duration()
@@ -1210,17 +932,17 @@ void tst_QDeclarativeAudio::loops()
QDeclarativeAudio audio;
QSignalSpy loopsChangedSpy(&audio, SIGNAL(loopCountChanged()));
- QSignalSpy playingChangedSpy(&audio, SIGNAL(playingChanged()));
+ QSignalSpy stateChangedSpy(&audio, SIGNAL(playbackStateChanged()));
QSignalSpy stoppedSpy(&audio, SIGNAL(stopped()));
- int playingChanged = 0;
- int stopped = 0;
+ int stateChanged = 0;
int loopsChanged = 0;
+ int stoppedCount = 0;
audio.classBegin();
audio.componentComplete();
- QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(audio.playbackState(), audio.StoppedState);
//setLoopCount(3) when stopped.
audio.setLoopCount(3);
@@ -1229,68 +951,67 @@ void tst_QDeclarativeAudio::loops()
//play till end
audio.play();
- QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.playbackState(), audio.PlayingState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(stateChangedSpy.count(), ++stateChanged);
+ QCOMPARE(stoppedSpy.count(), stoppedCount);
- // setPlaying(true) when playing.
- audio.setPlaying(true);
- QCOMPARE(audio.isPlaying(), true);
+ // play() when playing.
+ audio.play();
+ QCOMPARE(audio.playbackState(), audio.PlayingState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(stoppedSpy.count(), stopped);
+ QCOMPARE(stateChangedSpy.count(), stateChanged);
+ QCOMPARE(stoppedSpy.count(), stoppedCount);
provider.playerControl()->updateMediaStatus(QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState);
- QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.playbackState(), audio.PlayingState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(stateChangedSpy.count(), stateChanged);
+ QCOMPARE(stoppedSpy.count(), stoppedCount);
//play to end
provider.playerControl()->updateMediaStatus(QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState);
+ QCOMPARE(stoppedSpy.count(), stoppedCount);
//play to end
provider.playerControl()->updateMediaStatus(QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState);
- QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(audio.playbackState(), audio.StoppedState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(stoppedSpy.count(), ++stopped);
+ QCOMPARE(stateChangedSpy.count(), ++stateChanged);
+ QCOMPARE(stoppedSpy.count(), ++stoppedCount);
// stop when playing
audio.play();
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(stateChangedSpy.count(), ++stateChanged);
+ QCOMPARE(stoppedSpy.count(), stoppedCount);
provider.playerControl()->updateMediaStatus(QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState);
audio.stop();
- QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(audio.playbackState(), audio.StoppedState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(stoppedSpy.count(), ++stopped);
+ QCOMPARE(stateChangedSpy.count(), ++stateChanged);
+ QCOMPARE(stoppedSpy.count(), ++stoppedCount);
- //setPlaying(true) with infinite loop
+ //play() with infinite loop
audio.setLoopCount(-1);
QCOMPARE(audio.loopCount(), -1);
QCOMPARE(loopsChangedSpy.count(), ++loopsChanged);
- audio.setPlaying(true);
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ audio.play();
+ QCOMPARE(audio.playbackState(), audio.PlayingState);
+ QCOMPARE(stateChangedSpy.count(), ++stateChanged);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
provider.playerControl()->updateMediaStatus(QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState);
- QCOMPARE(audio.isPlaying(), true);
- QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
-
- // play() when playing.
- audio.play();
- QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.playbackState(), audio.PlayingState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
- QCOMPARE(playingChangedSpy.count(), playingChanged);
- QCOMPARE(stoppedSpy.count(), stopped);
+ QCOMPARE(stateChangedSpy.count(), stateChanged);
- // setPlaying(false) when playing in infinite loop.
- audio.setPlaying(false);
- QCOMPARE(audio.isPlaying(), false);
+ // stop() when playing in infinite loop.
+ audio.stop();
+ QCOMPARE(audio.playbackState(), audio.StoppedState);
QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
- QCOMPARE(playingChangedSpy.count(), ++playingChanged);
- QCOMPARE(stoppedSpy.count(), ++stopped);
+ QCOMPARE(stateChangedSpy.count(), ++stateChanged);
+ QCOMPARE(stoppedSpy.count(), ++stoppedCount);
+
+ qDebug() << "Testing version 5";
}
QTEST_MAIN(tst_QDeclarativeAudio)
diff --git a/tests/auto/unit/qdeclarativeaudio_4/qdeclarativeaudio_4.pro b/tests/auto/unit/qdeclarativeaudio_4/qdeclarativeaudio_4.pro
new file mode 100644
index 00000000..0822a738
--- /dev/null
+++ b/tests/auto/unit/qdeclarativeaudio_4/qdeclarativeaudio_4.pro
@@ -0,0 +1,17 @@
+CONFIG += testcase
+TARGET = tst_qdeclarativeaudio_4
+
+QT += multimedia-private declarative testlib
+CONFIG += no_private_qt_headers_warning
+
+HEADERS += \
+ $$QT.multimedia.sources/../imports/multimedia/qdeclarativeaudio_p_4.h \
+ $$QT.multimedia.sources/../imports/multimedia/qdeclarativemediabase_p_4.h \
+ $$QT.multimedia.sources/../imports/multimedia/qdeclarativemediametadata_p.h
+
+SOURCES += \
+ tst_qdeclarativeaudio_4.cpp \
+ $$QT.multimedia.sources/../imports/multimedia/qdeclarativeaudio_4.cpp \
+ $$QT.multimedia.sources/../imports/multimedia/qdeclarativemediabase_4.cpp
+
+INCLUDEPATH += $$QT.multimedia.sources/../imports/multimedia
diff --git a/tests/auto/unit/qdeclarativeaudio_4/tst_qdeclarativeaudio_4.cpp b/tests/auto/unit/qdeclarativeaudio_4/tst_qdeclarativeaudio_4.cpp
new file mode 100644
index 00000000..6737fd9e
--- /dev/null
+++ b/tests/auto/unit/qdeclarativeaudio_4/tst_qdeclarativeaudio_4.cpp
@@ -0,0 +1,1300 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//TESTED_COMPONENT=plugins/declarative/multimedia
+
+#include <QtTest/QtTest>
+
+#include "qdeclarativeaudio_p_4.h"
+#include "qdeclarativemediametadata_p.h"
+
+#include <qmediaplayercontrol.h>
+#include <qmediaservice.h>
+#include <private/qmediaserviceprovider_p.h>
+#include <qmetadatareadercontrol.h>
+
+#include <QtWidgets/qapplication.h>
+
+class tst_QDeclarativeAudio_4 : public QObject
+{
+ Q_OBJECT
+public slots:
+ void initTestCase();
+
+private slots:
+ void nullPlayerControl();
+ void nullMetaDataControl();
+ void nullService();
+
+ void source();
+ void autoLoad();
+ void playing();
+ void paused();
+ void duration();
+ void position();
+ void volume();
+ void muted();
+ void bufferProgress();
+ void seekable();
+ void playbackRate();
+ void status();
+ void metaData_data();
+ void metaData();
+ void error();
+ void loops();
+};
+
+Q_DECLARE_METATYPE(QDeclarativeAudio_4::Error);
+
+class QtTestMediaPlayerControl : public QMediaPlayerControl
+{
+ Q_OBJECT
+public:
+ QtTestMediaPlayerControl(QObject *parent = 0)
+ : QMediaPlayerControl(parent)
+ , m_state(QMediaPlayer::StoppedState)
+ , m_mediaStatus(QMediaPlayer::NoMedia)
+ , m_duration(0)
+ , m_position(0)
+ , m_playbackRate(1.0)
+ , m_volume(100)
+ , m_bufferStatus(0)
+ , m_muted(false)
+ , m_audioAvailable(false)
+ , m_videoAvailable(false)
+ , m_seekable(false)
+ {
+ }
+
+ QMediaPlayer::State state() const { return m_state; }
+ void updateState(QMediaPlayer::State state) { emit stateChanged(m_state = state); }
+
+ QMediaPlayer::MediaStatus mediaStatus() const { return m_mediaStatus; }
+ void updateMediaStatus(QMediaPlayer::MediaStatus status) {
+ emit mediaStatusChanged(m_mediaStatus = status); }
+ void updateMediaStatus(QMediaPlayer::MediaStatus status, QMediaPlayer::State state)
+ {
+ m_mediaStatus = status;
+ m_state = state;
+
+ emit mediaStatusChanged(m_mediaStatus);
+ emit stateChanged(m_state);
+ }
+
+ qint64 duration() const { return m_duration; }
+ void setDuration(qint64 duration) { emit durationChanged(m_duration = duration); }
+
+ qint64 position() const { return m_position; }
+ void setPosition(qint64 position) { emit positionChanged(m_position = position); }
+
+ int volume() const { return m_volume; }
+ void setVolume(int volume) { emit volumeChanged(m_volume = volume); }
+
+ bool isMuted() const { return m_muted; }
+ void setMuted(bool muted) { emit mutedChanged(m_muted = muted); }
+
+ int bufferStatus() const { return m_bufferStatus; }
+ void setBufferStatus(int status) { emit bufferStatusChanged(m_bufferStatus = status); }
+
+ bool isAudioAvailable() const { return m_audioAvailable; }
+ void setAudioAvailable(bool available) {
+ emit audioAvailableChanged(m_audioAvailable = available); }
+ bool isVideoAvailable() const { return m_videoAvailable; }
+ void setVideoAvailable(bool available) {
+ emit videoAvailableChanged(m_videoAvailable = available); }
+
+ bool isSeekable() const { return m_seekable; }
+ void setSeekable(bool seekable) { emit seekableChanged(m_seekable = seekable); }
+
+ QMediaTimeRange availablePlaybackRanges() const { return QMediaTimeRange(); }
+
+ qreal playbackRate() const { return m_playbackRate; }
+ void setPlaybackRate(qreal rate) { emit playbackRateChanged(m_playbackRate = rate); }
+
+ QMediaContent media() const { return m_media; }
+ const QIODevice *mediaStream() const { return 0; }
+ void setMedia(const QMediaContent &media, QIODevice *)
+ {
+ m_media = media;
+
+ m_mediaStatus = m_media.isNull()
+ ? QMediaPlayer::NoMedia
+ : QMediaPlayer::LoadingMedia;
+
+ emit mediaChanged(m_media);
+ emit mediaStatusChanged(m_mediaStatus);
+ }
+
+ void play()
+ {
+ m_state = QMediaPlayer::PlayingState;
+ if (m_mediaStatus == QMediaPlayer::EndOfMedia)
+ updateMediaStatus(QMediaPlayer::LoadedMedia);
+ emit stateChanged(m_state);
+ }
+ void pause() { emit stateChanged(m_state = QMediaPlayer::PausedState); }
+ void stop() { emit stateChanged(m_state = QMediaPlayer::StoppedState); }
+
+ void emitError(QMediaPlayer::Error err, const QString &errorString) {
+ emit error(err, errorString); }
+
+private:
+ QMediaPlayer::State m_state;
+ QMediaPlayer::MediaStatus m_mediaStatus;
+ qint64 m_duration;
+ qint64 m_position;
+ qreal m_playbackRate;
+ int m_volume;
+ int m_bufferStatus;
+ bool m_muted;
+ bool m_audioAvailable;
+ bool m_videoAvailable;
+ bool m_seekable;
+ QMediaContent m_media;
+};
+
+class QtTestMetaDataControl : public QMetaDataReaderControl
+{
+ Q_OBJECT
+public:
+ QtTestMetaDataControl(QObject *parent = 0)
+ : QMetaDataReaderControl(parent)
+ {
+ }
+
+ bool isMetaDataAvailable() const { return true; }
+
+ QVariant metaData(const QString &key) const { return m_metaData.value(key); }
+ void setMetaData(const QString &key, const QVariant &value) {
+ m_metaData.insert(key, value); emit metaDataChanged(); }
+
+ QStringList availableMetaData() const { return m_metaData.keys(); }
+
+private:
+ QMap<QString, QVariant> m_metaData;
+};
+
+class QtTestMediaService : public QMediaService
+{
+ Q_OBJECT
+public:
+ QtTestMediaService(
+ QtTestMediaPlayerControl *playerControl,
+ QtTestMetaDataControl *metaDataControl,
+ QObject *parent)
+ : QMediaService(parent)
+ , playerControl(playerControl)
+ , metaDataControl(metaDataControl)
+ {
+ }
+
+ QMediaControl *requestControl(const char *name)
+ {
+ if (qstrcmp(name, QMediaPlayerControl_iid) == 0)
+ return playerControl;
+ else if (qstrcmp(name, QMetaDataReaderControl_iid) == 0)
+ return metaDataControl;
+ else
+ return 0;
+ }
+
+ void releaseControl(QMediaControl *) {}
+
+ QtTestMediaPlayerControl *playerControl;
+ QtTestMetaDataControl *metaDataControl;
+};
+
+class QtTestMediaServiceProvider : public QMediaServiceProvider
+{
+ Q_OBJECT
+public:
+ QtTestMediaServiceProvider()
+ : service(new QtTestMediaService(
+ new QtTestMediaPlayerControl(this), new QtTestMetaDataControl(this), this))
+ {
+ setDefaultServiceProvider(this);
+ }
+
+ QtTestMediaServiceProvider(QtTestMediaService *service)
+ : service(service)
+ {
+ setDefaultServiceProvider(this);
+ }
+
+ QtTestMediaServiceProvider(
+ QtTestMediaPlayerControl *playerControl, QtTestMetaDataControl *metaDataControl)
+ : service(new QtTestMediaService(playerControl, metaDataControl, this))
+ {
+ setDefaultServiceProvider(this);
+ }
+
+ ~QtTestMediaServiceProvider()
+ {
+ setDefaultServiceProvider(0);
+ }
+
+ QMediaService *requestService(
+ const QByteArray &type,
+ const QMediaServiceProviderHint & = QMediaServiceProviderHint())
+ {
+ requestedService = type;
+
+ return service;
+ }
+
+ void releaseService(QMediaService *) {}
+
+ inline QtTestMediaPlayerControl *playerControl() { return service->playerControl; }
+ inline QtTestMetaDataControl *metaDataControl() { return service->metaDataControl; }
+
+ QtTestMediaService *service;
+ QByteArray requestedService;
+};
+
+void tst_QDeclarativeAudio_4::initTestCase()
+{
+ qRegisterMetaType<QDeclarativeAudio_4::Error>();
+}
+
+void tst_QDeclarativeAudio_4::nullPlayerControl()
+{
+ QtTestMetaDataControl metaDataControl;
+ QtTestMediaServiceProvider provider(0, &metaDataControl);
+
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+
+ QCOMPARE(audio.source(), QUrl());
+ audio.setSource(QUrl("http://example.com"));
+ QCOMPARE(audio.source(), QUrl("http://example.com"));
+
+ QCOMPARE(audio.isPlaying(), false);
+ audio.setPlaying(true);
+ QCOMPARE(audio.isPlaying(), true);
+ audio.setPlaying(false);
+ audio.play();
+ QCOMPARE(audio.isPlaying(), false);
+
+ QCOMPARE(audio.isPaused(), false);
+ audio.pause();
+ QCOMPARE(audio.isPaused(), false);
+ audio.setPaused(true);
+ QCOMPARE(audio.isPaused(), true);
+
+ QCOMPARE(audio.duration(), 0);
+
+ QCOMPARE(audio.position(), 0);
+ audio.setPosition(10000);
+ QCOMPARE(audio.position(), 10000);
+
+ QCOMPARE(audio.volume(), qreal(1.0));
+ audio.setVolume(0.5);
+ QCOMPARE(audio.volume(), qreal(0.5));
+
+ QCOMPARE(audio.isMuted(), false);
+ audio.setMuted(true);
+ QCOMPARE(audio.isMuted(), true);
+
+ QCOMPARE(audio.bufferProgress(), qreal(0));
+
+ QCOMPARE(audio.isSeekable(), false);
+
+ QCOMPARE(audio.playbackRate(), qreal(1.0));
+
+ QCOMPARE(audio.status(), QDeclarativeAudio_4::NoMedia);
+
+ QCOMPARE(audio.error(), QDeclarativeAudio_4::ServiceMissing);
+}
+
+void tst_QDeclarativeAudio_4::nullMetaDataControl()
+{
+ QtTestMediaPlayerControl playerControl;
+ QtTestMediaServiceProvider provider(&playerControl, 0);
+
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+ audio.componentComplete();
+
+ QVERIFY(audio.metaData());
+}
+
+void tst_QDeclarativeAudio_4::nullService()
+{
+ QtTestMediaServiceProvider provider(0);
+
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+
+ QCOMPARE(audio.source(), QUrl());
+ audio.setSource(QUrl("http://example.com"));
+ QCOMPARE(audio.source(), QUrl("http://example.com"));
+
+ QCOMPARE(audio.isPlaying(), false);
+ audio.setPlaying(true);
+ QCOMPARE(audio.isPlaying(), true);
+ audio.setPlaying(false);
+ audio.play();
+ QCOMPARE(audio.isPlaying(), false);
+
+ QCOMPARE(audio.isPaused(), false);
+ audio.pause();
+ QCOMPARE(audio.isPaused(), false);
+ audio.setPaused(true);
+ QCOMPARE(audio.isPaused(), true);
+
+ QCOMPARE(audio.duration(), 0);
+
+ QCOMPARE(audio.position(), 0);
+ audio.setPosition(10000);
+ QCOMPARE(audio.position(), 10000);
+
+ QCOMPARE(audio.volume(), qreal(1.0));
+ audio.setVolume(0.5);
+ QCOMPARE(audio.volume(), qreal(0.5));
+
+ QCOMPARE(audio.isMuted(), false);
+ audio.setMuted(true);
+ QCOMPARE(audio.isMuted(), true);
+
+ QCOMPARE(audio.bufferProgress(), qreal(0));
+
+ QCOMPARE(audio.isSeekable(), false);
+
+ QCOMPARE(audio.playbackRate(), qreal(1.0));
+
+ QCOMPARE(audio.status(), QDeclarativeAudio_4::NoMedia);
+
+ QCOMPARE(audio.error(), QDeclarativeAudio_4::ServiceMissing);
+
+ QVERIFY(audio.metaData());
+}
+
+void tst_QDeclarativeAudio_4::source()
+{
+ const QUrl url1("http://example.com");
+ const QUrl url2("file:///local/path");
+ const QUrl url3;
+
+ QtTestMediaServiceProvider provider;
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+ audio.componentComplete();
+
+ QSignalSpy spy(&audio, SIGNAL(sourceChanged()));
+
+ audio.setSource(url1);
+ QCOMPARE(audio.source(), url1);
+ QCOMPARE(provider.playerControl()->media().canonicalUrl(), url1);
+ QCOMPARE(spy.count(), 1);
+
+ audio.setSource(url2);
+ QCOMPARE(audio.source(), url2);
+ QCOMPARE(provider.playerControl()->media().canonicalUrl(), url2);
+ QCOMPARE(spy.count(), 2);
+
+ audio.setSource(url3);
+ QCOMPARE(audio.source(), url3);
+ QCOMPARE(provider.playerControl()->media().canonicalUrl(), url3);
+ QCOMPARE(spy.count(), 3);
+}
+
+void tst_QDeclarativeAudio_4::autoLoad()
+{
+ QtTestMediaServiceProvider provider;
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+ audio.componentComplete();
+
+ QSignalSpy spy(&audio, SIGNAL(autoLoadChanged()));
+
+ QCOMPARE(audio.isAutoLoad(), true);
+
+ audio.setAutoLoad(false);
+ QCOMPARE(audio.isAutoLoad(), false);
+ QCOMPARE(spy.count(), 1);
+
+ audio.setSource(QUrl("http://example.com"));
+ QCOMPARE(audio.source(), QUrl("http://example.com"));
+ audio.play();
+ QCOMPARE(audio.isPlaying(), true);
+ audio.stop();
+
+ audio.setAutoLoad(true);
+ audio.setSource(QUrl("http://example.com"));
+ audio.setPaused(true);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(audio.isPaused(), true);
+}
+
+void tst_QDeclarativeAudio_4::playing()
+{
+ QtTestMediaServiceProvider provider;
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+
+ QSignalSpy playingChangedSpy(&audio, SIGNAL(playingChanged()));
+ QSignalSpy startedSpy(&audio, SIGNAL(started()));
+ QSignalSpy stoppedSpy(&audio, SIGNAL(stopped()));
+
+ int playingChanged = 0;
+ int started = 0;
+ int stopped = 0;
+
+ audio.componentComplete();
+ audio.setSource(QUrl("http://example.com"));
+
+ QCOMPARE(audio.isPlaying(), false);
+
+ // setPlaying(true) when stopped.
+ audio.setPlaying(true);
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(startedSpy.count(), ++started);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // setPlaying(false) when playing.
+ audio.setPlaying(false);
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(stoppedSpy.count(), ++stopped);
+
+ // play() when stopped.
+ audio.play();
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(startedSpy.count(), ++started);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // stop() when playing.
+ audio.stop();
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(stoppedSpy.count(), ++stopped);
+
+ // stop() when stopped.
+ audio.stop();
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // setPlaying(false) when stopped.
+ audio.setPlaying(false);
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ audio.setPlaying(true);
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(startedSpy.count(), ++started);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // setPlaying(true) when playing.
+ audio.setPlaying(true);
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // play() when playing.
+ audio.play();
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(stoppedSpy.count(), stopped);
+}
+
+void tst_QDeclarativeAudio_4::paused()
+{
+ QtTestMediaServiceProvider provider;
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+
+ QSignalSpy playingChangedSpy(&audio, SIGNAL(playingChanged()));
+ QSignalSpy pausedChangedSpy(&audio, SIGNAL(pausedChanged()));
+ QSignalSpy startedSpy(&audio, SIGNAL(started()));
+ QSignalSpy pausedSpy(&audio, SIGNAL(paused()));
+ QSignalSpy resumedSpy(&audio, SIGNAL(resumed()));
+ QSignalSpy stoppedSpy(&audio, SIGNAL(stopped()));
+
+ int playingChanged = 0;
+ int pausedChanged = 0;
+ int started = 0;
+ int paused = 0;
+ int resumed = 0;
+ int stopped = 0;
+
+ audio.componentComplete();
+ audio.setSource(QUrl("http://example.com"));
+
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(audio.isPaused(), false);
+
+ // setPlaying(true) when stopped.
+ audio.setPlaying(true);
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.isPaused(), false);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), pausedChanged);
+ QCOMPARE(startedSpy.count(), ++started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // setPaused(true) when playing.
+ audio.setPaused(true);
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), ++paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // setPaused(true) when paused.
+ audio.setPaused(true);
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // pause() when paused.
+ audio.pause();
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // setPaused(false) when paused.
+ audio.setPaused(false);
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.isPaused(), false);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), ++resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // setPaused(false) when playing.
+ audio.setPaused(false);
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.isPaused(), false);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // pause() when playing.
+ audio.pause();
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), ++paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // setPlaying(false) when paused.
+ audio.setPlaying(false);
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), ++stopped);
+
+ // setPaused(true) when stopped and paused.
+ audio.setPaused(true);
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // setPaused(false) when stopped and paused.
+ audio.setPaused(false);
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(audio.isPaused(), false);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // setPaused(true) when stopped.
+ audio.setPaused(true);
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // setPlaying(true) when stopped and paused.
+ audio.setPlaying(true);
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), pausedChanged);
+ QCOMPARE(startedSpy.count(), ++started);
+ QCOMPARE(pausedSpy.count(), ++paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // play() when paused.
+ audio.play();
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.isPaused(), false);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), ++resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // setPaused(true) when playing.
+ audio.setPaused(true);
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), ++paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // stop() when paused.
+ audio.stop();
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(audio.isPaused(), false);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), ++stopped);
+
+ // setPaused(true) when stopped.
+ audio.setPaused(true);
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // stop() when stopped and paused.
+ audio.stop();
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(audio.isPaused(), false);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // pause() when stopped.
+ audio.pause();
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
+ QCOMPARE(startedSpy.count(), ++started);
+ QCOMPARE(pausedSpy.count(), ++paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // setPlaying(false) when paused.
+ audio.setPlaying(false);
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), ++stopped);
+
+ // pause() when stopped and paused.
+ audio.pause();
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), pausedChanged);
+ QCOMPARE(startedSpy.count(), ++started);
+ QCOMPARE(pausedSpy.count(), ++paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // setPlaying(false) when paused.
+ audio.setPlaying(false);
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(audio.isPaused(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), pausedChanged);
+ QCOMPARE(startedSpy.count(), started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), ++stopped);
+
+ // play() when stopped and paused.
+ audio.play();
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(audio.isPaused(), false);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(pausedChangedSpy.count(), ++pausedChanged);
+ QCOMPARE(startedSpy.count(), ++started);
+ QCOMPARE(pausedSpy.count(), paused);
+ QCOMPARE(resumedSpy.count(), resumed);
+ QCOMPARE(stoppedSpy.count(), stopped);
+}
+
+void tst_QDeclarativeAudio_4::duration()
+{
+ QtTestMediaServiceProvider provider;
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+ audio.componentComplete();
+
+ QSignalSpy spy(&audio, SIGNAL(durationChanged()));
+
+ QCOMPARE(audio.duration(), 0);
+
+ provider.playerControl()->setDuration(4040);
+ QCOMPARE(audio.duration(), 4040);
+ QCOMPARE(spy.count(), 1);
+
+ provider.playerControl()->setDuration(-129);
+ QCOMPARE(audio.duration(), -129);
+ QCOMPARE(spy.count(), 2);
+
+ provider.playerControl()->setDuration(0);
+ QCOMPARE(audio.duration(), 0);
+ QCOMPARE(spy.count(), 3);
+
+ // Unnecessary duration changed signals aren't filtered.
+ provider.playerControl()->setDuration(0);
+ QCOMPARE(audio.duration(), 0);
+ QCOMPARE(spy.count(), 4);
+}
+
+void tst_QDeclarativeAudio_4::position()
+{
+ QtTestMediaServiceProvider provider;
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+ audio.componentComplete();
+
+ QSignalSpy spy(&audio, SIGNAL(positionChanged()));
+
+ QCOMPARE(audio.position(), 0);
+
+ // QDeclarativeAudio_4 won't bound set positions to the duration. A media service may though.
+ QCOMPARE(audio.duration(), 0);
+
+ audio.setPosition(450);
+ QCOMPARE(audio.position(), 450);
+ QCOMPARE(provider.playerControl()->position(), qint64(450));
+ QCOMPARE(spy.count(), 1);
+
+ audio.setPosition(-5403);
+ QCOMPARE(audio.position(), -5403);
+ QCOMPARE(provider.playerControl()->position(), qint64(-5403));
+ QCOMPARE(spy.count(), 2);
+
+ audio.setPosition(-5403);
+ QCOMPARE(audio.position(), -5403);
+ QCOMPARE(provider.playerControl()->position(), qint64(-5403));
+ QCOMPARE(spy.count(), 2);
+
+ // Check the signal change signal is emitted if the change originates from the media service.
+ provider.playerControl()->setPosition(0);
+ QCOMPARE(audio.position(), 0);
+ QCOMPARE(spy.count(), 3);
+
+ connect(&audio, SIGNAL(positionChanged()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+
+ provider.playerControl()->updateState(QMediaPlayer::PlayingState);
+ QTestEventLoop::instance().enterLoop(1);
+ QVERIFY(spy.count() > 3 && spy.count() < 6); // 4 or 5
+
+ provider.playerControl()->updateState(QMediaPlayer::PausedState);
+ QTestEventLoop::instance().enterLoop(1);
+ QVERIFY(spy.count() < 6);
+}
+
+void tst_QDeclarativeAudio_4::volume()
+{
+ QtTestMediaServiceProvider provider;
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+ audio.componentComplete();
+
+ QSignalSpy spy(&audio, SIGNAL(volumeChanged()));
+
+ QCOMPARE(audio.volume(), qreal(1.0));
+
+ audio.setVolume(0.7);
+ QCOMPARE(audio.volume(), qreal(0.7));
+ QCOMPARE(provider.playerControl()->volume(), 70);
+ QCOMPARE(spy.count(), 1);
+
+ audio.setVolume(0.7);
+ QCOMPARE(audio.volume(), qreal(0.7));
+ QCOMPARE(provider.playerControl()->volume(), 70);
+ QCOMPARE(spy.count(), 1);
+
+ provider.playerControl()->setVolume(30);
+ QCOMPARE(audio.volume(), qreal(0.3));
+ QCOMPARE(spy.count(), 2);
+}
+
+void tst_QDeclarativeAudio_4::muted()
+{
+ QtTestMediaServiceProvider provider;
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+ audio.componentComplete();
+
+ QSignalSpy spy(&audio, SIGNAL(mutedChanged()));
+
+ QCOMPARE(audio.isMuted(), false);
+
+ audio.setMuted(true);
+ QCOMPARE(audio.isMuted(), true);
+ QCOMPARE(provider.playerControl()->isMuted(), true);
+ QCOMPARE(spy.count(), 1);
+
+ provider.playerControl()->setMuted(false);
+ QCOMPARE(audio.isMuted(), false);
+ QCOMPARE(spy.count(), 2);
+
+ audio.setMuted(false);
+ QCOMPARE(audio.isMuted(), false);
+ QCOMPARE(provider.playerControl()->isMuted(), false);
+ QCOMPARE(spy.count(), 3);
+}
+
+void tst_QDeclarativeAudio_4::bufferProgress()
+{
+ QtTestMediaServiceProvider provider;
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+ audio.componentComplete();
+
+ QSignalSpy spy(&audio, SIGNAL(bufferProgressChanged()));
+
+ QCOMPARE(audio.bufferProgress(), qreal(0.0));
+
+ provider.playerControl()->setBufferStatus(20);
+ QCOMPARE(audio.bufferProgress(), qreal(0.2));
+ QCOMPARE(spy.count(), 1);
+
+ provider.playerControl()->setBufferStatus(20);
+ QCOMPARE(audio.bufferProgress(), qreal(0.2));
+ QCOMPARE(spy.count(), 2);
+
+ provider.playerControl()->setBufferStatus(40);
+ QCOMPARE(audio.bufferProgress(), qreal(0.4));
+ QCOMPARE(spy.count(), 3);
+
+ connect(&audio, SIGNAL(positionChanged()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+
+ provider.playerControl()->updateMediaStatus(
+ QMediaPlayer::BufferingMedia, QMediaPlayer::PlayingState);
+ QTestEventLoop::instance().enterLoop(1);
+ QVERIFY(spy.count() > 3 && spy.count() < 6); // 4 or 5
+
+ provider.playerControl()->updateMediaStatus(QMediaPlayer::BufferedMedia);
+ QTestEventLoop::instance().enterLoop(1);
+ QVERIFY(spy.count() < 6);
+}
+
+void tst_QDeclarativeAudio_4::seekable()
+{
+ QtTestMediaServiceProvider provider;
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+ audio.componentComplete();
+
+ QSignalSpy spy(&audio, SIGNAL(seekableChanged()));
+
+ QCOMPARE(audio.isSeekable(), false);
+
+ provider.playerControl()->setSeekable(true);
+ QCOMPARE(audio.isSeekable(), true);
+ QCOMPARE(spy.count(), 1);
+
+ provider.playerControl()->setSeekable(true);
+ QCOMPARE(audio.isSeekable(), true);
+ QCOMPARE(spy.count(), 2);
+
+ provider.playerControl()->setSeekable(false);
+ QCOMPARE(audio.isSeekable(), false);
+ QCOMPARE(spy.count(), 3);
+}
+
+void tst_QDeclarativeAudio_4::playbackRate()
+{
+ QtTestMediaServiceProvider provider;
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+ audio.componentComplete();
+
+ QSignalSpy spy(&audio, SIGNAL(playbackRateChanged()));
+
+ QCOMPARE(audio.playbackRate(), qreal(1.0));
+
+ audio.setPlaybackRate(0.5);
+ QCOMPARE(audio.playbackRate(), qreal(0.5));
+ QCOMPARE(provider.playerControl()->playbackRate(), qreal(0.5));
+ QCOMPARE(spy.count(), 1);
+
+ provider.playerControl()->setPlaybackRate(2.0);
+ QCOMPARE(provider.playerControl()->playbackRate(), qreal(2.0));
+ QCOMPARE(spy.count(), 2);
+
+ audio.setPlaybackRate(2.0);
+ QCOMPARE(audio.playbackRate(), qreal(2.0));
+ QCOMPARE(provider.playerControl()->playbackRate(), qreal(2.0));
+ QCOMPARE(spy.count(), 3);
+}
+
+void tst_QDeclarativeAudio_4::status()
+{
+ QtTestMediaServiceProvider provider;
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+ audio.componentComplete();
+
+ QSignalSpy statusChangedSpy(&audio, SIGNAL(statusChanged()));
+
+ QCOMPARE(audio.status(), QDeclarativeAudio_4::NoMedia);
+
+ // Set media, start loading.
+ provider.playerControl()->updateMediaStatus(QMediaPlayer::LoadingMedia);
+ QCOMPARE(audio.status(), QDeclarativeAudio_4::Loading);
+ QCOMPARE(statusChangedSpy.count(), 1);
+
+ // Finish loading.
+ provider.playerControl()->updateMediaStatus(QMediaPlayer::LoadedMedia);
+ QCOMPARE(audio.status(), QDeclarativeAudio_4::Loaded);
+ QCOMPARE(statusChangedSpy.count(), 2);
+
+ // Play, start buffering.
+ provider.playerControl()->updateMediaStatus(
+ QMediaPlayer::StalledMedia, QMediaPlayer::PlayingState);
+ QCOMPARE(audio.status(), QDeclarativeAudio_4::Stalled);
+ QCOMPARE(statusChangedSpy.count(), 3);
+
+ // Enough data buffered to proceed.
+ provider.playerControl()->updateMediaStatus(QMediaPlayer::BufferingMedia);
+ QCOMPARE(audio.status(), QDeclarativeAudio_4::Buffering);
+ QCOMPARE(statusChangedSpy.count(), 4);
+
+ // Errant second buffering status changed.
+ provider.playerControl()->updateMediaStatus(QMediaPlayer::BufferingMedia);
+ QCOMPARE(audio.status(), QDeclarativeAudio_4::Buffering);
+ QCOMPARE(statusChangedSpy.count(), 4);
+
+ // Buffer full.
+ provider.playerControl()->updateMediaStatus(QMediaPlayer::BufferedMedia);
+ QCOMPARE(audio.status(), QDeclarativeAudio_4::Buffered);
+ QCOMPARE(statusChangedSpy.count(), 5);
+
+ // Buffer getting low.
+ provider.playerControl()->updateMediaStatus(QMediaPlayer::BufferingMedia);
+ QCOMPARE(audio.status(), QDeclarativeAudio_4::Buffering);
+ QCOMPARE(statusChangedSpy.count(), 6);
+
+ // Buffer full.
+ provider.playerControl()->updateMediaStatus(QMediaPlayer::BufferedMedia);
+ QCOMPARE(audio.status(), QDeclarativeAudio_4::Buffered);
+ QCOMPARE(statusChangedSpy.count(), 7);
+
+ // Finished.
+ provider.playerControl()->updateMediaStatus(
+ QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState);
+ QCOMPARE(audio.status(), QDeclarativeAudio_4::EndOfMedia);
+ QCOMPARE(statusChangedSpy.count(), 8);
+}
+
+void tst_QDeclarativeAudio_4::metaData_data()
+{
+ QTest::addColumn<QByteArray>("propertyName");
+ QTest::addColumn<QString>("propertyKey");
+ QTest::addColumn<QVariant>("value");
+
+ QTest::newRow("title")
+ << QByteArray("title")
+ << QtMultimedia::MetaData::Title
+ << QVariant(QString::fromLatin1("This is a title"));
+
+ QTest::newRow("genre")
+ << QByteArray("genre")
+ << QtMultimedia::MetaData::Genre
+ << QVariant(QString::fromLatin1("rock"));
+
+ QTest::newRow("trackNumber")
+ << QByteArray("trackNumber")
+ << QtMultimedia::MetaData::TrackNumber
+ << QVariant(8);
+}
+
+void tst_QDeclarativeAudio_4::metaData()
+{
+ QFETCH(QByteArray, propertyName);
+ QFETCH(QString, propertyKey);
+ QFETCH(QVariant, value);
+
+ QtTestMediaServiceProvider provider;
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+ audio.componentComplete();
+
+ QSignalSpy spy(audio.metaData(), SIGNAL(metaDataChanged()));
+
+ const int index = audio.metaData()->metaObject()->indexOfProperty(propertyName.constData());
+ QVERIFY(index != -1);
+
+ QMetaProperty property = audio.metaData()->metaObject()->property(index);
+ QCOMPARE(property.read(&audio), QVariant());
+
+ property.write(audio.metaData(), value);
+ QCOMPARE(property.read(audio.metaData()), QVariant());
+ QCOMPARE(provider.metaDataControl()->metaData(propertyKey), QVariant());
+ QCOMPARE(spy.count(), 0);
+
+ provider.metaDataControl()->setMetaData(propertyKey, value);
+ QCOMPARE(property.read(audio.metaData()), value);
+ QCOMPARE(spy.count(), 1);
+}
+
+void tst_QDeclarativeAudio_4::error()
+{
+ const QString errorString = QLatin1String("Failed to open device.");
+
+ QtTestMediaServiceProvider provider;
+ QDeclarativeAudio_4 audio;
+ audio.classBegin();
+ audio.componentComplete();
+
+ QSignalSpy errorSpy(&audio, SIGNAL(error(QDeclarativeAudio_4::Error,QString)));
+ QSignalSpy errorChangedSpy(&audio, SIGNAL(errorChanged()));
+
+ QCOMPARE(audio.error(), QDeclarativeAudio_4::NoError);
+ QCOMPARE(audio.errorString(), QString());
+
+ provider.playerControl()->emitError(QMediaPlayer::ResourceError, errorString);
+
+ QCOMPARE(audio.error(), QDeclarativeAudio_4::ResourceError);
+ QCOMPARE(audio.errorString(), errorString);
+ QCOMPARE(errorSpy.count(), 1);
+ QCOMPARE(errorChangedSpy.count(), 1);
+
+ // Changing the source resets the error properties.
+ audio.setSource(QUrl("http://example.com"));
+ QCOMPARE(audio.error(), QDeclarativeAudio_4::NoError);
+ QCOMPARE(audio.errorString(), QString());
+ QCOMPARE(errorSpy.count(), 1);
+ QCOMPARE(errorChangedSpy.count(), 2);
+
+ // But isn't noisy.
+ audio.setSource(QUrl("file:///file/path"));
+ QCOMPARE(audio.error(), QDeclarativeAudio_4::NoError);
+ QCOMPARE(audio.errorString(), QString());
+ QCOMPARE(errorSpy.count(), 1);
+ QCOMPARE(errorChangedSpy.count(), 2);
+}
+
+void tst_QDeclarativeAudio_4::loops()
+{
+ QtTestMediaServiceProvider provider;
+ QDeclarativeAudio_4 audio;
+
+ QSignalSpy loopsChangedSpy(&audio, SIGNAL(loopCountChanged()));
+ QSignalSpy playingChangedSpy(&audio, SIGNAL(playingChanged()));
+ QSignalSpy stoppedSpy(&audio, SIGNAL(stopped()));
+
+ int playingChanged = 0;
+ int stopped = 0;
+ int loopsChanged = 0;
+
+ audio.classBegin();
+ audio.componentComplete();
+
+ QCOMPARE(audio.isPlaying(), false);
+
+ //setLoopCount(3) when stopped.
+ audio.setLoopCount(3);
+ QCOMPARE(audio.loopCount(), 3);
+ QCOMPARE(loopsChangedSpy.count(), ++loopsChanged);
+
+ //play till end
+ audio.play();
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+
+ // setPlaying(true) when playing.
+ audio.setPlaying(true);
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ provider.playerControl()->updateMediaStatus(QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState);
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+
+ //play to end
+ provider.playerControl()->updateMediaStatus(QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState);
+ //play to end
+ provider.playerControl()->updateMediaStatus(QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState);
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(stoppedSpy.count(), ++stopped);
+
+ // stop when playing
+ audio.play();
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ provider.playerControl()->updateMediaStatus(QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState);
+ audio.stop();
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(stoppedSpy.count(), ++stopped);
+
+ //setPlaying(true) with infinite loop
+ audio.setLoopCount(-1);
+ QCOMPARE(audio.loopCount(), -1);
+ QCOMPARE(loopsChangedSpy.count(), ++loopsChanged);
+ audio.setPlaying(true);
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ provider.playerControl()->updateMediaStatus(QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState);
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+
+ // play() when playing.
+ audio.play();
+ QCOMPARE(audio.isPlaying(), true);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(playingChangedSpy.count(), playingChanged);
+ QCOMPARE(stoppedSpy.count(), stopped);
+
+ // setPlaying(false) when playing in infinite loop.
+ audio.setPlaying(false);
+ QCOMPARE(audio.isPlaying(), false);
+ QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(playingChangedSpy.count(), ++playingChanged);
+ QCOMPARE(stoppedSpy.count(), ++stopped);
+
+ qDebug() << "testing version 4";
+}
+
+QTEST_MAIN(tst_QDeclarativeAudio_4)
+
+#include "tst_qdeclarativeaudio_4.moc"