summaryrefslogtreecommitdiffstats
path: root/src/multimedia
diff options
context:
space:
mode:
Diffstat (limited to 'src/multimedia')
-rw-r--r--src/multimedia/qml/qmetadatacontrolmetaobject.cpp234
-rw-r--r--src/multimedia/qml/qmetadatacontrolmetaobject_p.h85
-rw-r--r--src/multimedia/qml/qml.pri12
-rw-r--r--src/multimedia/qml/qmlaudio.cpp292
-rw-r--r--src/multimedia/qml/qmlaudio_p.h162
-rw-r--r--src/multimedia/qml/qmlgraphicsvideo.cpp378
-rw-r--r--src/multimedia/qml/qmlgraphicsvideo_p.h197
-rw-r--r--src/multimedia/qml/qmlmediabase.cpp379
8 files changed, 1737 insertions, 2 deletions
diff --git a/src/multimedia/qml/qmetadatacontrolmetaobject.cpp b/src/multimedia/qml/qmetadatacontrolmetaobject.cpp
new file mode 100644
index 0000000..c2b5e78
--- /dev/null
+++ b/src/multimedia/qml/qmetadatacontrolmetaobject.cpp
@@ -0,0 +1,234 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtMultimedia module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtMultimedia/private/qmetadatacontrolmetaobject_p.h>
+
+#include <QtMultimedia>/qmetadatacontrol.h>
+
+
+QT_BEGIN_NAMESPACE
+
+namespace
+{
+ struct MetaDataKey
+ {
+ QtMedia::MetaData key;
+ const char *name;
+ };
+
+ const MetaDataKey qt_metaDataKeys[] =
+ {
+ { QtMedia::Title, "title" },
+ { QtMedia::SubTitle, "subTitle" },
+ { QtMedia::Author, "author" },
+ { QtMedia::Comment, "comment" },
+ { QtMedia::Description, "description" },
+ { QtMedia::Category, "category" },
+ { QtMedia::Genre, "genre" },
+ { QtMedia::Year, "year" },
+ { QtMedia::Date, "date" },
+ { QtMedia::UserRating, "userRating" },
+ { QtMedia::Keywords, "keywords" },
+ { QtMedia::Language, "language" },
+ { QtMedia::Publisher, "publisher" },
+ { QtMedia::Copyright, "copyright" },
+ { QtMedia::ParentalRating, "parentalRating" },
+ { QtMedia::RatingOrganisation, "ratingOrganisation" },
+
+ // Media
+ { QtMedia::Size, "size" },
+ { QtMedia::MediaType, "mediaType" },
+ { QtMedia::Duration, "duration" },
+
+ // Audio
+ { QtMedia::AudioBitRate, "audioBitRate" },
+ { QtMedia::AudioCodec, "audioCodec" },
+ { QtMedia::AverageLevel, "averageLevel" },
+ { QtMedia::ChannelCount, "channelCount" },
+ { QtMedia::PeakValue, "peakValue" },
+ { QtMedia::SampleRate, "frequency" },
+
+ // Music
+ { QtMedia::AlbumTitle, "albumTitle" },
+ { QtMedia::AlbumArtist, "albumArtist" },
+ { QtMedia::ContributingArtist, "contributingArtist" },
+ { QtMedia::Composer, "composer" },
+ { QtMedia::Conductor, "conductor" },
+ { QtMedia::Lyrics, "lyrics" },
+ { QtMedia::Mood, "mood" },
+ { QtMedia::TrackNumber, "trackNumber" },
+ { QtMedia::TrackCount, "trackCount" },
+
+ { QtMedia::CoverArtUrlSmall, "coverArtUrlSmall" },
+ { QtMedia::CoverArtUrlLarge, "coverArtUrlLarge" },
+
+ // Image/Video
+ { QtMedia::Resolution, "resolution" },
+ { QtMedia::PixelAspectRatio, "pixelAspectRatio" },
+
+ // Video
+ { QtMedia::VideoFrameRate, "videoFrameRate" },
+ { QtMedia::VideoBitRate, "videoBitRate" },
+ { QtMedia::VideoCodec, "videoCodec" },
+
+ { QtMedia::PosterUrl, "posterUrl" },
+
+ // Movie
+ { QtMedia::ChapterNumber, "chapterNumber" },
+ { QtMedia::Director, "director" },
+ { QtMedia::LeadPerformer, "leadPerformer" },
+ { QtMedia::Writer, "writer" },
+
+ // Photos
+ { QtMedia::CameraManufacturer, "cameraManufacturer" },
+ { QtMedia::CameraModel, "cameraModel" },
+ { QtMedia::Event, "event" },
+ { QtMedia::Subject, "subject" },
+ { QtMedia::Orientation, "orientation" },
+ { QtMedia::ExposureTime, "exposureTime" },
+ { QtMedia::FNumber, "fNumber" },
+ { QtMedia::ExposureProgram, "exposureProgram" },
+ { QtMedia::ISOSpeedRatings, "isoSpeedRatings" },
+ { QtMedia::ExposureBiasValue, "exposureBiasValue" },
+ { QtMedia::DateTimeOriginal, "dateTimeOriginal" },
+ { QtMedia::DateTimeDigitized, "dateTimeDigitized" },
+ { QtMedia::SubjectDistance, "subjectDistance" },
+ { QtMedia::MeteringMode, "meteringMode" },
+ { QtMedia::LightSource, "lightSource" },
+ { QtMedia::Flash, "flash" },
+ { QtMedia::FocalLength, "focalLength" },
+ { QtMedia::ExposureMode, "exposureMode" },
+ { QtMedia::WhiteBalance, "whiteBalance" },
+ { QtMedia::DigitalZoomRatio, "digitalZoomRatio" },
+ { QtMedia::FocalLengthIn35mmFilm, "focalLengthIn35mmFilm" },
+ { QtMedia::SceneCaptureType, "sceneCaptureType" },
+ { QtMedia::GainControl, "gainControl" },
+ { QtMedia::Contrast, "contrast" },
+ { QtMedia::Saturation, "saturation" },
+ { QtMedia::Sharpness, "sharpness" },
+ { QtMedia::DeviceSettingDescription, "deviceSettingDescription" }
+ };
+}
+
+QMetaDataControlMetaObject::QMetaDataControlMetaObject(QMetaDataControl *control, QObject *object)
+ : m_control(control)
+ , m_object(object)
+ , m_mem(0)
+ , m_propertyOffset(0)
+ , m_signalOffset(0)
+{
+ m_builder.setSuperClass(m_object->metaObject());
+ m_builder.setClassName(m_object->metaObject()->className());
+ m_builder.setFlags(QMetaObjectBuilder::DynamicMetaObject);
+
+ QObjectPrivate *op = QObjectPrivate::get(m_object);
+ if (op->metaObject)
+ m_builder.setSuperClass(op->metaObject);
+
+ m_mem = m_builder.toMetaObject();
+ *static_cast<QMetaObject *>(this) = *m_mem;
+
+ op->metaObject = this;
+ m_propertyOffset = propertyOffset();
+ m_signalOffset = methodOffset();
+}
+
+QMetaDataControlMetaObject::~QMetaDataControlMetaObject()
+{
+ qFree(m_mem);
+
+ QObjectPrivate *op = QObjectPrivate::get(m_object);
+ op->metaObject = 0;
+}
+
+int QMetaDataControlMetaObject::metaCall(QMetaObject::Call c, int id, void **a)
+{
+ if (c == QMetaObject::ReadProperty && id >= m_propertyOffset) {
+ int propId = id - m_propertyOffset;
+
+ *reinterpret_cast<QVariant *>(a[0]) = m_control->metaData(m_keys.at(propId));
+
+ return -1;
+ } else if (c == QMetaObject::WriteProperty && id >= m_propertyOffset) {
+ int propId = id - m_propertyOffset;
+
+ m_control->setMetaData(m_keys.at(propId), *reinterpret_cast<QVariant *>(a[0]));
+
+ activate(m_object, m_signalOffset + propId, 0);
+
+ return -1;
+ } else {
+ return m_object->qt_metacall(c, id, a);
+ }
+}
+
+int QMetaDataControlMetaObject::createProperty(const char *name, const char *)
+{
+ const int count = sizeof(qt_metaDataKeys) / sizeof(MetaDataKey);
+
+ for (int i = 0; i < count; ++i) {
+ if (qstrcmp(name, qt_metaDataKeys[i].name) == 0) {
+ int id = m_keys.count();
+ m_keys.append(qt_metaDataKeys[i].key);
+
+ m_builder.addSignal("__" + QByteArray::number(id) + "()");
+
+ QMetaPropertyBuilder build = m_builder.addProperty(name, "QVariant", id);
+ build.setDynamic(true);
+
+ qFree(m_mem);
+ m_mem = m_builder.toMetaObject();
+ *static_cast<QMetaObject *>(this) = *m_mem;
+
+ return m_propertyOffset + id;
+ }
+ }
+
+ return -1;
+}
+
+void QMetaDataControlMetaObject::metaDataChanged()
+{
+ for (int i = 0; i < m_keys.count(); ++i)
+ activate(m_object, m_signalOffset + i, 0);
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/qml/qmetadatacontrolmetaobject_p.h b/src/multimedia/qml/qmetadatacontrolmetaobject_p.h
new file mode 100644
index 0000000..b7f88fe
--- /dev/null
+++ b/src/multimedia/qml/qmetadatacontrolmetaobject_p.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtMultimedia module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMETADATACONTROLMETAOBJECT_P_H
+#define QMETADATACONTROLMETAOJBECT_P_H
+
+#include <QtMultimedia/qtmedianamespace.h>
+
+#include <QtCore/qmetaobject.h>
+#include <QtCore/private/qobject_p.h>
+#include <QtDeclarative/private/qmetaobjectbuilder_p.h>
+
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QMetaDataControl;
+
+class QMetaDataControlMetaObject : public QAbstractDynamicMetaObject
+{
+public:
+ QMetaDataControlMetaObject(QMetaDataControl *control, QObject *object);
+ ~QMetaDataControlMetaObject();
+
+ int metaCall(QMetaObject::Call call, int _id, void **arguments);
+ int createProperty(const char *, const char *);
+
+ void metaDataChanged();
+
+private:
+ QMetaDataControl *m_control;
+ QObject *m_object;
+ QMetaObject *m_mem;
+
+ int m_propertyOffset;
+ int m_signalOffset;
+
+ QVector<QtMedia::MetaData> m_keys;
+ QMetaObjectBuilder m_builder;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/multimedia/qml/qml.pri b/src/multimedia/qml/qml.pri
index adfcc23..6b44e0c 100644
--- a/src/multimedia/qml/qml.pri
+++ b/src/multimedia/qml/qml.pri
@@ -3,9 +3,17 @@ contains(QT_CONFIG, declarative) {
QT += declarative
HEADERS += \
- $$PWD/qmlsound_p.h
+ $$PWD/qmlsound_p.h \
+ $$PWD/qmetadatacontrolmetaobject_p.h \
+ $$PWD/qmlaudio_p.h \
+ $$PWD/qmlgraphicsvideo_p.h \
+ $$PWD/qmlmediabase_p.h
SOURCES += \
- $$PWD/qmlsound.cpp
+ $$PWD/qmlsound.cpp \
+ $$PWD/qmetadatacontrolmetaobject.cpp \
+ $$PWD/qmlaudio.cpp \
+ $$PWD/qmlgraphicsvideo.cpp \
+ $$PWD/qmlmediabase.cpp
}
diff --git a/src/multimedia/qml/qmlaudio.cpp b/src/multimedia/qml/qmlaudio.cpp
new file mode 100644
index 0000000..713e36a
--- /dev/null
+++ b/src/multimedia/qml/qmlaudio.cpp
@@ -0,0 +1,292 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtMultimedia module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qmlaudio_p.h"
+
+#include <QtMultimedia/qmediaplayercontrol.h>
+
+QT_BEGIN_NAMESPACE
+
+QML_DEFINE_TYPE(Qt,4,6,Audio,QmlAudio);
+
+/*!
+ \qmlclass Audio QmlAudio
+ \brief The Audio element allows you to add audio to a scene.
+*/
+
+/*!
+ \internal
+ \class QmlAudio
+ \brief The QmlAudio class provides a audio item that you can add to a QmlView.
+*/
+
+void QmlAudio::_q_error(QMediaPlayer::Error errorCode, const QString &errorString)
+{
+ m_error = errorCode;
+ m_errorString = errorString;
+
+ emit error(Error(errorCode), errorString);
+ emit errorChanged();
+}
+
+
+QmlAudio::QmlAudio(QObject *parent)
+ : QObject(parent)
+{
+ setObject(this);
+}
+
+QmlAudio::~QmlAudio()
+{
+ shutdown();
+}
+
+/*!
+ \qmlmethod Audio::play()
+
+ Starts playback of the audio.
+*/
+
+void QmlAudio::play()
+{
+ m_playerControl->play();
+}
+
+/*!
+ \qmlmethod Audio::pause()
+
+ Pauses playback of the audio.
+*/
+
+void QmlAudio::pause()
+{
+ m_playerControl->pause();
+}
+
+/*!
+ \qmlmethod Audio::stop()
+
+ Stops playback of the audio.
+*/
+
+void QmlAudio::stop()
+{
+ m_playerControl->stop();
+}
+
+/*!
+ \qmlproperty url Audio::source
+
+ This property holds the source URL of the audio.
+*/
+
+/*!
+ \qmlproperty bool Audio::playing
+
+ This property holds whether the audio is playing.
+*/
+
+/*!
+ \qmlproperty bool Audio::paused
+
+ This property holds whether the audio is paused.
+*/
+
+/*!
+ \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 enum Audio::status
+
+ This property holds the status of audio loading. It can be one of:
+
+ \list
+ \o NoMedia - no audio has been set.
+ \o Loading - the audio is currently being loaded.
+ \o Loaded - the audio has been loaded.
+ \o Buffering - the audio is buffering data.
+ \o Stalled - playback has been interrupted while the audio is buffering data.
+ \o Buffered - the audio has buffered data.
+ \o EndOfMedia - the audio has played to the end.
+ \o InvalidMedia - the audio cannot be played.
+ \o UnknownStatus - the status of the audio is unknown.
+ \endlist
+*/
+
+QmlAudio::Status QmlAudio::status() const
+{
+ return Status(m_status);
+}
+
+/*!
+ \qmlsignal Audio::onLoaded()
+
+ This handler is called when the video source has been loaded.
+*/
+
+/*!
+ \qmlsignal Audio::onBuffering()
+
+ This handler is called when the video stream starts buffering.
+*/
+
+/*!
+ \qmlsignal Audio::onStalled()
+
+ This handler is called when playback has stalled while the video stream buffers.
+*/
+
+/*!
+ \qmlsignal Audio::onBuffered()
+
+ This handler is called when the video stream has finished buffering.
+*/
+
+/*!
+ \qmlsignal Audio::onEndOfMedia
+
+ This handler is called when playback stops because end of the video has been reached.
+*/
+/*!
+ \qmlproperty int Audio::duration
+
+ This property holds the duration of the audio in milliseconds.
+
+ If the audio 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.
+*/
+
+/*!
+ \qmlproperty qreal 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 qreal 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.
+*/
+
+/*!
+ \qmlproperty qreal playbackRate
+
+ This property holds the rate at which audio is played at as a multiple of the normal rate.
+*/
+
+/*!
+ \qmlproperty enum 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
+*/
+
+QmlAudio::Error QmlAudio::error() const
+{
+ return Error(m_error);
+}
+
+/*!
+ \qmlproperty string Audio::errorString
+
+ This property holds a string describing the current error condition in more detail.
+*/
+
+/*!
+ \qmlproperty Audio::onError(error, errorString)
+
+ This property is called when an \l {Error}{error} has occurred. The errorString parameter
+ may contain more detailed information about the error.
+*/
+
+QT_END_NAMESPACE
+
+#include "moc_qmlaudio_p.cpp"
+
+
diff --git a/src/multimedia/qml/qmlaudio_p.h b/src/multimedia/qml/qmlaudio_p.h
new file mode 100644
index 0000000..c6ab53d
--- /dev/null
+++ b/src/multimedia/qml/qmlaudio_p.h
@@ -0,0 +1,162 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtMultimedia module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMLAUDIO_P_H
+#define QMLAUDIO_P_H
+
+#include <QtMultimedia/private/qmlmediabase_p.h>
+
+#include <QtCore/qbasictimer.h>
+#include <QtDeclarative/qmlgraphicsitem.h>
+
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QTimerEvent;
+
+class QmlAudio : public QObject, public QmlMediaBase, public QmlParserStatus
+{
+ Q_OBJECT
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged)
+ 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(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_ENUMS(Status)
+ Q_ENUMS(Error)
+ Q_INTERFACES(QmlParserStatus)
+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
+ };
+
+ QmlAudio(QObject *parent = 0);
+ ~QmlAudio();
+
+ Status status() const;
+ Error error() const;
+
+public Q_SLOTS:
+ void play();
+ void pause();
+ void stop();
+
+Q_SIGNALS:
+ void sourceChanged();
+
+ void playingChanged();
+ void pausedChanged();
+
+ void started();
+ void resumed();
+ void paused();
+ void stopped();
+
+ void statusChanged();
+
+ void loaded();
+ void buffering();
+ void stalled();
+ void buffered();
+ void endOfMedia();
+
+ void durationChanged();
+ void positionChanged();
+
+ void volumeChanged();
+ void mutedChanged();
+
+ void bufferProgressChanged();
+
+ void seekableChanged();
+ void playbackRateChanged();
+
+ void errorChanged();
+ void error(QmlAudio::Error error, const QString &errorString);
+
+private Q_SLOTS:
+ void _q_error(QMediaPlayer::Error, const QString &);
+
+private:
+ Q_DISABLE_COPY(QmlAudio)
+ Q_PRIVATE_SLOT(mediaBase(), void _q_stateChanged(QMediaPlayer::State))
+ Q_PRIVATE_SLOT(mediaBase(), void _q_mediaStatusChanged(QMediaPlayer::MediaStatus))
+ Q_PRIVATE_SLOT(mediaBase(), void _q_metaDataChanged())
+
+ inline QmlMediaBase *mediaBase() { return this; }
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QmlAudio))
+
+QT_END_HEADER
+
+#endif
diff --git a/src/multimedia/qml/qmlgraphicsvideo.cpp b/src/multimedia/qml/qmlgraphicsvideo.cpp
new file mode 100644
index 0000000..c96f7e9
--- /dev/null
+++ b/src/multimedia/qml/qmlgraphicsvideo.cpp
@@ -0,0 +1,378 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtMultimedia module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qmlgraphicsvideo_p.h"
+
+#include <QtMultimedia/qmediaplayercontrol.h>
+#include <QtMultimedia/qmediaservice.h>
+#include <QtMultimedia/private/qpaintervideosurface_p.h>
+#include <QtMultimedia/qvideooutputcontrol.h>
+#include <QtMultimedia/qvideorenderercontrol.h>
+
+
+QT_BEGIN_NAMESPACE
+
+QML_DEFINE_TYPE(Qt,4,6,Video,QmlGraphicsVideo);
+
+
+void QmlGraphicsVideo::_q_nativeSizeChanged(const QSizeF &size)
+{
+ setImplicitWidth(size.width());
+ setImplicitHeight(size.height());
+}
+
+void QmlGraphicsVideo::_q_error(QMediaPlayer::Error errorCode, const QString &errorString)
+{
+ m_error = errorCode;
+ m_errorString = errorString;
+
+ emit error(Error(errorCode), errorString);
+ emit errorChanged();
+}
+
+
+/*!
+ \qmlclass Video QmlGraphicsVideo
+ \brief The Video element allows you to add videos to a scene.
+ \inherits Item
+*/
+
+/*!
+ \internal
+ \class QmlGraphicsVideo
+ \brief The QmlGraphicsVideo class provides a video item that you can add to a QmlView.
+*/
+
+QmlGraphicsVideo::QmlGraphicsVideo(QmlGraphicsItem *parent)
+ : QmlGraphicsItem(parent)
+ , m_graphicsItem(0)
+ , m_fillMode(QmlGraphicsVideo::PreserveAspectFit)
+
+{
+ m_graphicsItem = new QGraphicsVideoItem(this);
+ connect(m_graphicsItem, SIGNAL(nativeSizeChanged(QSizeF)),
+ this, SLOT(_q_nativeSizeChanged(QSizeF)));
+
+ setObject(this);
+
+ if (m_mediaService) {
+ connect(m_playerControl, SIGNAL(audioAvailableChanged(bool)),
+ this, SIGNAL(hasAudioChanged()));
+ connect(m_playerControl, SIGNAL(videoAvailableChanged(bool)),
+ this, SIGNAL(hasVideoChanged()));
+
+ m_graphicsItem->setMediaObject(m_mediaObject);
+ }
+}
+
+QmlGraphicsVideo::~QmlGraphicsVideo()
+{
+ shutdown();
+
+ delete m_graphicsItem;
+}
+
+/*!
+ \qmlproperty url Video::source
+
+ This property holds the source URL of the video.
+*/
+
+/*!
+ \qmlproperty bool Video::playing
+
+ This property holds whether the video is playing.
+*/
+
+/*!
+ \qmlproperty bool Video::paused
+
+ This property holds whether the video is paused.
+*/
+
+/*!
+ \qmlsignal Video::onStarted()
+
+ This handler is called when playback is started.
+*/
+
+/*!
+ \qmlsignal Video::onResumed()
+
+ This handler is called when playback is resumed from the paused state.
+*/
+
+/*!
+ \qmlsignal Video::onPaused()
+
+ This handler is called when playback is paused.
+*/
+
+/*!
+ \qmlsignal Video::onStopped()
+
+ This handler is called when playback is stopped.
+*/
+
+/*!
+ \qmlproperty enum Video::status
+
+ This property holds the status of video loading. It can be one of:
+
+ \list
+ \o NoMedia - no video has been set.
+ \o Loading - the video is currently being loaded.
+ \o Loaded - the video has been loaded.
+ \o Buffering - the video is buffering data.
+ \o Stalled - playback has been interrupted while the video is buffering data.
+ \o Buffered - the video has buffered data.
+ \o EndOfMedia - the video has played to the end.
+ \o InvalidMedia - the video cannot be played.
+ \o UnknownStatus - the status of the video is unknown.
+ \endlist
+*/
+
+QmlGraphicsVideo::Status QmlGraphicsVideo::status() const
+{
+ return Status(m_status);
+}
+
+/*!
+ \qmlsignal Video::onLoaded()
+
+ This handler is called when the video source has been loaded.
+*/
+
+/*!
+ \qmlsignal Video::onBuffering()
+
+ This handler is called when the video stream starts buffering.
+*/
+
+/*!
+ \qmlsignal Video::onStalled()
+
+ This handler is called when playback has stalled while the video stream buffers.
+*/
+
+/*!
+ \qmlsignal Video::onBuffered()
+
+ This handler is called when the video stream has finished buffering.
+*/
+
+/*!
+ \qmlsignal Video::onEndOfMedia
+
+ This handler is called when playback stops because end of the video has been reached.
+*/
+
+/*!
+ \qmlproperty int Video::duration
+
+ This property holds the duration of the video in milliseconds.
+
+ If the video doesn't have a fixed duration (a live stream for example) this will be 0.
+*/
+
+/*!
+ \qmlproperty int Video::position
+
+ This property holds the current playback position in milliseconds.
+*/
+
+/*!
+ \qmlproperty qreal Video::volume
+
+ This property holds the volume of the audio output, from 0.0 (silent) to 1.0 (maximum volume).
+*/
+
+/*!
+ \qmlproperty bool Video::muted
+
+ This property holds whether the audio output is muted.
+*/
+
+/*!
+ \qmlproperty bool Audio::hasAudio
+
+ This property holds whether the source contains audio.
+*/
+
+bool QmlGraphicsVideo::hasAudio() const
+{
+ return m_playerControl->isAudioAvailable();
+}
+
+/*!
+ \qmlproperty bool Video::hasVideo
+
+ This property holds whether the source contains video.
+*/
+
+bool QmlGraphicsVideo::hasVideo() const
+{
+ return m_playerControl->isVideoAvailable();
+}
+
+/*!
+ \qmlproperty qreal Video::bufferProgress
+
+ This property holds how much of the data buffer is currently filled, from 0.0 (empty) to 1.0
+ (full).
+*/
+
+/*!
+ \qmlproperty bool Video::seekable
+
+ This property holds whether position of the video can be changed.
+*/
+
+/*!
+ \qmlproperty qreal playbackRate
+
+ This property holds the rate at which video is played at as a multiple of the normal rate.
+*/
+
+/*!
+ \qmlproperty enum Video::error
+
+ This property holds the error state of the video. It can be one of:
+
+ \list
+ \o NoError - there is no current error.
+ \o ResourceError - the video cannot be played due to a problem allocating resources.
+ \o FormatError - the video format is not supported.
+ \o NetworkError - the video cannot be played due to network issues.
+ \o AccessDenied - the video cannot be played due to insufficient permissions.
+ \o ServiceMissing - the video cannot be played because the media service could not be
+ instantiated.
+ \endlist
+*/
+
+
+QmlGraphicsVideo::Error QmlGraphicsVideo::error() const
+{
+ return Error(m_error);
+}
+
+/*!
+ \qmlproperty string Video::errorString
+
+ This property holds a string describing the current error condition in more detail.
+*/
+
+/*!
+ \qmlproperty Video::onError(error, errorString)
+
+ This property is called when an \l {Error}{error} has occurred. The errorString parameter
+ may contain more detailed information about the error.
+*/
+
+/*!
+ \qmlproperty enum Video::FillMode
+
+ Set this property to define how the video is scaled to fit the target area.
+
+ \list
+ \o Stretch - the video is scaled to fit.
+ \o PreserveAspectFit - the video is scaled uniformly to fit without cropping
+ \o PreserveAspectCrop - the video is scaled uniformly to fill, cropping if necessary
+ \endlist
+*/
+
+QmlGraphicsVideo::FillMode QmlGraphicsVideo::fillMode() const
+{
+ return FillMode(m_graphicsItem->aspectRatioMode());
+}
+
+void QmlGraphicsVideo::setFillMode(FillMode mode)
+{
+ m_graphicsItem->setAspectRatioMode(Qt::AspectRatioMode(mode));
+}
+
+/*!
+ \qmlmethod Video::play()
+
+ Starts playback of the video.
+*/
+
+void QmlGraphicsVideo::play()
+{
+ m_playerControl->play();
+}
+
+/*!
+ \qmlmethod Video::pause()
+
+ Pauses playback of the video.
+*/
+
+void QmlGraphicsVideo::pause()
+{
+ m_playerControl->pause();
+}
+
+/*!
+ \qmlmethod Video::stop()
+
+ Stops playback of the video.
+*/
+
+void QmlGraphicsVideo::stop()
+{
+ m_playerControl->stop();
+}
+
+void QmlGraphicsVideo::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *)
+{
+}
+
+void QmlGraphicsVideo::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+{
+ m_graphicsItem->setSize(newGeometry.size());
+
+ QmlGraphicsItem::geometryChanged(newGeometry, oldGeometry);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qmlgraphicsvideo_p.cpp"
diff --git a/src/multimedia/qml/qmlgraphicsvideo_p.h b/src/multimedia/qml/qmlgraphicsvideo_p.h
new file mode 100644
index 0000000..d89de8c
--- /dev/null
+++ b/src/multimedia/qml/qmlgraphicsvideo_p.h
@@ -0,0 +1,197 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtMultimedia module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMLGRAPHICSVIDEO_H
+#define QMLGRAPHICSVIDEO_H
+
+#include <QtMultimedia/private/qmlmediabase_p.h>
+
+#include <QtMultimedia/qgraphicsvideoitem.h>
+
+#include <QtCore/qbasictimer.h>
+#include <QtDeclarative/qmlgraphicsitem.h>
+
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QTimerEvent;
+class QVideoSurfaceFormat;
+
+
+class QmlGraphicsVideo : public QmlGraphicsItem, public QmlMediaBase
+{
+ Q_OBJECT
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged)
+ 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(FillMode fillMode READ fillMode WRITE setFillMode)
+ Q_ENUMS(FillMode)
+ Q_ENUMS(Status)
+ Q_ENUMS(Error)
+public:
+ enum FillMode
+ {
+ Stretch = Qt::IgnoreAspectRatio,
+ PreserveAspectFit = Qt::KeepAspectRatio,
+ PreserveAspectCrop = Qt::KeepAspectRatioByExpanding
+ };
+
+ 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
+ };
+
+ QmlGraphicsVideo(QmlGraphicsItem *parent = 0);
+ ~QmlGraphicsVideo();
+
+ bool hasAudio() const;
+ bool hasVideo() const;
+
+ FillMode fillMode() const;
+ void setFillMode(FillMode mode);
+
+ Status status() const;
+ Error error() const;
+
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
+
+public Q_SLOTS:
+ void play();
+ void pause();
+ void stop();
+
+Q_SIGNALS:
+ void sourceChanged();
+
+ void playingChanged();
+ void pausedChanged();
+
+ void started();
+ void resumed();
+ void paused();
+ void stopped();
+
+ void statusChanged();
+
+ void loaded();
+ void buffering();
+ void stalled();
+ void buffered();
+ void endOfMedia();
+
+ void durationChanged();
+ void positionChanged();
+
+ void volumeChanged();
+ void mutedChanged();
+ void hasAudioChanged();
+ void hasVideoChanged();
+
+ void bufferProgressChanged();
+
+ void seekableChanged();
+ void playbackRateChanged();
+
+ void errorChanged();
+ void error(QmlGraphicsVideo::Error error, const QString &errorString);
+
+protected:
+ void geometryChanged(const QRectF &geometry, const QRectF &);
+
+private Q_SLOTS:
+ void _q_nativeSizeChanged(const QSizeF &size);
+ void _q_error(QMediaPlayer::Error, const QString &);
+
+private:
+ Q_DISABLE_COPY(QmlGraphicsVideo)
+
+ QGraphicsVideoItem *m_graphicsItem;
+
+ FillMode m_fillMode;
+ QRectF m_scaledRect;
+ bool m_updatePaintDevice;
+
+ Q_PRIVATE_SLOT(mediaBase(), void _q_stateChanged(QMediaPlayer::State))
+ Q_PRIVATE_SLOT(mediaBase(), void _q_mediaStatusChanged(QMediaPlayer::MediaStatus))
+ Q_PRIVATE_SLOT(mediaBase(), void _q_metaDataChanged())
+
+ inline QmlMediaBase *mediaBase() { return this; }
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QmlGraphicsVideo))
+
+QT_END_HEADER
+
+#endif
diff --git a/src/multimedia/qml/qmlmediabase.cpp b/src/multimedia/qml/qmlmediabase.cpp
new file mode 100644
index 0000000..0f0f1e4
--- /dev/null
+++ b/src/multimedia/qml/qmlmediabase.cpp
@@ -0,0 +1,379 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtMultimedia module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "QtMultimedia/private/qmlmediabase_p.h"
+
+#include <QtCore/qcoreevent.h>
+#include <QtCore/qurl.h>
+
+#include <QtMultimedia/qmediaplayercontrol.h>
+#include <QtMultimedia/qmediaservice.h>
+#include <QtMultimedia/qmediaserviceprovider.h>
+#include <QtMultimedia/qmetadatacontrol.h>
+#include <QtMultimedia/qmetadatacontrolmetaobject_p.h>
+
+
+
+QT_BEGIN_NAMESPACE
+
+
+class QmlMediaBaseObject : public QMediaObject
+{
+public:
+ QmlMediaBaseObject(QMediaService *service)
+ : QMediaObject(0, service)
+ {
+ }
+};
+
+class QmlMediaBasePlayerControl : public QMediaPlayerControl
+{
+public:
+ QmlMediaBasePlayerControl(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 100; }
+ 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 QmlMediaBaseAnimation : public QObject
+{
+public:
+ QmlMediaBaseAnimation(QmlMediaBase *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_state == QMediaPlayer::PlayingState)
+ emit m_media->positionChanged();
+ if (m_media->m_status == QMediaPlayer::BufferingMedia || QMediaPlayer::StalledMedia)
+ emit m_media->bufferProgressChanged();
+ } else {
+ QObject::timerEvent(event);
+ }
+ }
+
+private:
+ QmlMediaBase *m_media;
+ QBasicTimer m_timer;
+};
+
+void QmlMediaBase::_q_stateChanged(QMediaPlayer::State state)
+{
+ if (state != m_state) {
+ QMediaPlayer::State oldState = state;
+
+ m_state = state;
+
+ switch (state) {
+ case QMediaPlayer::PlayingState:
+ if (oldState == QMediaPlayer::StoppedState)
+ emit started();
+ else if (oldState == QMediaPlayer::PausedState)
+ emit resumed();
+ break;
+ case QMediaPlayer::PausedState:
+ emit paused();
+ case QMediaPlayer::StoppedState:
+ emit stopped();
+ break;
+ default:
+ break;
+ }
+
+ emit playingChanged();
+ emit pausedChanged();
+
+ if (m_state == QMediaPlayer::PlayingState
+ || m_status == QMediaPlayer::BufferingMedia
+ || m_status == QMediaPlayer::StalledMedia) {
+ m_animation->start();
+ } else {
+ m_animation->stop();
+ }
+ }
+}
+
+void QmlMediaBase::_q_mediaStatusChanged(QMediaPlayer::MediaStatus status)
+{
+ if (status != m_status) {
+ m_status = status;
+
+ switch (status) {
+ case QMediaPlayer::LoadedMedia:
+ emit loaded();
+ break;
+ case QMediaPlayer::BufferingMedia:
+ emit buffering();
+ break;
+ case QMediaPlayer::BufferedMedia:
+ emit buffered();
+ break;
+ case QMediaPlayer::StalledMedia:
+ emit stalled();
+ break;
+ case QMediaPlayer::EndOfMedia:
+ emit endOfMedia();
+ break;
+ default:
+ break;
+ }
+
+ emit statusChanged();
+
+ if (m_state == QMediaPlayer::PlayingState
+ || m_status == QMediaPlayer::BufferingMedia
+ || m_status == QMediaPlayer::StalledMedia) {
+ m_animation->start();
+ } else {
+ m_animation->stop();
+ }
+ }
+}
+
+void QmlMediaBase::_q_metaDataChanged()
+{
+ m_metaObject->metaDataChanged();
+}
+
+QmlMediaBase::QmlMediaBase()
+ : m_mediaService(0)
+ , m_playerControl(0)
+ , m_mediaObject(0)
+ , m_mediaProvider(0)
+ , m_metaDataControl(0)
+ , m_metaObject(0)
+ , m_animation(0)
+ , m_state(QMediaPlayer::StoppedState)
+ , m_status(QMediaPlayer::NoMedia)
+ , m_error(QMediaPlayer::NoError)
+{
+}
+
+QmlMediaBase::~QmlMediaBase()
+{
+}
+
+void QmlMediaBase::shutdown()
+{
+ delete m_metaObject;
+ delete m_mediaObject;
+
+ if (m_mediaProvider)
+ m_mediaProvider->releaseService(m_mediaService);
+
+ delete m_animation;
+
+}
+
+void QmlMediaBase::setObject(QObject *object)
+{
+ if ((m_mediaProvider = QMediaServiceProvider::defaultServiceProvider())) {
+ if ((m_mediaService = m_mediaProvider->requestService(Q_MEDIASERVICE_MEDIAPLAYER))) {
+ m_playerControl = qobject_cast<QMediaPlayerControl *>(
+ m_mediaService->control(QMediaPlayerControl_iid));
+ m_metaDataControl = qobject_cast<QMetaDataControl *>(
+ m_mediaService->control(QMetaDataControl_iid));
+ m_mediaObject = new QmlMediaBaseObject(m_mediaService);
+ }
+ }
+
+ if (m_playerControl) {
+ QObject::connect(m_playerControl, SIGNAL(stateChanged(QMediaPlayer::State)),
+ object, SLOT(_q_stateChanged(QMediaPlayer::State)));
+ QObject::connect(m_playerControl, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
+ object, SLOT(_q_mediaStatusChanged(QMediaPlayer::MediaStatus)));
+ 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()));
+
+ m_animation = new QmlMediaBaseAnimation(this);
+ } else {
+ m_playerControl = new QmlMediaBasePlayerControl(object);
+ }
+
+ if (m_metaDataControl) {
+ m_metaObject = new QMetaDataControlMetaObject(m_metaDataControl, object);
+
+ QObject::connect(m_metaDataControl, SIGNAL(metaDataChanged()),
+ object, SLOT(_q_metaDataChanged()));
+ }
+}
+
+QUrl QmlMediaBase::source() const
+{
+ return m_playerControl->media().canonicalUrl();
+}
+
+void QmlMediaBase::setSource(const QUrl &url)
+{
+ m_playerControl->setMedia(QMediaContent(url), 0);
+}
+
+bool QmlMediaBase::isPlaying() const
+{
+ return m_state != QMediaPlayer::StoppedState;
+}
+
+void QmlMediaBase::setPlaying(bool playing)
+{
+ if (playing && m_state == QMediaPlayer::StoppedState)
+ m_playerControl->play();
+ else if (!playing)
+ m_playerControl->stop();
+}
+
+bool QmlMediaBase::isPaused() const
+{
+ return m_state == QMediaPlayer::PausedState;
+}
+
+void QmlMediaBase::setPaused(bool paused)
+{
+ if (paused && m_state == QMediaPlayer::PlayingState)
+ m_playerControl->pause();
+ if (!paused && m_state == QMediaPlayer::PausedState)
+ m_playerControl->play();
+}
+
+int QmlMediaBase::duration() const
+{
+ return m_playerControl->duration();
+}
+
+int QmlMediaBase::position() const
+{
+ return m_playerControl->position();
+
+}
+
+void QmlMediaBase::setPosition(int position)
+{
+ m_playerControl->setPosition(position);
+}
+
+qreal QmlMediaBase::volume() const
+{
+ return qreal(m_playerControl->volume()) / 100;
+}
+
+void QmlMediaBase::setVolume(qreal volume)
+{
+ m_playerControl->setVolume(volume * 100);
+}
+
+bool QmlMediaBase::isMuted() const
+{
+ return m_playerControl->isMuted();
+}
+
+void QmlMediaBase::setMuted(bool muted)
+{
+ m_playerControl->setMuted(muted);
+}
+
+qreal QmlMediaBase::bufferProgress() const
+{
+ return qreal(m_playerControl->bufferStatus()) / 100;
+}
+
+bool QmlMediaBase::isSeekable() const
+{
+ return m_playerControl->isSeekable();
+}
+
+qreal QmlMediaBase::playbackRate() const
+{
+ return m_playerControl->playbackRate();
+}
+
+void QmlMediaBase::setPlaybackRate(qreal rate)
+{
+ m_playerControl->setPlaybackRate(rate);
+}
+
+QString QmlMediaBase::errorString() const
+{
+ return m_errorString;
+}
+
+QT_END_NAMESPACE
+