diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-12-15 17:24:21 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2021-01-20 15:11:26 +0000 |
commit | 3fcc619cb4300e2e07b3615b0b887938532c22cc (patch) | |
tree | c82b97737e9a6c141692744ec43c8763d8b8b461 | |
parent | 1aceb4feb8ffab96773d919fa49408af8dc24e12 (diff) |
Clean up playlist handling
Remove the whole plugin infrastructure and all the complexity
that came with it and some other architectural decisions.
Change-Id: I86bc2f1a5bddf5ba90881990c5cf49463d12ed65
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
39 files changed, 320 insertions, 3957 deletions
diff --git a/src/gsttools/qgstreamerplayercontrol.cpp b/src/gsttools/qgstreamerplayercontrol.cpp index 6edde7bb0..81e2eb6c4 100644 --- a/src/gsttools/qgstreamerplayercontrol.cpp +++ b/src/gsttools/qgstreamerplayercontrol.cpp @@ -40,8 +40,6 @@ #include <private/qgstreamerplayercontrol_p.h> #include <private/qgstreamerplayersession_p.h> -#include <private/qmediaplaylistnavigator_p.h> - #include <QtCore/qdir.h> #include <QtCore/qsocketnotifier.h> #include <QtCore/qurl.h> diff --git a/src/imports/multimedia/qdeclarativeplaylist.cpp b/src/imports/multimedia/qdeclarativeplaylist.cpp index 400e23467..29900730c 100644 --- a/src/imports/multimedia/qdeclarativeplaylist.cpp +++ b/src/imports/multimedia/qdeclarativeplaylist.cpp @@ -182,7 +182,6 @@ QDeclarativePlaylist::QDeclarativePlaylist(QObject *parent) : QAbstractListModel(parent) , m_playlist(0) , m_error(QMediaPlaylist::NoError) - , m_readOnly(false) { } @@ -264,18 +263,6 @@ int QDeclarativePlaylist::itemCount() const } /*! - \qmlproperty bool QtMultimedia::Playlist::readOnly - - This property indicates if the playlist can be modified. - */ -bool QDeclarativePlaylist::readOnly() const -{ - // There's no signal to tell whether or not the read only state changed, so we consider it fixed - // after its initial retrieval in componentComplete(). - return m_readOnly; -} - -/*! \qmlproperty enumeration QtMultimedia::Playlist::error This property holds the error condition of the playlist. @@ -418,9 +405,9 @@ bool QDeclarativePlaylist::save(const QUrl &location, const QString &format) Returns true if the \a source is added successfully. */ -bool QDeclarativePlaylist::addItem(const QUrl &source) +void QDeclarativePlaylist::addItem(const QUrl &source) { - return m_playlist->addMedia(QMediaContent(source)); + m_playlist->addMedia(QMediaContent(source)); } /*! @@ -432,10 +419,10 @@ bool QDeclarativePlaylist::addItem(const QUrl &source) \since 5.7 */ -bool QDeclarativePlaylist::addItems(const QList<QUrl> &sources) +void QDeclarativePlaylist::addItems(const QList<QUrl> &sources) { if (sources.isEmpty()) - return false; + return; QList<QMediaContent> contents; QList<QUrl>::const_iterator it = sources.constBegin(); @@ -443,7 +430,7 @@ bool QDeclarativePlaylist::addItems(const QList<QUrl> &sources) contents.push_back(QMediaContent(*it)); ++it; } - return m_playlist->addMedia(contents); + m_playlist->addMedia(contents); } /*! @@ -528,9 +515,9 @@ bool QDeclarativePlaylist::removeItems(int start, int end) Returns \c true if the operation is successful. */ -bool QDeclarativePlaylist::clear() +void QDeclarativePlaylist::clear() { - return m_playlist->clear(); + m_playlist->clear(); } int QDeclarativePlaylist::rowCount(const QModelIndex &parent) const @@ -582,11 +569,6 @@ void QDeclarativePlaylist::classBegin() this, SIGNAL(loaded())); connect(m_playlist, SIGNAL(loadFailed()), this, SLOT(_q_loadFailed())); - - if (m_playlist->isReadOnly()) { - m_readOnly = true; - emit readOnlyChanged(); - } } void QDeclarativePlaylist::componentComplete() diff --git a/src/imports/multimedia/qdeclarativeplaylist_p.h b/src/imports/multimedia/qdeclarativeplaylist_p.h index d086f26b5..8c3cce300 100644 --- a/src/imports/multimedia/qdeclarativeplaylist_p.h +++ b/src/imports/multimedia/qdeclarativeplaylist_p.h @@ -81,7 +81,6 @@ class QDeclarativePlaylist : public QAbstractListModel, public QQmlParserStatus Q_PROPERTY(QUrl currentItemSource READ currentItemSource NOTIFY currentItemSourceChanged) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(int itemCount READ itemCount NOTIFY itemCountChanged) - Q_PROPERTY(bool readOnly READ readOnly NOTIFY readOnlyChanged) Q_PROPERTY(Error error READ error NOTIFY errorChanged) Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) Q_PROPERTY(QQmlListProperty<QDeclarativePlaylistItem> items READ items DESIGNABLE false) @@ -97,7 +96,7 @@ public: CurrentItemInLoop = QMediaPlaylist::CurrentItemInLoop, Sequential = QMediaPlaylist::Sequential, Loop = QMediaPlaylist::Loop, - Random = QMediaPlaylist::Random +// Random = QMediaPlaylist::Random }; enum Error { @@ -121,7 +120,6 @@ public: int currentIndex() const; void setCurrentIndex(int currentIndex); int itemCount() const; - bool readOnly() const; Error error() const; QString errorString() const; QMediaPlaylist *mediaPlaylist() const { return m_playlist; } @@ -157,21 +155,20 @@ public Q_SLOTS: void shuffle(); void load(const QUrl &location, const QString &format = QString()); bool save(const QUrl &location, const QString &format = QString()); - bool addItem(const QUrl &source); - Q_REVISION(1) bool addItems(const QList<QUrl> &sources); + void addItem(const QUrl &source); + Q_REVISION(1) void addItems(const QList<QUrl> &sources); bool insertItem(int index, const QUrl &source); Q_REVISION(1) bool insertItems(int index, const QList<QUrl> &sources); Q_REVISION(1) bool moveItem(int from, int to); bool removeItem(int index); Q_REVISION(1) bool removeItems(int start, int end); - bool clear(); + void clear(); Q_SIGNALS: void playbackModeChanged(); void currentItemSourceChanged(); void currentIndexChanged(); void itemCountChanged(); - void readOnlyChanged(); void errorChanged(); void itemAboutToBeInserted(int start, int end); @@ -198,7 +195,6 @@ private: QMediaPlaylist *m_playlist; QString m_errorString; QMediaPlaylist::Error m_error; - bool m_readOnly; }; QT_END_NAMESPACE diff --git a/src/multimedia/controls/controls.pri b/src/multimedia/controls/controls.pri index 37e13398b..e1fedc7ed 100644 --- a/src/multimedia/controls/controls.pri +++ b/src/multimedia/controls/controls.pri @@ -34,9 +34,6 @@ PUBLIC_HEADERS += \ controls/qaudiorolecontrol.h \ controls/qcustomaudiorolecontrol.h -PRIVATE_HEADERS += \ - controls/qmediaplaylistcontrol_p.h \ - SOURCES += \ controls/qcameracapturebufferformatcontrol.cpp \ controls/qcameracapturedestinationcontrol.cpp \ @@ -53,7 +50,6 @@ SOURCES += \ controls/qimageencodercontrol.cpp \ controls/qmediacontainercontrol.cpp \ controls/qmediaplayercontrol.cpp \ - controls/qmediaplaylistcontrol.cpp \ controls/qmediarecordercontrol.cpp \ controls/qmediastreamscontrol.cpp \ controls/qmetadatareadercontrol.cpp \ diff --git a/src/multimedia/controls/qmediaplaylistcontrol.cpp b/src/multimedia/controls/qmediaplaylistcontrol.cpp deleted file mode 100644 index 61e20e170..000000000 --- a/src/multimedia/controls/qmediaplaylistcontrol.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "qmediaplaylistcontrol_p.h" -#include "qmediacontrol_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QMediaPlaylistControl - \internal - - \inmodule QtMultimedia - - - \ingroup multimedia_control - - - \brief The QMediaPlaylistControl class provides access to the playlist - functionality of a QMediaService. - - If a QMediaService contains an internal playlist it will implement - QMediaPlaylistControl. This control provides access to the contents of the - \l {playlistProvider()}{playlist}, as well as the \l - {currentIndex()}{position} of the current media, and a means of navigating - to the \l {next()}{next} and \l {previous()}{previous} media. - - The functionality provided by the control is exposed to application code - through the QMediaPlaylist class. - - The interface name of QMediaPlaylistControl is \c org.qt-project.qt.mediaplaylistcontrol/5.0 as - defined in QMediaPlaylistControl_iid. - - \sa QMediaService::requestControl(), QMediaPlayer -*/ - -/*! - \macro QMediaPlaylistControl_iid - - \c org.qt-project.qt.mediaplaylistcontrol/5.0 - - Defines the interface name of the QMediaPlaylistControl class. - - \relates QMediaPlaylistControl -*/ - -/*! - Create a new playlist control object with the given \a parent. -*/ -QMediaPlaylistControl::QMediaPlaylistControl(QObject *parent): - QMediaControl(*new QMediaControlPrivate, parent) -{ -} - -/*! - Destroys the playlist control. -*/ -QMediaPlaylistControl::~QMediaPlaylistControl() -{ -} - - -/*! - \fn QMediaPlaylistControl::playlistProvider() const - - Returns the playlist used by this media player. -*/ - -/*! - \fn QMediaPlaylistControl::setPlaylistProvider(QMediaPlaylistProvider *playlist) - - Set the playlist of this media player to \a playlist. - - In many cases it is possible just to use the playlist - constructed by player, but sometimes replacing the whole - playlist allows to avoid copyting of all the items bettween playlists. - - Returns true if player can use this passed playlist; otherwise returns false. - -*/ - -/*! - \fn QMediaPlaylistControl::currentIndex() const - - Returns position of the current media source in the playlist. -*/ - -/*! - \fn QMediaPlaylistControl::setCurrentIndex(int position) - - Jump to the item at the given \a position. -*/ - -/*! - \fn QMediaPlaylistControl::nextIndex(int step) const - - Returns the index of item, which were current after calling next() - \a step times. - - Returned value depends on the size of playlist, current position - and playback mode. - - \sa QMediaPlaylist::playbackMode -*/ - -/*! - \fn QMediaPlaylistControl::previousIndex(int step) const - - Returns the index of item, which were current after calling previous() - \a step times. - - \sa QMediaPlaylist::playbackMode -*/ - -/*! - \fn QMediaPlaylistControl::next() - - Moves to the next item in playlist. -*/ - -/*! - \fn QMediaPlaylistControl::previous() - - Returns to the previous item in playlist. -*/ - -/*! - \fn QMediaPlaylistControl::playbackMode() const - - Returns the playlist navigation mode. - - \sa QMediaPlaylist::PlaybackMode -*/ - -/*! - \fn QMediaPlaylistControl::setPlaybackMode(QMediaPlaylist::PlaybackMode mode) - - Sets the playback \a mode. - - \sa QMediaPlaylist::PlaybackMode -*/ - -/*! - \fn QMediaPlaylistControl::playlistProviderChanged() - - Signal emitted when the playlist provider has changed. -*/ - -/*! - \fn QMediaPlaylistControl::currentIndexChanged(int position) - - Signal emitted when the playlist \a position is changed. -*/ - -/*! - \fn QMediaPlaylistControl::playbackModeChanged(QMediaPlaylist::PlaybackMode mode) - - Signal emitted when the playback \a mode is changed. -*/ - -/*! - \fn QMediaPlaylistControl::currentMediaChanged(const QMediaContent& content) - - Signal emitted when current media changes to \a content. -*/ - -QT_END_NAMESPACE - -#include "moc_qmediaplaylistcontrol_p.cpp" diff --git a/src/multimedia/controls/qmediaplaylistcontrol_p.h b/src/multimedia/controls/qmediaplaylistcontrol_p.h deleted file mode 100644 index 93c5a3e25..000000000 --- a/src/multimedia/controls/qmediaplaylistcontrol_p.h +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#ifndef QMEDIAPLAYLISTCONTROL_P_H -#define QMEDIAPLAYLISTCONTROL_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtCore/qobject.h> -#include "qmediacontrol.h" -#include <private/qmediaplaylistnavigator_p.h> - - -QT_BEGIN_NAMESPACE - - -class QMediaPlaylistProvider; - -class Q_MULTIMEDIA_EXPORT QMediaPlaylistControl : public QMediaControl -{ - Q_OBJECT - -public: - virtual ~QMediaPlaylistControl(); - - virtual QMediaPlaylistProvider* playlistProvider() const = 0; - virtual bool setPlaylistProvider(QMediaPlaylistProvider *playlist) = 0; - - virtual int currentIndex() const = 0; - virtual void setCurrentIndex(int position) = 0; - virtual int nextIndex(int steps) const = 0; - virtual int previousIndex(int steps) const = 0; - - virtual void next() = 0; - virtual void previous() = 0; - - virtual QMediaPlaylist::PlaybackMode playbackMode() const = 0; - virtual void setPlaybackMode(QMediaPlaylist::PlaybackMode mode) = 0; - -Q_SIGNALS: - void playlistProviderChanged(); - void currentIndexChanged(int position); - void currentMediaChanged(const QMediaContent&); - void playbackModeChanged(QMediaPlaylist::PlaybackMode mode); - -protected: - QMediaPlaylistControl(QObject *parent = nullptr); -}; - -#define QMediaPlaylistControl_iid "org.qt-project.qt.mediaplaylistcontrol/5.0" -Q_MEDIA_DECLARE_CONTROL(QMediaPlaylistControl, QMediaPlaylistControl_iid) - -QT_END_NAMESPACE - - -#endif // QMEDIAPLAYLISTCONTROL_P_H diff --git a/src/multimedia/playback/playback.pri b/src/multimedia/playback/playback.pri index 81a3b298f..4ab4b05c9 100644 --- a/src/multimedia/playback/playback.pri +++ b/src/multimedia/playback/playback.pri @@ -7,18 +7,10 @@ PUBLIC_HEADERS += \ PRIVATE_HEADERS += \ playback/qmediaplaylist_p.h \ - playback/qmediaplaylistprovider_p.h \ - playback/qmediaplaylistioplugin_p.h \ - playback/qmediaplaylistnavigator_p.h \ - playback/qmedianetworkplaylistprovider_p.h \ playback/qplaylistfileparser_p.h SOURCES += \ - playback/qmedianetworkplaylistprovider.cpp \ playback/qmediacontent.cpp \ playback/qmediaplayer.cpp \ playback/qmediaplaylist.cpp \ - playback/qmediaplaylistioplugin.cpp \ - playback/qmediaplaylistnavigator.cpp \ - playback/qmediaplaylistprovider.cpp \ playback/qplaylistfileparser.cpp diff --git a/src/multimedia/playback/qmedianetworkplaylistprovider.cpp b/src/multimedia/playback/qmedianetworkplaylistprovider.cpp deleted file mode 100644 index 03bdb0e73..000000000 --- a/src/multimedia/playback/qmedianetworkplaylistprovider.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmedianetworkplaylistprovider_p.h" -#include "qmediaplaylistprovider_p.h" -#include "qmediacontent.h" -#include "qmediaobject_p.h" -#include "qplaylistfileparser_p.h" -#include "qrandom.h" - -QT_BEGIN_NAMESPACE - -class QMediaNetworkPlaylistProviderPrivate: public QMediaPlaylistProviderPrivate -{ - Q_DECLARE_NON_CONST_PUBLIC(QMediaNetworkPlaylistProvider) -public: - bool load(const QNetworkRequest &request); - - QPlaylistFileParser parser; - QList<QMediaContent> resources; - - void _q_handleParserError(QPlaylistFileParser::ParserError err, const QString &); - void _q_handleNewItem(const QVariant& content); - - QMediaNetworkPlaylistProvider *q_ptr; -}; - -bool QMediaNetworkPlaylistProviderPrivate::load(const QNetworkRequest &request) -{ - parser.abort(); - parser.start(request); - - return true; -} - -void QMediaNetworkPlaylistProviderPrivate::_q_handleParserError(QPlaylistFileParser::ParserError err, const QString &errorMessage) -{ - Q_Q(QMediaNetworkPlaylistProvider); - - QMediaPlaylist::Error playlistError = QMediaPlaylist::NoError; - - switch (err) { - case QPlaylistFileParser::NoError: - return; - case QPlaylistFileParser::FormatError: - playlistError = QMediaPlaylist::FormatError; - break; - case QPlaylistFileParser::FormatNotSupportedError: - playlistError = QMediaPlaylist::FormatNotSupportedError; - break; - case QPlaylistFileParser::ResourceError: - // fall through - case QPlaylistFileParser::NetworkError: - playlistError = QMediaPlaylist::NetworkError; - break; - } - - parser.abort(); - - emit q->loadFailed(playlistError, errorMessage); -} - -void QMediaNetworkPlaylistProviderPrivate::_q_handleNewItem(const QVariant& content) -{ - Q_Q(QMediaNetworkPlaylistProvider); - - QUrl url; - switch (content.metaType().id() ) { - case QMetaType::QUrl: - url = content.toUrl(); - break; - case QMetaType::QVariantMap: - url = content.toMap().value(QLatin1String("url")).toUrl(); - break; - default: - return; - } - - q->addMedia(QMediaContent(url)); -} - -QMediaNetworkPlaylistProvider::QMediaNetworkPlaylistProvider(QObject *parent) - :QMediaPlaylistProvider(*new QMediaNetworkPlaylistProviderPrivate, parent) -{ - d_func()->q_ptr = this; - connect(&d_func()->parser, SIGNAL(newItem(QVariant)), - this, SLOT(_q_handleNewItem(QVariant))); - connect(&d_func()->parser, SIGNAL(finished()), this, SIGNAL(loaded())); - connect(&d_func()->parser, SIGNAL(error(QPlaylistFileParser::ParserError,QString)), - this, SLOT(_q_handleParserError(QPlaylistFileParser::ParserError,QString))); -} - -QMediaNetworkPlaylistProvider::~QMediaNetworkPlaylistProvider() -{ -} - -bool QMediaNetworkPlaylistProvider::isReadOnly() const -{ - return false; -} - -bool QMediaNetworkPlaylistProvider::load(const QNetworkRequest &request, const char *format) -{ - Q_UNUSED(format); - return d_func()->load(request); -} - -int QMediaNetworkPlaylistProvider::mediaCount() const -{ - return d_func()->resources.size(); -} - -QMediaContent QMediaNetworkPlaylistProvider::media(int pos) const -{ - return d_func()->resources.value(pos); -} - -bool QMediaNetworkPlaylistProvider::addMedia(const QMediaContent &content) -{ - Q_D(QMediaNetworkPlaylistProvider); - - int pos = d->resources.count(); - - emit mediaAboutToBeInserted(pos, pos); - d->resources.append(content); - emit mediaInserted(pos, pos); - - return true; -} - -bool QMediaNetworkPlaylistProvider::addMedia(const QList<QMediaContent> &items) -{ - Q_D(QMediaNetworkPlaylistProvider); - - if (items.isEmpty()) - return true; - - int pos = d->resources.count(); - int end = pos+items.count()-1; - - emit mediaAboutToBeInserted(pos, end); - d->resources.append(items); - emit mediaInserted(pos, end); - - return true; -} - - -bool QMediaNetworkPlaylistProvider::insertMedia(int pos, const QMediaContent &content) -{ - Q_D(QMediaNetworkPlaylistProvider); - - emit mediaAboutToBeInserted(pos, pos); - d->resources.insert(pos, content); - emit mediaInserted(pos,pos); - - return true; -} - -bool QMediaNetworkPlaylistProvider::insertMedia(int pos, const QList<QMediaContent> &items) -{ - Q_D(QMediaNetworkPlaylistProvider); - - if (items.isEmpty()) - return true; - - const int last = pos+items.count()-1; - - emit mediaAboutToBeInserted(pos, last); - for (int i=0; i<items.count(); i++) - d->resources.insert(pos+i, items.at(i)); - emit mediaInserted(pos, last); - - return true; -} - -bool QMediaNetworkPlaylistProvider::moveMedia(int from, int to) -{ - Q_D(QMediaNetworkPlaylistProvider); - - Q_ASSERT(from >= 0 && from < mediaCount()); - Q_ASSERT(to >= 0 && to < mediaCount()); - - if (from == to) - return false; - - const QMediaContent media = d->resources.at(from); - return removeMedia(from, from) && insertMedia(to, media); -} - -bool QMediaNetworkPlaylistProvider::removeMedia(int fromPos, int toPos) -{ - Q_D(QMediaNetworkPlaylistProvider); - - Q_ASSERT(fromPos >= 0); - Q_ASSERT(fromPos <= toPos); - Q_ASSERT(toPos < mediaCount()); - - emit mediaAboutToBeRemoved(fromPos, toPos); - d->resources.erase(d->resources.begin()+fromPos, d->resources.begin()+toPos+1); - emit mediaRemoved(fromPos, toPos); - - return true; -} - -bool QMediaNetworkPlaylistProvider::removeMedia(int pos) -{ - Q_D(QMediaNetworkPlaylistProvider); - - emit mediaAboutToBeRemoved(pos, pos); - d->resources.removeAt(pos); - emit mediaRemoved(pos, pos); - - return true; -} - -bool QMediaNetworkPlaylistProvider::clear() -{ - Q_D(QMediaNetworkPlaylistProvider); - if (!d->resources.isEmpty()) { - int lastPos = mediaCount()-1; - emit mediaAboutToBeRemoved(0, lastPos); - d->resources.clear(); - emit mediaRemoved(0, lastPos); - } - - return true; -} - -void QMediaNetworkPlaylistProvider::shuffle() -{ - Q_D(QMediaNetworkPlaylistProvider); - if (!d->resources.isEmpty()) { - QList<QMediaContent> resources; - - while (!d->resources.isEmpty()) { - resources.append(d->resources.takeAt(QRandomGenerator::global()->bounded(int(d->resources.size())))); - } - - d->resources = resources; - emit mediaChanged(0, mediaCount()-1); - } - -} - -QT_END_NAMESPACE - -#include "moc_qmedianetworkplaylistprovider_p.cpp" diff --git a/src/multimedia/playback/qmedianetworkplaylistprovider_p.h b/src/multimedia/playback/qmedianetworkplaylistprovider_p.h deleted file mode 100644 index 6b5220935..000000000 --- a/src/multimedia/playback/qmedianetworkplaylistprovider_p.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIANETWORKPAYLISTPROVIDER_P_H -#define QMEDIANETWORKPAYLISTPROVIDER_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qmediaplaylistprovider_p.h" - -QT_BEGIN_NAMESPACE - - -class QMediaNetworkPlaylistProviderPrivate; -class Q_MULTIMEDIA_EXPORT QMediaNetworkPlaylistProvider : public QMediaPlaylistProvider -{ - Q_OBJECT -public: - QMediaNetworkPlaylistProvider(QObject *parent = nullptr); - ~QMediaNetworkPlaylistProvider(); - - bool load(const QNetworkRequest &request, const char *format = nullptr) override; - - int mediaCount() const override; - QMediaContent media(int pos) const override; - - bool isReadOnly() const override; - - bool addMedia(const QMediaContent &content) override; - bool addMedia(const QList<QMediaContent> &items) override; - bool insertMedia(int pos, const QMediaContent &content) override; - bool insertMedia(int pos, const QList<QMediaContent> &items) override; - bool moveMedia(int from, int to) override; - bool removeMedia(int pos) override; - bool removeMedia(int start, int end) override; - bool clear() override; - -public Q_SLOTS: - void shuffle() override; - -private: - Q_DISABLE_COPY(QMediaNetworkPlaylistProvider) - Q_DECLARE_PRIVATE(QMediaNetworkPlaylistProvider) - Q_PRIVATE_SLOT(d_func(), void _q_handleParserError(QPlaylistFileParser::ParserError err, const QString &)) - Q_PRIVATE_SLOT(d_func(), void _q_handleNewItem(const QVariant& content)) -}; - -QT_END_NAMESPACE - - -#endif // QMEDIANETWORKPAYLISTSOURCE_P_H diff --git a/src/multimedia/playback/qmediaplayer.cpp b/src/multimedia/playback/qmediaplayer.cpp index 850ed69b9..6cbb68c1d 100644 --- a/src/multimedia/playback/qmediaplayer.cpp +++ b/src/multimedia/playback/qmediaplayer.cpp @@ -46,7 +46,6 @@ #include <qmediaplayercontrol.h> #include <qmediaserviceprovider_p.h> #include <qmediaplaylist.h> -#include <qmediaplaylistcontrol_p.h> #include <qaudiorolecontrol.h> #include <qcustomaudiorolecontrol.h> diff --git a/src/multimedia/playback/qmediaplaylist.cpp b/src/multimedia/playback/qmediaplaylist.cpp index 9539a1809..3aafe8687 100644 --- a/src/multimedia/playback/qmediaplaylist.cpp +++ b/src/multimedia/playback/qmediaplaylist.cpp @@ -39,12 +39,9 @@ #include "qmediaplaylist.h" #include "qmediaplaylist_p.h" -#include "qmediaplaylistprovider_p.h" -#include "qmediaplaylistioplugin_p.h" -#include "qmedianetworkplaylistprovider_p.h" #include "qmediaservice.h" -#include "qmediaplaylistcontrol_p.h" #include "qmediaplayercontrol.h" +#include "qplaylistfileparser_p.h" #include <QtCore/qlist.h> #include <QtCore/qfile.h> @@ -56,17 +53,83 @@ QT_BEGIN_NAMESPACE -Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, playlistIOLoader, - (QMediaPlaylistIOInterface_iid, QLatin1String("playlistformats"), Qt::CaseInsensitive)) +class QM3uPlaylistWriter +{ +public: + QM3uPlaylistWriter(QIODevice *device) + :m_device(device), m_textStream(new QTextStream(m_device)) + { + } + + ~QM3uPlaylistWriter() + { + delete m_textStream; + } + + bool writeItem(const QMediaContent& item) + { + *m_textStream << item.request().url().toString() << Qt::endl; + return true; + } -static void qRegisterMediaPlaylistMetaTypes() +private: + QIODevice *m_device; + QTextStream *m_textStream; +}; + + +int QMediaPlaylistPrivate::nextPosition(int steps) const { - qRegisterMetaType<QMediaPlaylist::Error>(); - qRegisterMetaType<QMediaPlaylist::PlaybackMode>(); -} + if (playlist.count() == 0) + return -1; + + int next = currentPos + steps; -Q_CONSTRUCTOR_FUNCTION(qRegisterMediaPlaylistMetaTypes) + switch (playbackMode) { + case QMediaPlaylist::CurrentItemOnce: + return steps != 0 ? -1 : currentPos; + case QMediaPlaylist::CurrentItemInLoop: + return currentPos; + case QMediaPlaylist::Sequential: + if (next >= playlist.size()) + next = -1; + break; + case QMediaPlaylist::Loop: + next %= playlist.count(); + break; + } + + return next; +} + +int QMediaPlaylistPrivate::prevPosition(int steps) const +{ + if (playlist.count() == 0) + return -1; + + int next = currentPos; + if (next < 0) + next = playlist.size(); + next -= steps; + + switch (playbackMode) { + case QMediaPlaylist::CurrentItemOnce: + return steps != 0 ? -1 : currentPos; + case QMediaPlaylist::CurrentItemInLoop: + return currentPos; + case QMediaPlaylist::Sequential: + if (next < 0) + next = -1; + break; + case QMediaPlaylist::Loop: + next %= playlist.size(); + if (next < 0) + next += playlist.size(); + break; + } + return next; +} /*! \class QMediaPlaylist @@ -88,6 +151,8 @@ Q_CONSTRUCTOR_FUNCTION(qRegisterMediaPlaylistMetaTypes) Depending on playlist source implementation, most of the playlist mutating operations can be asynchronous. + QMediaPlayList currently supports M3U playlists (file extension .m3u and .m3u8). + \sa QMediaContent */ @@ -122,8 +187,6 @@ QMediaPlaylist::QMediaPlaylist(QObject *parent) Q_D(QMediaPlaylist); d->q_ptr = this; - d->networkPlaylistControl = new QMediaNetworkPlaylistControl(this); - setMediaObject(nullptr); } @@ -159,87 +222,6 @@ bool QMediaPlaylist::setMediaObject(QMediaObject *mediaObject) { Q_D(QMediaPlaylist); - if (mediaObject && mediaObject == d->mediaObject) - return true; - - QMediaService *service = mediaObject - ? mediaObject->service() : nullptr; - - QMediaPlaylistControl *newControl = nullptr; - - if (service) - newControl = qobject_cast<QMediaPlaylistControl*>(service->requestControl(QMediaPlaylistControl_iid)); - - if (!newControl) - newControl = d->networkPlaylistControl; - - if (d->control != newControl) { - int removedStart = -1; - int removedEnd = -1; - int insertedStart = -1; - int insertedEnd = -1; - - if (d->control) { - QMediaPlaylistProvider *playlist = d->control->playlistProvider(); - disconnect(playlist, SIGNAL(loadFailed(QMediaPlaylist::Error,QString)), - this, SLOT(_q_loadFailed(QMediaPlaylist::Error,QString))); - - disconnect(playlist, &QMediaPlaylistProvider::mediaChanged, this, &QMediaPlaylist::mediaChanged); - disconnect(playlist, &QMediaPlaylistProvider::mediaAboutToBeInserted, this, &QMediaPlaylist::mediaAboutToBeInserted); - disconnect(playlist, &QMediaPlaylistProvider::mediaInserted, this, &QMediaPlaylist::mediaInserted); - disconnect(playlist, &QMediaPlaylistProvider::mediaAboutToBeRemoved, this, &QMediaPlaylist::mediaAboutToBeRemoved); - disconnect(playlist, &QMediaPlaylistProvider::mediaRemoved, this, &QMediaPlaylist::mediaRemoved); - - disconnect(playlist, &QMediaPlaylistProvider::loaded, this, &QMediaPlaylist::loaded); - - disconnect(d->control, &QMediaPlaylistControl::playbackModeChanged, - this, &QMediaPlaylist::playbackModeChanged); - disconnect(d->control, &QMediaPlaylistControl::currentIndexChanged, - this, &QMediaPlaylist::currentIndexChanged); - disconnect(d->control, &QMediaPlaylistControl::currentMediaChanged, - this, &QMediaPlaylist::currentMediaChanged); - - // Copy playlist items, sync playback mode and sync current index between - // old control and new control - d->syncControls(d->control, newControl, - &removedStart, &removedEnd, - &insertedStart, &insertedEnd); - - if (d->mediaObject) - d->mediaObject->service()->releaseControl(d->control); - } - - d->control = newControl; - QMediaPlaylistProvider *playlist = d->control->playlistProvider(); - connect(playlist, SIGNAL(loadFailed(QMediaPlaylist::Error,QString)), - this, SLOT(_q_loadFailed(QMediaPlaylist::Error,QString))); - - connect(playlist, &QMediaPlaylistProvider::mediaChanged, this, &QMediaPlaylist::mediaChanged); - connect(playlist, &QMediaPlaylistProvider::mediaAboutToBeInserted, this, &QMediaPlaylist::mediaAboutToBeInserted); - connect(playlist, &QMediaPlaylistProvider::mediaInserted, this, &QMediaPlaylist::mediaInserted); - connect(playlist, &QMediaPlaylistProvider::mediaAboutToBeRemoved, this, &QMediaPlaylist::mediaAboutToBeRemoved); - connect(playlist, &QMediaPlaylistProvider::mediaRemoved, this, &QMediaPlaylist::mediaRemoved); - - connect(playlist, &QMediaPlaylistProvider::loaded, this, &QMediaPlaylist::loaded); - - connect(d->control, &QMediaPlaylistControl::playbackModeChanged, - this, &QMediaPlaylist::playbackModeChanged); - connect(d->control, &QMediaPlaylistControl::currentIndexChanged, - this, &QMediaPlaylist::currentIndexChanged); - connect(d->control, &QMediaPlaylistControl::currentMediaChanged, - this, &QMediaPlaylist::currentMediaChanged); - - if (removedStart != -1 && removedEnd != -1) { - emit mediaAboutToBeRemoved(removedStart, removedEnd); - emit mediaRemoved(removedStart, removedEnd); - } - - if (insertedStart != -1 && insertedEnd != -1) { - emit mediaAboutToBeInserted(insertedStart, insertedEnd); - emit mediaInserted(insertedStart, insertedEnd); - } - } - d->mediaObject = mediaObject; return true; @@ -255,13 +237,19 @@ bool QMediaPlaylist::setMediaObject(QMediaObject *mediaObject) QMediaPlaylist::PlaybackMode QMediaPlaylist::playbackMode() const { - return d_func()->control->playbackMode(); + return d_func()->playbackMode; } void QMediaPlaylist::setPlaybackMode(QMediaPlaylist::PlaybackMode mode) { Q_D(QMediaPlaylist); - d->control->setPlaybackMode(mode); + + if (mode == d->playbackMode) + return; + + d->playbackMode = mode; + + emit playbackModeChanged(mode); } /*! @@ -269,7 +257,7 @@ void QMediaPlaylist::setPlaybackMode(QMediaPlaylist::PlaybackMode mode) */ int QMediaPlaylist::currentIndex() const { - return d_func()->control->currentIndex(); + return d_func()->currentPos; } /*! @@ -278,7 +266,10 @@ int QMediaPlaylist::currentIndex() const QMediaContent QMediaPlaylist::currentMedia() const { - return d_func()->playlist()->media(currentIndex()); + Q_D(const QMediaPlaylist); + if (d->currentPos < 0 || d->currentPos >= d->playlist.size()) + return QMediaContent(); + return d_func()->playlist.at(d_func()->currentPos); } /*! @@ -292,7 +283,7 @@ QMediaContent QMediaPlaylist::currentMedia() const */ int QMediaPlaylist::nextIndex(int steps) const { - return d_func()->control->nextIndex(steps); + return d_func()->nextPosition(steps); } /*! @@ -304,7 +295,7 @@ int QMediaPlaylist::nextIndex(int steps) const int QMediaPlaylist::previousIndex(int steps) const { - return d_func()->control->previousIndex(steps); + return d_func()->prevPosition(steps); } @@ -315,7 +306,7 @@ int QMediaPlaylist::previousIndex(int steps) const */ int QMediaPlaylist::mediaCount() const { - return d_func()->playlist()->mediaCount(); + return d_func()->playlist.count(); } /*! @@ -329,22 +320,15 @@ bool QMediaPlaylist::isEmpty() const } /*! - Returns true if the playlist can be modified, otherwise returns false. - - \sa mediaCount() - */ -bool QMediaPlaylist::isReadOnly() const -{ - return d_func()->playlist()->isReadOnly(); -} - -/*! Returns the media content at \a index in the playlist. */ QMediaContent QMediaPlaylist::media(int index) const { - return d_func()->playlist()->media(index); + Q_D(const QMediaPlaylist); + if (index < 0 || index >= d->playlist.size()) + return QMediaContent(); + return d->playlist.at(index); } /*! @@ -352,9 +336,13 @@ QMediaContent QMediaPlaylist::media(int index) const Returns true if the operation is successful, otherwise returns false. */ -bool QMediaPlaylist::addMedia(const QMediaContent &content) +void QMediaPlaylist::addMedia(const QMediaContent &content) { - return d_func()->control->playlistProvider()->addMedia(content); + Q_D(QMediaPlaylist); + int pos = d->playlist.size(); + emit mediaAboutToBeInserted(pos, pos); + d->playlist.append(content); + emit mediaInserted(pos, pos); } /*! @@ -362,9 +350,17 @@ bool QMediaPlaylist::addMedia(const QMediaContent &content) Returns true if the operation is successful, otherwise returns false. */ -bool QMediaPlaylist::addMedia(const QList<QMediaContent> &items) +void QMediaPlaylist::addMedia(const QList<QMediaContent> &items) { - return d_func()->control->playlistProvider()->addMedia(items); + if (!items.size()) + return; + + Q_D(QMediaPlaylist); + int first = d->playlist.size(); + int last = first + items.size() - 1; + emit mediaAboutToBeInserted(first, last); + d_func()->playlist.append(items); + emit mediaInserted(first, last); } /*! @@ -375,8 +371,12 @@ bool QMediaPlaylist::addMedia(const QList<QMediaContent> &items) bool QMediaPlaylist::insertMedia(int pos, const QMediaContent &content) { - QMediaPlaylistProvider *playlist = d_func()->playlist(); - return playlist->insertMedia(qBound(0, pos, playlist->mediaCount()), content); + Q_D(QMediaPlaylist); + pos = qBound(0, pos, d->playlist.size()); + emit mediaAboutToBeInserted(pos, pos); + d->playlist.insert(pos, content); + emit mediaInserted(pos, pos); + return true; } /*! @@ -387,8 +387,19 @@ bool QMediaPlaylist::insertMedia(int pos, const QMediaContent &content) bool QMediaPlaylist::insertMedia(int pos, const QList<QMediaContent> &items) { - QMediaPlaylistProvider *playlist = d_func()->playlist(); - return playlist->insertMedia(qBound(0, pos, playlist->mediaCount()), items); + if (!items.size()) + return true; + + Q_D(QMediaPlaylist); + pos = qBound(0, pos, d->playlist.size()); + int last = pos + items.size() - 1; + emit mediaAboutToBeInserted(pos, last); + auto newList = d->playlist.mid(0, pos); + newList += items; + newList += d->playlist.mid(pos); + d->playlist = newList; + emit mediaInserted(pos, last); + return true; } /*! @@ -400,9 +411,14 @@ bool QMediaPlaylist::insertMedia(int pos, const QList<QMediaContent> &items) */ bool QMediaPlaylist::moveMedia(int from, int to) { - QMediaPlaylistProvider *playlist = d_func()->playlist(); - return playlist->moveMedia(qBound(0, from, playlist->mediaCount()), - qBound(0, to, playlist->mediaCount())); + Q_D(QMediaPlaylist); + if (from < 0 || from > d->playlist.count() || + to < 0 || to > d->playlist.count()) + return false; + + d->playlist.move(from, to); + emit mediaChanged(from, to); + return true; } /*! @@ -412,11 +428,7 @@ bool QMediaPlaylist::moveMedia(int from, int to) */ bool QMediaPlaylist::removeMedia(int pos) { - QMediaPlaylistProvider *playlist = d_func()->playlist(); - if (pos >= 0 && pos < playlist->mediaCount()) - return playlist->removeMedia(pos); - else - return false; + return removeMedia(pos, pos); } /*! @@ -426,13 +438,16 @@ bool QMediaPlaylist::removeMedia(int pos) */ bool QMediaPlaylist::removeMedia(int start, int end) { - QMediaPlaylistProvider *playlist = d_func()->playlist(); - start = qMax(0, start); - end = qMin(end, playlist->mediaCount() - 1); - if (start <= end) - return playlist->removeMedia(start, end); - else + Q_D(QMediaPlaylist); + if (end < start || end < 0 || start >= d->playlist.count()) return false; + start = qBound(0, start, d->playlist.size() - 1); + end = qBound(0, end, d->playlist.size() - 1); + + emit mediaAboutToBeRemoved(start, end); + d->playlist.remove(start, end - start + 1); + emit mediaRemoved(start, end); + return true; } /*! @@ -440,77 +455,13 @@ bool QMediaPlaylist::removeMedia(int start, int end) Returns true if the operation is successful, otherwise return false. */ -bool QMediaPlaylist::clear() +void QMediaPlaylist::clear() { Q_D(QMediaPlaylist); - return d->playlist()->clear(); -} - -bool QMediaPlaylistPrivate::readItems(QMediaPlaylistReader *reader) -{ - QList<QMediaContent> items; - - while (!reader->atEnd()) - items.append(reader->readItem()); - - return playlist()->addMedia(items); -} - -bool QMediaPlaylistPrivate::writeItems(QMediaPlaylistWriter *writer) -{ - for (int i=0; i<playlist()->mediaCount(); i++) { - if (!writer->writeItem(playlist()->media(i))) - return false; - } - writer->close(); - return true; -} - -/*! - * \internal - * Copy playlist items, sync playback mode and sync current index between old control and new control -*/ -void QMediaPlaylistPrivate::syncControls(QMediaPlaylistControl *oldControl, QMediaPlaylistControl *newControl, - int *removedStart, int *removedEnd, - int *insertedStart, int *insertedEnd) -{ - Q_ASSERT(oldControl != NULL && newControl != NULL); - Q_ASSERT(removedStart != NULL && removedEnd != NULL - && insertedStart != NULL && insertedEnd != NULL); - - QMediaPlaylistProvider *oldPlaylist = oldControl->playlistProvider(); - QMediaPlaylistProvider *newPlaylist = newControl->playlistProvider(); - - Q_ASSERT(oldPlaylist != NULL && newPlaylist != NULL); - - *removedStart = -1; - *removedEnd = -1; - *insertedStart = -1; - *insertedEnd = -1; - - if (newPlaylist->isReadOnly()) { - // we can't transfer the items from the old control. - // Report these items as removed. - if (oldPlaylist->mediaCount() > 0) { - *removedStart = 0; - *removedEnd = oldPlaylist->mediaCount() - 1; - } - // The new control might have some items that can't be cleared. - // Report these as inserted. - if (newPlaylist->mediaCount() > 0) { - *insertedStart = 0; - *insertedEnd = newPlaylist->mediaCount() - 1; - } - } else { - const int oldPlaylistSize = oldPlaylist->mediaCount(); - - newPlaylist->clear(); - for (int i = 0; i < oldPlaylistSize; ++i) - newPlaylist->addMedia(oldPlaylist->media(i)); - } - - newControl->setPlaybackMode(oldControl->playbackMode()); - newControl->setCurrentIndex(oldControl->currentIndex()); + int size = d->playlist.size(); + emit mediaAboutToBeRemoved(0, size - 1); + d->playlist.clear(); + emit mediaRemoved(0, size - 1); } /*! @@ -529,35 +480,8 @@ void QMediaPlaylist::load(const QNetworkRequest &request, const char *format) d->error = NoError; d->errorString.clear(); - if (d->playlist()->load(request,format)) - return; - - if (isReadOnly()) { - d->error = AccessDeniedError; - d->errorString = tr("Could not add items to read only playlist."); - emit loadFailed(); - return; - } - - const auto keys = playlistIOLoader()->keys(); - for (QString const& key : keys) { - QMediaPlaylistIOInterface* plugin = qobject_cast<QMediaPlaylistIOInterface*>(playlistIOLoader()->instance(key)); - if (plugin && plugin->canRead(request.url(), format)) { - QMediaPlaylistReader *reader = plugin->createReader(request.url(), QByteArray(format)); - if (reader && d->readItems(reader)) { - delete reader; - emit loaded(); - return; - } - delete reader; - } - } - - d->error = FormatNotSupportedError; - d->errorString = tr("Playlist format is not supported"); - emit loadFailed(); - - return; + d->ensureParser(); + d->parser->start(request, QString::fromUtf8(format)); } /*! @@ -584,42 +508,15 @@ void QMediaPlaylist::load(const QUrl &location, const char *format) QMediaPlaylist::loaded() signal is emitted if playlist was loaded successfully, otherwise the playlist emits loadFailed(). */ -void QMediaPlaylist::load(QIODevice * device, const char *format) +void QMediaPlaylist::load(QIODevice *device, const char *format) { Q_D(QMediaPlaylist); d->error = NoError; d->errorString.clear(); - if (d->playlist()->load(device,format)) - return; - - if (isReadOnly()) { - d->error = AccessDeniedError; - d->errorString = tr("Could not add items to read only playlist."); - emit loadFailed(); - return; - } - - const auto keys = playlistIOLoader()->keys(); - for (QString const& key : keys) { - QMediaPlaylistIOInterface* plugin = qobject_cast<QMediaPlaylistIOInterface*>(playlistIOLoader()->instance(key)); - if (plugin && plugin->canRead(device,format)) { - QMediaPlaylistReader *reader = plugin->createReader(device,QByteArray(format)); - if (reader && d->readItems(reader)) { - delete reader; - emit loaded(); - return; - } - delete reader; - } - } - - d->error = FormatNotSupportedError; - d->errorString = tr("Playlist format is not supported"); - emit loadFailed(); - - return; + d->ensureParser(); + d->parser->start(device, QString::fromUtf8(format)); } /*! @@ -628,15 +525,15 @@ void QMediaPlaylist::load(QIODevice * device, const char *format) Returns true if playlist was saved successfully, otherwise returns false. */ -bool QMediaPlaylist::save(const QUrl &location, const char *format) +bool QMediaPlaylist::save(const QUrl &location, const char *format) const { - Q_D(QMediaPlaylist); + Q_D(const QMediaPlaylist); d->error = NoError; d->errorString.clear(); - if (d->playlist()->save(location,format)) - return true; + if (!d->checkFormat(format)) + return false; QFile file(location.toLocalFile()); @@ -654,33 +551,20 @@ bool QMediaPlaylist::save(const QUrl &location, const char *format) Returns true if playlist was saved successfully, otherwise returns false. */ -bool QMediaPlaylist::save(QIODevice * device, const char *format) +bool QMediaPlaylist::save(QIODevice *device, const char *format) const { - Q_D(QMediaPlaylist); + Q_D(const QMediaPlaylist); d->error = NoError; d->errorString.clear(); - if (d->playlist()->save(device,format)) - return true; - - const auto keys = playlistIOLoader()->keys(); - for (QString const& key : keys) { - QMediaPlaylistIOInterface* plugin = qobject_cast<QMediaPlaylistIOInterface*>(playlistIOLoader()->instance(key)); - if (plugin && plugin->canWrite(device,format)) { - QMediaPlaylistWriter *writer = plugin->createWriter(device,QByteArray(format)); - if (writer && d->writeItems(writer)) { - delete writer; - return true; - } - delete writer; - } - } - - d->error = FormatNotSupportedError; - d->errorString = tr("Playlist format is not supported."); + if (!d->checkFormat(format)) + return false; - return false; + QM3uPlaylistWriter writer(device); + for (const auto &entry : d->playlist) + writer.writeItem(entry); + return true; } /*! @@ -704,7 +588,21 @@ QString QMediaPlaylist::errorString() const */ void QMediaPlaylist::shuffle() { - d_func()->playlist()->shuffle(); + Q_D(QMediaPlaylist); + QList<QMediaContent> playlist; + + // keep the current item when shuffling + QMediaContent current; + if (d->currentPos != -1) + current = d->playlist.takeAt(d->currentPos); + + while (!d->playlist.isEmpty()) + playlist.append(d->playlist.takeAt(QRandomGenerator::global()->bounded(int(d->playlist.size())))); + + if (d->currentPos != -1) + playlist.insert(d->currentPos, current); + d->playlist = playlist; + emit mediaChanged(0, d->playlist.count()); } @@ -713,7 +611,11 @@ void QMediaPlaylist::shuffle() */ void QMediaPlaylist::next() { - d_func()->control->next(); + Q_D(QMediaPlaylist); + d->currentPos = d->nextPosition(1); + + emit currentIndexChanged(d->currentPos); + emit currentMediaChanged(currentMedia()); } /*! @@ -721,7 +623,11 @@ void QMediaPlaylist::next() */ void QMediaPlaylist::previous() { - d_func()->control->previous(); + Q_D(QMediaPlaylist); + d->currentPos = d->prevPosition(1); + + emit currentIndexChanged(d->currentPos); + emit currentMediaChanged(currentMedia()); } /*! @@ -730,7 +636,13 @@ void QMediaPlaylist::previous() void QMediaPlaylist::setCurrentIndex(int playlistPosition) { - d_func()->control->setCurrentIndex(playlistPosition); + Q_D(QMediaPlaylist); + if (playlistPosition < 0 || playlistPosition >= d->playlist.size()) + playlistPosition = -1; + d->currentPos = playlistPosition; + + emit currentIndexChanged(d->currentPos); + emit currentMediaChanged(currentMedia()); } /*! @@ -821,4 +733,3 @@ void QMediaPlaylist::setCurrentIndex(int playlistPosition) QT_END_NAMESPACE #include "moc_qmediaplaylist.cpp" -#include "moc_qmediaplaylist_p.cpp" diff --git a/src/multimedia/playback/qmediaplaylist.h b/src/multimedia/playback/qmediaplaylist.h index 4eb93bd02..c036636ca 100644 --- a/src/multimedia/playback/qmediaplaylist.h +++ b/src/multimedia/playback/qmediaplaylist.h @@ -50,9 +50,6 @@ QT_BEGIN_NAMESPACE - -class QMediaPlaylistProvider; - class QMediaPlaylistPrivate; class Q_MULTIMEDIA_EXPORT QMediaPlaylist : public QObject, public QMediaBindableInterface { @@ -64,7 +61,7 @@ class Q_MULTIMEDIA_EXPORT QMediaPlaylist : public QObject, public QMediaBindable Q_ENUMS(PlaybackMode Error) public: - enum PlaybackMode { CurrentItemOnce, CurrentItemInLoop, Sequential, Loop, Random }; + enum PlaybackMode { CurrentItemOnce, CurrentItemInLoop, Sequential, Loop }; enum Error { NoError, FormatError, FormatNotSupportedError, NetworkError, AccessDeniedError }; explicit QMediaPlaylist(QObject *parent = nullptr); @@ -85,23 +82,22 @@ public: int mediaCount() const; bool isEmpty() const; - bool isReadOnly() const; - bool addMedia(const QMediaContent &content); - bool addMedia(const QList<QMediaContent> &items); + void addMedia(const QMediaContent &content); + void addMedia(const QList<QMediaContent> &items); bool insertMedia(int index, const QMediaContent &content); bool insertMedia(int index, const QList<QMediaContent> &items); bool moveMedia(int from, int to); bool removeMedia(int pos); bool removeMedia(int start, int end); - bool clear(); + void clear(); void load(const QNetworkRequest &request, const char *format = nullptr); void load(const QUrl &location, const char *format = nullptr); void load(QIODevice *device, const char *format = nullptr); - bool save(const QUrl &location, const char *format = nullptr); - bool save(QIODevice * device, const char *format); + bool save(const QUrl &location, const char *format = nullptr) const; + bool save(QIODevice *device, const char *format) const; Error error() const; QString errorString() const; @@ -134,7 +130,6 @@ protected: private: Q_DECLARE_PRIVATE(QMediaPlaylist) - Q_PRIVATE_SLOT(d_func(), void _q_loadFailed(QMediaPlaylist::Error, const QString &)) }; QT_END_NAMESPACE diff --git a/src/multimedia/playback/qmediaplaylist_p.h b/src/multimedia/playback/qmediaplaylist_p.h index 16fce00a9..fb462fedf 100644 --- a/src/multimedia/playback/qmediaplaylist_p.h +++ b/src/multimedia/playback/qmediaplaylist_p.h @@ -52,11 +52,10 @@ // #include "qmediaplaylist.h" -#include "qmediaplaylistcontrol_p.h" #include "qmediaplayer.h" #include "qmediaplayercontrol.h" -#include "qmedianetworkplaylistprovider_p.h" #include "qmediaobject_p.h" +#include "qplaylistfileparser_p.h" #include <QtCore/qdebug.h> @@ -68,26 +67,24 @@ QT_BEGIN_NAMESPACE class QMediaPlaylistControl; -class QMediaPlaylistProvider; -class QMediaPlaylistReader; -class QMediaPlaylistWriter; -class QMediaPlayerControl; class QMediaPlaylistPrivate { Q_DECLARE_PUBLIC(QMediaPlaylist) public: QMediaPlaylistPrivate() - :mediaObject(nullptr), - control(nullptr), - networkPlaylistControl(nullptr), - error(QMediaPlaylist::NoError) + : mediaObject(nullptr), + error(QMediaPlaylist::NoError) { } - virtual ~QMediaPlaylistPrivate() {} + virtual ~QMediaPlaylistPrivate() + { + if (parser) + delete parser; + } - void _q_loadFailed(QMediaPlaylist::Error error, const QString &errorString) + void loadFailed(QMediaPlaylist::Error error, const QString &errorString) { this->error = error; this->errorString = errorString; @@ -95,78 +92,66 @@ public: emit q_ptr->loadFailed(); } + void loadFinished() + { + q_ptr->addMedia(parser->playlist); + + emit q_ptr->loaded(); + } + void _q_mediaObjectDeleted() { Q_Q(QMediaPlaylist); mediaObject = nullptr; - if (control != networkPlaylistControl) - control = nullptr; q->setMediaObject(nullptr); } - QMediaObject *mediaObject; - - QMediaPlaylistControl *control; - QMediaPlaylistProvider *playlist() const { return control->playlistProvider(); } - - QMediaPlaylistControl *networkPlaylistControl; - - bool readItems(QMediaPlaylistReader *reader); - bool writeItems(QMediaPlaylistWriter *writer); - - void syncControls(QMediaPlaylistControl *oldControl, QMediaPlaylistControl *newControl, - int *removedStart, int *removedEnd, - int *insertedStart, int *insertedEnd); - - QMediaPlaylist::Error error; - QString errorString; - - QMediaPlaylist *q_ptr; -}; - + bool checkFormat(const char *format) const + { + QPlaylistFileParser::FileType type = format ? QPlaylistFileParser::UNKNOWN : QPlaylistFileParser::M3U8; + if (format == QLatin1String("m3u") || format == QLatin1String("text/uri-list") || + format == QLatin1String("audio/x-mpegurl") || format == QLatin1String("audio/mpegurl")) + type = QPlaylistFileParser::M3U; + else if (format == QLatin1String("m3u8") || format == QLatin1String("application/x-mpegURL") || + format == QLatin1String("application/vnd.apple.mpegurl")) + type = QPlaylistFileParser::M3U8; + + if (type == QPlaylistFileParser::UNKNOWN || type == QPlaylistFileParser::PLS) { + error = QMediaPlaylist::FormatNotSupportedError; + errorString = QMediaPlaylist::tr("This file format is not supported."); + return false; + } + return true; + } -class QMediaNetworkPlaylistControl : public QMediaPlaylistControl -{ - Q_OBJECT -public: - QMediaNetworkPlaylistControl(QObject *parent) - :QMediaPlaylistControl(parent) + void ensureParser() { - QMediaPlaylistProvider *playlist = new QMediaNetworkPlaylistProvider(this); - m_navigator = new QMediaPlaylistNavigator(playlist,this); - m_navigator->setPlaybackMode(QMediaPlaylist::Sequential); + if (parser) + return; - connect(m_navigator, SIGNAL(currentIndexChanged(int)), SIGNAL(currentIndexChanged(int))); - connect(m_navigator, SIGNAL(activated(QMediaContent)), SIGNAL(currentMediaChanged(QMediaContent))); - connect(m_navigator, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)), SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode))); + parser = new QPlaylistFileParser(q_ptr); + QObject::connect(parser, &QPlaylistFileParser::finished, [this]() { loadFinished(); }); + QObject::connect(parser, &QPlaylistFileParser::error, + [this](QMediaPlaylist::Error err, const QString& errorMsg) { loadFailed(err, errorMsg); }); } - ~QMediaNetworkPlaylistControl() {} + int nextPosition(int steps) const; + int prevPosition(int steps) const; - QMediaPlaylistProvider* playlistProvider() const override { return m_navigator->playlist(); } - bool setPlaylistProvider(QMediaPlaylistProvider *mediaPlaylist) override - { - m_navigator->setPlaylist(mediaPlaylist); - emit playlistProviderChanged(); - return true; - } + QMediaObject *mediaObject; - int currentIndex() const override { return m_navigator->currentIndex(); } - void setCurrentIndex(int position) override { m_navigator->jump(position); } - int nextIndex(int steps) const override { return m_navigator->nextIndex(steps); } - int previousIndex(int steps) const override { return m_navigator->previousIndex(steps); } + QList<QMediaContent> playlist; - void next() override { m_navigator->next(); } - void previous() override { m_navigator->previous(); } + int currentPos = -1; + QMediaPlaylist::PlaybackMode playbackMode = QMediaPlaylist::Sequential; - QMediaPlaylist::PlaybackMode playbackMode() const override { return m_navigator->playbackMode(); } - void setPlaybackMode(QMediaPlaylist::PlaybackMode mode) override { m_navigator->setPlaybackMode(mode); } + QPlaylistFileParser *parser = nullptr; + mutable QMediaPlaylist::Error error; + mutable QString errorString; -private: - QMediaPlaylistNavigator *m_navigator; + QMediaPlaylist *q_ptr; }; - QT_END_NAMESPACE diff --git a/src/multimedia/playback/qmediaplaylistioplugin.cpp b/src/multimedia/playback/qmediaplaylistioplugin.cpp deleted file mode 100644 index 957c7c79d..000000000 --- a/src/multimedia/playback/qmediaplaylistioplugin.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmediaplaylistioplugin_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QMediaPlaylistReader - \internal - - \brief The QMediaPlaylistReader class provides an interface for reading a playlist file. - \inmodule QtMultimedia - - \ingroup multimedia - \ingroup multimedia_playback - - \sa QMediaPlaylistIOPlugin -*/ - -/*! - Destroys a media playlist reader. -*/ -QMediaPlaylistReader::~QMediaPlaylistReader() -{ -} - -/*! - \fn QMediaPlaylistReader::atEnd() const - - Identifies if a playlist reader has reached the end of its input. - - Returns true if the reader has reached the end; and false otherwise. -*/ - -/*! - \fn QMediaPlaylistReader::readItem() - - Reads an item of media from a playlist file. - - Returns the read media, or a null QMediaContent if no more media is available. -*/ - -/*! - \fn QMediaPlaylistReader::close() - - Closes a playlist reader's input device. -*/ - -/*! - \class QMediaPlaylistWriter - \internal - - \brief The QMediaPlaylistWriter class provides an interface for writing a playlist file. - - \sa QMediaPlaylistIOPlugin -*/ - -/*! - Destroys a media playlist writer. -*/ -QMediaPlaylistWriter::~QMediaPlaylistWriter() -{ -} - -/*! - \fn QMediaPlaylistWriter::writeItem(const QMediaContent &media) - - Writes an item of \a media to a playlist file. - - Returns true if the media was written successfully; and false otherwise. -*/ - -/*! - \fn QMediaPlaylistWriter::close() - - Finalizes the writing of a playlist and closes the output device. -*/ - -/*! - \class QMediaPlaylistIOPlugin - \internal - - \brief The QMediaPlaylistIOPlugin class provides an interface for media playlist I/O plug-ins. -*/ - -/*! - Constructs a media playlist I/O plug-in with the given \a parent. -*/ -QMediaPlaylistIOPlugin::QMediaPlaylistIOPlugin(QObject *parent) - :QObject(parent) -{ -} - -/*! - Destroys a media playlist I/O plug-in. -*/ -QMediaPlaylistIOPlugin::~QMediaPlaylistIOPlugin() -{ -} - -/*! - \fn QMediaPlaylistIOPlugin::canRead(QIODevice *device, const QByteArray &format) const - - Identifies if plug-in can read \a format data from an I/O \a device. - - Returns true if the data can be read; and false otherwise. -*/ - -/*! - \fn QMediaPlaylistIOPlugin::canRead(const QUrl& location, const QByteArray &format) const - - Identifies if a plug-in can read \a format data from a URL \a location. - - Returns true if the data can be read; and false otherwise. -*/ - -/*! - \fn QMediaPlaylistIOPlugin::canWrite(QIODevice *device, const QByteArray &format) const - - Identifies if a plug-in can write \a format data to an I/O \a device. - - Returns true if the data can be written; and false otherwise. -*/ - -/*! - \fn QMediaPlaylistIOPlugin::createReader(QIODevice *device, const QByteArray &format) - - Returns a new QMediaPlaylistReader which reads \a format data from an I/O \a device. - - If the device is invalid or the format is unsupported this will return a null pointer. -*/ - -/*! - \fn QMediaPlaylistIOPlugin::createReader(const QUrl& location, const QByteArray &format) - - Returns a new QMediaPlaylistReader which reads \a format data from a URL \a location. - - If the location or the format is unsupported this will return a null pointer. -*/ - -/*! - \fn QMediaPlaylistIOPlugin::createWriter(QIODevice *device, const QByteArray &format) - - Returns a new QMediaPlaylistWriter which writes \a format data to an I/O \a device. - - If the device is invalid or the format is unsupported this will return a null pointer. -*/ - -QT_END_NAMESPACE - -#include "moc_qmediaplaylistioplugin_p.cpp" diff --git a/src/multimedia/playback/qmediaplaylistioplugin_p.h b/src/multimedia/playback/qmediaplaylistioplugin_p.h deleted file mode 100644 index 153679958..000000000 --- a/src/multimedia/playback/qmediaplaylistioplugin_p.h +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIAPLAYLISTIOPLUGIN_P_H -#define QMEDIAPLAYLISTIOPLUGIN_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtCore/qobject.h> -#include <QtCore/qplugin.h> - -#include <qtmultimediaglobal.h> - -#include "qmediacontent.h" - -QT_BEGIN_NAMESPACE - -class QString; -class QUrl; -class QByteArray; -class QIODevice; - -class Q_MULTIMEDIA_EXPORT QMediaPlaylistReader -{ -public: - virtual ~QMediaPlaylistReader(); - - virtual bool atEnd() const = 0; - virtual QMediaContent readItem() = 0; - virtual void close() = 0; -}; - -class Q_MULTIMEDIA_EXPORT QMediaPlaylistWriter -{ -public: - virtual ~QMediaPlaylistWriter(); - - virtual bool writeItem(const QMediaContent &content) = 0; - virtual void close() = 0; -}; - -struct Q_MULTIMEDIA_EXPORT QMediaPlaylistIOInterface -{ - virtual bool canRead(QIODevice *device, const QByteArray &format = QByteArray() ) const = 0; - virtual bool canRead(const QUrl& location, const QByteArray &format = QByteArray()) const = 0; - - virtual bool canWrite(QIODevice *device, const QByteArray &format) const = 0; - - virtual QMediaPlaylistReader *createReader(QIODevice *device, const QByteArray &format = QByteArray()) = 0; - virtual QMediaPlaylistReader *createReader(const QUrl& location, const QByteArray &format = QByteArray()) = 0; - - virtual QMediaPlaylistWriter *createWriter(QIODevice *device, const QByteArray &format) = 0; -}; - -#define QMediaPlaylistIOInterface_iid "org.qt-project.qt.mediaplaylistio/5.0" -Q_DECLARE_INTERFACE(QMediaPlaylistIOInterface, QMediaPlaylistIOInterface_iid); - -class Q_MULTIMEDIA_EXPORT QMediaPlaylistIOPlugin : public QObject, public QMediaPlaylistIOInterface -{ -Q_OBJECT -Q_INTERFACES(QMediaPlaylistIOInterface) -public: - explicit QMediaPlaylistIOPlugin(QObject *parent = nullptr); - ~QMediaPlaylistIOPlugin(); - - bool canRead(QIODevice *device, const QByteArray &format = QByteArray() ) const override = 0; - bool canRead(const QUrl& location, const QByteArray &format = QByteArray()) const override = 0; - - bool canWrite(QIODevice *device, const QByteArray &format) const override = 0; - - QMediaPlaylistReader *createReader(QIODevice *device, const QByteArray &format = QByteArray()) override = 0; - QMediaPlaylistReader *createReader(const QUrl& location, const QByteArray &format = QByteArray()) override = 0; - - QMediaPlaylistWriter *createWriter(QIODevice *device, const QByteArray &format) override = 0; -}; - -QT_END_NAMESPACE - - -#endif // QMEDIAPLAYLISTIOPLUGIN_P_H diff --git a/src/multimedia/playback/qmediaplaylistnavigator.cpp b/src/multimedia/playback/qmediaplaylistnavigator.cpp deleted file mode 100644 index 9b25f968a..000000000 --- a/src/multimedia/playback/qmediaplaylistnavigator.cpp +++ /dev/null @@ -1,544 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmediaplaylistnavigator_p.h" -#include "qmediaplaylistprovider_p.h" -#include "qmediaplaylist.h" -#include "qmediaobject_p.h" - -#include <QtCore/qdebug.h> -#include <QtCore/qrandom.h> - -QT_BEGIN_NAMESPACE - -class QMediaPlaylistNullProvider : public QMediaPlaylistProvider -{ -public: - QMediaPlaylistNullProvider() :QMediaPlaylistProvider() {} - ~QMediaPlaylistNullProvider() {} - int mediaCount() const override {return 0;} - QMediaContent media(int) const override { return QMediaContent(); } -}; - -Q_GLOBAL_STATIC(QMediaPlaylistNullProvider, _q_nullMediaPlaylist) - -class QMediaPlaylistNavigatorPrivate -{ - Q_DECLARE_NON_CONST_PUBLIC(QMediaPlaylistNavigator) -public: - QMediaPlaylistNavigatorPrivate() - :playlist(nullptr), - currentPos(-1), - lastValidPos(-1), - playbackMode(QMediaPlaylist::Sequential), - randomPositionsOffset(-1) - { - } - - QMediaPlaylistProvider *playlist; - int currentPos; - int lastValidPos; //to be used with CurrentItemOnce playback mode - QMediaPlaylist::PlaybackMode playbackMode; - QMediaContent currentItem; - - mutable QList<int> randomModePositions; - mutable int randomPositionsOffset; - - int nextItemPos(int steps = 1) const; - int previousItemPos(int steps = 1) const; - - void _q_mediaInserted(int start, int end); - void _q_mediaRemoved(int start, int end); - void _q_mediaChanged(int start, int end); - - QMediaPlaylistNavigator *q_ptr; -}; - - -int QMediaPlaylistNavigatorPrivate::nextItemPos(int steps) const -{ - if (playlist->mediaCount() == 0) - return -1; - - if (steps == 0) - return currentPos; - - switch (playbackMode) { - case QMediaPlaylist::CurrentItemOnce: - return /*currentPos == -1 ? lastValidPos :*/ -1; - case QMediaPlaylist::CurrentItemInLoop: - return currentPos; - case QMediaPlaylist::Sequential: - { - int nextPos = currentPos+steps; - return nextPos < playlist->mediaCount() ? nextPos : -1; - } - case QMediaPlaylist::Loop: - return (currentPos+steps) % playlist->mediaCount(); - case QMediaPlaylist::Random: - { - //TODO: limit the history size - - if (randomPositionsOffset == -1) { - randomModePositions.clear(); - randomModePositions.append(currentPos); - randomPositionsOffset = 0; - } - - while (randomModePositions.size() < randomPositionsOffset+steps+1) - randomModePositions.append(-1); - int res = randomModePositions[randomPositionsOffset+steps]; - if (res<0 || res >= playlist->mediaCount()) { - res = QRandomGenerator::global()->bounded(playlist->mediaCount()); - randomModePositions[randomPositionsOffset+steps] = res; - } - - return res; - } - } - - return -1; -} - -int QMediaPlaylistNavigatorPrivate::previousItemPos(int steps) const -{ - if (playlist->mediaCount() == 0) - return -1; - - if (steps == 0) - return currentPos; - - switch (playbackMode) { - case QMediaPlaylist::CurrentItemOnce: - return /*currentPos == -1 ? lastValidPos :*/ -1; - case QMediaPlaylist::CurrentItemInLoop: - return currentPos; - case QMediaPlaylist::Sequential: - { - int prevPos = currentPos == -1 ? playlist->mediaCount() - steps : currentPos - steps; - return prevPos>=0 ? prevPos : -1; - } - case QMediaPlaylist::Loop: - { - int prevPos = currentPos - steps; - while (prevPos<0) - prevPos += playlist->mediaCount(); - return prevPos; - } - case QMediaPlaylist::Random: - { - //TODO: limit the history size - - if (randomPositionsOffset == -1) { - randomModePositions.clear(); - randomModePositions.append(currentPos); - randomPositionsOffset = 0; - } - - while (randomPositionsOffset-steps < 0) { - randomModePositions.prepend(-1); - randomPositionsOffset++; - } - - int res = randomModePositions[randomPositionsOffset-steps]; - if (res<0 || res >= playlist->mediaCount()) { - res = QRandomGenerator::global()->bounded(playlist->mediaCount()); - randomModePositions[randomPositionsOffset-steps] = res; - } - - return res; - } - } - - return -1; -} - -/*! - \class QMediaPlaylistNavigator - \internal - - \brief The QMediaPlaylistNavigator class provides navigation for a media playlist. - \inmodule QtMultimedia - \ingroup multimedia - \ingroup multimedia_playback - - \sa QMediaPlaylist, QMediaPlaylistProvider -*/ - - -/*! - Constructs a media playlist navigator for a \a playlist. - - The \a parent is passed to QObject. - */ -QMediaPlaylistNavigator::QMediaPlaylistNavigator(QMediaPlaylistProvider *playlist, QObject *parent) - : QObject(parent) - , d_ptr(new QMediaPlaylistNavigatorPrivate) -{ - d_ptr->q_ptr = this; - - setPlaylist(playlist ? playlist : _q_nullMediaPlaylist()); -} - -/*! - Destroys a media playlist navigator. - */ - -QMediaPlaylistNavigator::~QMediaPlaylistNavigator() -{ - delete d_ptr; -} - - -/*! \property QMediaPlaylistNavigator::playbackMode - Contains the playback mode. - */ -QMediaPlaylist::PlaybackMode QMediaPlaylistNavigator::playbackMode() const -{ - return d_func()->playbackMode; -} - -/*! - Sets the playback \a mode. - */ -void QMediaPlaylistNavigator::setPlaybackMode(QMediaPlaylist::PlaybackMode mode) -{ - Q_D(QMediaPlaylistNavigator); - if (d->playbackMode == mode) - return; - - if (mode == QMediaPlaylist::Random) { - d->randomPositionsOffset = 0; - d->randomModePositions.append(d->currentPos); - } else if (d->playbackMode == QMediaPlaylist::Random) { - d->randomPositionsOffset = -1; - d->randomModePositions.clear(); - } - - d->playbackMode = mode; - - emit playbackModeChanged(mode); - emit surroundingItemsChanged(); -} - -/*! - Returns the playlist being navigated. -*/ - -QMediaPlaylistProvider *QMediaPlaylistNavigator::playlist() const -{ - return d_func()->playlist; -} - -/*! - Sets the \a playlist to navigate. -*/ -void QMediaPlaylistNavigator::setPlaylist(QMediaPlaylistProvider *playlist) -{ - Q_D(QMediaPlaylistNavigator); - - if (d->playlist == playlist) - return; - - if (d->playlist) { - d->playlist->disconnect(this); - } - - if (playlist) { - d->playlist = playlist; - } else { - //assign to shared readonly null playlist - d->playlist = _q_nullMediaPlaylist(); - } - - connect(d->playlist, SIGNAL(mediaInserted(int,int)), SLOT(_q_mediaInserted(int,int))); - connect(d->playlist, SIGNAL(mediaRemoved(int,int)), SLOT(_q_mediaRemoved(int,int))); - connect(d->playlist, SIGNAL(mediaChanged(int,int)), SLOT(_q_mediaChanged(int,int))); - - d->randomPositionsOffset = -1; - d->randomModePositions.clear(); - - if (d->currentPos != -1) { - d->currentPos = -1; - emit currentIndexChanged(-1); - } - - if (!d->currentItem.isNull()) { - d->currentItem = QMediaContent(); - emit activated(d->currentItem); //stop playback - } -} - -/*! \property QMediaPlaylistNavigator::currentItem - - Contains the media at the current position in the playlist. - - \sa currentIndex() -*/ - -QMediaContent QMediaPlaylistNavigator::currentItem() const -{ - return itemAt(d_func()->currentPos); -} - -/*! \fn QMediaContent QMediaPlaylistNavigator::nextItem(int steps) const - - Returns the media that is \a steps positions ahead of the current - position in the playlist. - - \sa nextIndex() -*/ -QMediaContent QMediaPlaylistNavigator::nextItem(int steps) const -{ - return itemAt(nextIndex(steps)); -} - -/*! - Returns the media that is \a steps positions behind the current - position in the playlist. - - \sa previousIndex() - */ -QMediaContent QMediaPlaylistNavigator::previousItem(int steps) const -{ - return itemAt(previousIndex(steps)); -} - -/*! - Returns the media at a \a position in the playlist. - */ -QMediaContent QMediaPlaylistNavigator::itemAt(int position) const -{ - return d_func()->playlist->media(position); -} - -/*! \property QMediaPlaylistNavigator::currentIndex - - Contains the position of the current media. - - If no media is current, the property contains -1. - - \sa nextIndex(), previousIndex() -*/ - -int QMediaPlaylistNavigator::currentIndex() const -{ - return d_func()->currentPos; -} - -/*! - Returns a position \a steps ahead of the current position - accounting for the playbackMode(). - - If the position is beyond the end of the playlist, this value - returned is -1. - - \sa currentIndex(), previousIndex(), playbackMode() -*/ - -int QMediaPlaylistNavigator::nextIndex(int steps) const -{ - return d_func()->nextItemPos(steps); -} - -/*! - - Returns a position \a steps behind the current position accounting - for the playbackMode(). - - If the position is prior to the beginning of the playlist this will - return -1. - - \sa currentIndex(), nextIndex(), playbackMode() -*/ -int QMediaPlaylistNavigator::previousIndex(int steps) const -{ - return d_func()->previousItemPos(steps); -} - -/*! - Advances to the next item in the playlist. - - \sa previous(), jump(), playbackMode() - */ -void QMediaPlaylistNavigator::next() -{ - Q_D(QMediaPlaylistNavigator); - - int nextPos = d->nextItemPos(); - - if ( playbackMode() == QMediaPlaylist::Random ) - d->randomPositionsOffset++; - - jump(nextPos); -} - -/*! - Returns to the previous item in the playlist, - - \sa next(), jump(), playbackMode() - */ -void QMediaPlaylistNavigator::previous() -{ - Q_D(QMediaPlaylistNavigator); - - int prevPos = d->previousItemPos(); - if ( playbackMode() == QMediaPlaylist::Random ) - d->randomPositionsOffset--; - - jump(prevPos); -} - -/*! - Jumps to a new \a position in the playlist. - */ -void QMediaPlaylistNavigator::jump(int position) -{ - Q_D(QMediaPlaylistNavigator); - - if (position < -1 || position >= d->playlist->mediaCount()) - position = -1; - - if (position != -1) - d->lastValidPos = position; - - if (playbackMode() == QMediaPlaylist::Random) { - if (d->randomModePositions[d->randomPositionsOffset] != position) { - d->randomModePositions.clear(); - d->randomModePositions.append(position); - d->randomPositionsOffset = 0; - } - } - - if (position != -1) - d->currentItem = d->playlist->media(position); - else - d->currentItem = QMediaContent(); - - if (position != d->currentPos) { - d->currentPos = position; - emit currentIndexChanged(d->currentPos); - emit surroundingItemsChanged(); - } - - emit activated(d->currentItem); -} - -/*! - \internal -*/ -void QMediaPlaylistNavigatorPrivate::_q_mediaInserted(int start, int end) -{ - Q_Q(QMediaPlaylistNavigator); - - if (currentPos >= start) { - currentPos = end-start+1; - q->jump(currentPos); - } - - //TODO: check if they really changed - emit q->surroundingItemsChanged(); -} - -/*! - \internal -*/ -void QMediaPlaylistNavigatorPrivate::_q_mediaRemoved(int start, int end) -{ - Q_Q(QMediaPlaylistNavigator); - - if (currentPos > end) { - currentPos = currentPos - end-start+1; - q->jump(currentPos); - } else if (currentPos >= start) { - //current item was removed - currentPos = qMin(start, playlist->mediaCount()-1); - q->jump(currentPos); - } - - //TODO: check if they really changed - emit q->surroundingItemsChanged(); -} - -/*! - \internal -*/ -void QMediaPlaylistNavigatorPrivate::_q_mediaChanged(int start, int end) -{ - Q_Q(QMediaPlaylistNavigator); - - if (currentPos >= start && currentPos<=end) { - QMediaContent src = playlist->media(currentPos); - if (src != currentItem) { - currentItem = src; - emit q->activated(src); - } - } - - //TODO: check if they really changed - emit q->surroundingItemsChanged(); -} - -/*! - \fn QMediaPlaylistNavigator::activated(const QMediaContent &media) - - Signals that the current \a media has changed. -*/ - -/*! - \fn QMediaPlaylistNavigator::currentIndexChanged(int position) - - Signals the \a position of the current media has changed. -*/ - -/*! - \fn QMediaPlaylistNavigator::playbackModeChanged(QMediaPlaylist::PlaybackMode mode) - - Signals that the playback \a mode has changed. -*/ - -/*! - \fn QMediaPlaylistNavigator::surroundingItemsChanged() - - Signals that media immediately surrounding the current position has changed. -*/ - -QT_END_NAMESPACE - -#include "moc_qmediaplaylistnavigator_p.cpp" diff --git a/src/multimedia/playback/qmediaplaylistnavigator_p.h b/src/multimedia/playback/qmediaplaylistnavigator_p.h deleted file mode 100644 index 2ac03a62c..000000000 --- a/src/multimedia/playback/qmediaplaylistnavigator_p.h +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIAPLAYLISTNAVIGATOR_P_H -#define QMEDIAPLAYLISTNAVIGATOR_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qmediaplaylistprovider_p.h" -#include "qmediaplaylist.h" -#include <QtCore/qobject.h> - -QT_BEGIN_NAMESPACE - - -class QMediaPlaylistNavigatorPrivate; -class Q_MULTIMEDIA_EXPORT QMediaPlaylistNavigator : public QObject -{ - Q_OBJECT - Q_PROPERTY(QMediaPlaylist::PlaybackMode playbackMode READ playbackMode WRITE setPlaybackMode NOTIFY playbackModeChanged) - Q_PROPERTY(int currentIndex READ currentIndex WRITE jump NOTIFY currentIndexChanged) - Q_PROPERTY(QMediaContent currentItem READ currentItem) - -public: - QMediaPlaylistNavigator(QMediaPlaylistProvider *playlist, QObject *parent = nullptr); - virtual ~QMediaPlaylistNavigator(); - - QMediaPlaylistProvider *playlist() const; - void setPlaylist(QMediaPlaylistProvider *playlist); - - QMediaPlaylist::PlaybackMode playbackMode() const; - - QMediaContent currentItem() const; - QMediaContent nextItem(int steps = 1) const; - QMediaContent previousItem(int steps = 1) const; - - QMediaContent itemAt(int position) const; - - int currentIndex() const; - int nextIndex(int steps = 1) const; - int previousIndex(int steps = 1) const; - -public Q_SLOTS: - void next(); - void previous(); - - void jump(int); - - void setPlaybackMode(QMediaPlaylist::PlaybackMode mode); - -Q_SIGNALS: - void activated(const QMediaContent &content); - void currentIndexChanged(int); - void playbackModeChanged(QMediaPlaylist::PlaybackMode mode); - - void surroundingItemsChanged(); - -protected: - QMediaPlaylistNavigatorPrivate *d_ptr; - -private: - Q_DISABLE_COPY(QMediaPlaylistNavigator) - Q_DECLARE_PRIVATE(QMediaPlaylistNavigator) - - Q_PRIVATE_SLOT(d_func(), void _q_mediaInserted(int start, int end)) - Q_PRIVATE_SLOT(d_func(), void _q_mediaRemoved(int start, int end)) - Q_PRIVATE_SLOT(d_func(), void _q_mediaChanged(int start, int end)) -}; - -QT_END_NAMESPACE - - -#endif // QMEDIAPLAYLISTNAVIGATOR_P_H diff --git a/src/multimedia/playback/qmediaplaylistprovider.cpp b/src/multimedia/playback/qmediaplaylistprovider.cpp deleted file mode 100644 index 8089a9320..000000000 --- a/src/multimedia/playback/qmediaplaylistprovider.cpp +++ /dev/null @@ -1,321 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmediaplaylistprovider_p.h" - -#include <QtCore/qurl.h> - -QT_BEGIN_NAMESPACE - -/*! - \class QMediaPlaylistProvider - \internal - - \brief The QMediaPlaylistProvider class provides an abstract list of media. - \inmodule QtMultimedia - - \ingroup multimedia - \ingroup multimedia_playback - - \sa QMediaPlaylist -*/ - -/*! - Constructs a playlist provider with the given \a parent. -*/ -QMediaPlaylistProvider::QMediaPlaylistProvider(QObject *parent) - :QObject(parent), d_ptr(new QMediaPlaylistProviderPrivate) -{ -} - -/*! - \internal -*/ -QMediaPlaylistProvider::QMediaPlaylistProvider(QMediaPlaylistProviderPrivate &dd, QObject *parent) - :QObject(parent), d_ptr(&dd) -{ -} - -/*! - Destroys a playlist provider. -*/ -QMediaPlaylistProvider::~QMediaPlaylistProvider() -{ - delete d_ptr; -} - -/*! - \fn QMediaPlaylistProvider::mediaCount() const; - - Returns the size of playlist. -*/ - -/*! - \fn QMediaPlaylistProvider::media(int index) const; - - Returns the media at \a index in the playlist. - - If the index is invalid this will return a null media content. -*/ - - -/*! - Loads a playlist using network \a request. If no playlist \a format is specified the loader - will inspect the URL or probe the headers to guess the format. - - New items are appended to playlist. - - Returns true if the provider supports the format and loading from the locations URL protocol, - otherwise this will return false. -*/ -bool QMediaPlaylistProvider::load(const QNetworkRequest &request, const char *format) -{ - Q_UNUSED(request); - Q_UNUSED(format); - return false; -} - -/*! - Loads a playlist from from an I/O \a device. If no playlist \a format is specified the loader - will probe the headers to guess the format. - - New items are appended to playlist. - - Returns true if the provider supports the format and loading from an I/O device, otherwise this - will return false. -*/ -bool QMediaPlaylistProvider::load(QIODevice * device, const char *format) -{ - Q_UNUSED(device); - Q_UNUSED(format); - return false; -} - -/*! - Saves the contents of a playlist to a URL \a location. If no playlist \a format is specified - the writer will inspect the URL to guess the format. - - Returns true if the playlist was saved successfully; and false otherwise. - */ -bool QMediaPlaylistProvider::save(const QUrl &location, const char *format) -{ - Q_UNUSED(location); - Q_UNUSED(format); - return false; -} - -/*! - Saves the contents of a playlist to an I/O \a device in the specified \a format. - - Returns true if the playlist was saved successfully; and false otherwise. -*/ -bool QMediaPlaylistProvider::save(QIODevice * device, const char *format) -{ - Q_UNUSED(device); - Q_UNUSED(format); - return false; -} - -/*! - Returns true if a playlist is read-only; otherwise returns false. -*/ -bool QMediaPlaylistProvider::isReadOnly() const -{ - return true; -} - -/*! - Append \a media to a playlist. - - Returns true if the media was appended; and false otherwise. -*/ -bool QMediaPlaylistProvider::addMedia(const QMediaContent &media) -{ - Q_UNUSED(media); - return false; -} - -/*! - Append multiple media \a items to a playlist. - - Returns true if the media items were appended; and false otherwise. -*/ -bool QMediaPlaylistProvider::addMedia(const QList<QMediaContent> &items) -{ - for (const QMediaContent &item : items) { - if (!addMedia(item)) - return false; - } - - return true; -} - -/*! - Inserts \a media into a playlist at \a position. - - Returns true if the media was inserted; and false otherwise. -*/ -bool QMediaPlaylistProvider::insertMedia(int position, const QMediaContent &media) -{ - Q_UNUSED(position); - Q_UNUSED(media); - return false; -} - -/*! - Inserts multiple media \a items into a playlist at \a position. - - Returns true if the media \a items were inserted; and false otherwise. -*/ -bool QMediaPlaylistProvider::insertMedia(int position, const QList<QMediaContent> &items) -{ - for (int i=0; i<items.count(); i++) { - if (!insertMedia(position+i,items.at(i))) - return false; - } - - return true; -} - -/*! - Move the media from position \a from to position \a to. - - Returns true if the operation is successful, otherwise false. - - \since 5.7 -*/ -bool QMediaPlaylistProvider::moveMedia(int from, int to) -{ - Q_UNUSED(from); - Q_UNUSED(to); - - return false; -} - -/*! - Removes the media at \a position from a playlist. - - Returns true if the media was removed; and false otherwise. -*/ -bool QMediaPlaylistProvider::removeMedia(int position) -{ - Q_UNUSED(position); - return false; -} - -/*! - Removes the media between the given \a start and \a end positions from a playlist. - - Returns true if the media was removed; and false otherwise. - */ -bool QMediaPlaylistProvider::removeMedia(int start, int end) -{ - for (int pos=end; pos>=start; pos--) { - if (!removeMedia(pos)) - return false; - } - - return true; -} - -/*! - Removes all media from a playlist. - - Returns true if the media was removed; and false otherwise. -*/ -bool QMediaPlaylistProvider::clear() -{ - return removeMedia(0, mediaCount()-1); -} - -/*! - Shuffles the contents of a playlist. -*/ -void QMediaPlaylistProvider::shuffle() -{ -} - -/*! - \fn void QMediaPlaylistProvider::mediaAboutToBeInserted(int start, int end); - - Signals that new media is about to be inserted into a playlist between the \a start and \a end - positions. -*/ - -/*! - \fn void QMediaPlaylistProvider::mediaInserted(int start, int end); - - Signals that new media has been inserted into a playlist between the \a start and \a end - positions. -*/ - -/*! - \fn void QMediaPlaylistProvider::mediaAboutToBeRemoved(int start, int end); - - Signals that media is about to be removed from a playlist between the \a start and \a end - positions. -*/ - -/*! - \fn void QMediaPlaylistProvider::mediaRemoved(int start, int end); - - Signals that media has been removed from a playlist between the \a start and \a end positions. -*/ - -/*! - \fn void QMediaPlaylistProvider::mediaChanged(int start, int end); - - Signals that media in playlist between the \a start and \a end positions inclusive has changed. -*/ - -/*! - \fn void QMediaPlaylistProvider::loaded() - - Signals that a load() finished successfully. -*/ - -/*! - \fn void QMediaPlaylistProvider::loadFailed(QMediaPlaylist::Error error, const QString& errorMessage) - - Signals that a load failed() due to an \a error. The \a errorMessage provides more information. -*/ - -QT_END_NAMESPACE - -#include "moc_qmediaplaylistprovider_p.cpp" diff --git a/src/multimedia/playback/qmediaplaylistprovider_p.h b/src/multimedia/playback/qmediaplaylistprovider_p.h deleted file mode 100644 index ed27612b9..000000000 --- a/src/multimedia/playback/qmediaplaylistprovider_p.h +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMEDIAPLAYLISTPROVIDER_P_H -#define QMEDIAPLAYLISTPROVIDER_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qmediacontent.h" -#include "qmediaplaylist.h" - -QT_BEGIN_NAMESPACE - - -class QMediaPlaylistProviderPrivate -{ -public: - QMediaPlaylistProviderPrivate() - {} - virtual ~QMediaPlaylistProviderPrivate() - {} -}; - -class Q_MULTIMEDIA_EXPORT QMediaPlaylistProvider : public QObject -{ -Q_OBJECT -public: - QMediaPlaylistProvider(QObject *parent = nullptr); - virtual ~QMediaPlaylistProvider(); - - virtual bool load(const QNetworkRequest &request, const char *format = nullptr); - virtual bool load(QIODevice *device, const char *format = nullptr); - virtual bool save(const QUrl &location, const char *format = nullptr); - virtual bool save(QIODevice * device, const char *format); - - virtual int mediaCount() const = 0; - virtual QMediaContent media(int index) const = 0; - - virtual bool isReadOnly() const; - - virtual bool addMedia(const QMediaContent &content); - virtual bool addMedia(const QList<QMediaContent> &contentList); - virtual bool insertMedia(int index, const QMediaContent &content); - virtual bool insertMedia(int index, const QList<QMediaContent> &content); - virtual bool moveMedia(int from, int to); - virtual bool removeMedia(int pos); - virtual bool removeMedia(int start, int end); - virtual bool clear(); - -public Q_SLOTS: - virtual void shuffle(); - -Q_SIGNALS: - void mediaAboutToBeInserted(int start, int end); - void mediaInserted(int start, int end); - - void mediaAboutToBeRemoved(int start, int end); - void mediaRemoved(int start, int end); - - void mediaChanged(int start, int end); - - void loaded(); - void loadFailed(QMediaPlaylist::Error, const QString& errorMessage); - -protected: - QMediaPlaylistProviderPrivate *d_ptr; - QMediaPlaylistProvider(QMediaPlaylistProviderPrivate &dd, QObject *parent); - -private: - Q_DECLARE_PRIVATE(QMediaPlaylistProvider) -}; - -QT_END_NAMESPACE - - - -#endif // QMEDIAPLAYLISTSOURCE_P_H diff --git a/src/multimedia/playback/qplaylistfileparser.cpp b/src/multimedia/playback/qplaylistfileparser.cpp index c1a423308..0ea920f9e 100644 --- a/src/multimedia/playback/qplaylistfileparser.cpp +++ b/src/multimedia/playback/qplaylistfileparser.cpp @@ -102,7 +102,7 @@ protected: void newItemFound(const QVariant& content) { Q_EMIT m_parent->newItem(content); } -private: +protected: QPlaylistFileParser *m_parent; bool m_aborted; }; @@ -165,7 +165,9 @@ public: m_extendedFormat = true; } } else { - m_extraInfo[QLatin1String("url")] = expandToFullPath(root, line); + QUrl url = expandToFullPath(root, line); + m_extraInfo[QLatin1String("url")] = url; + m_parent->playlist.append(url); newItemFound(QVariant(m_extraInfo)); m_extraInfo.clear(); } @@ -251,7 +253,9 @@ Version=2 if (value.isEmpty()) return true; - newItemFound(expandToFullPath(root, value)); + QUrl path = expandToFullPath(root, value); + m_parent->playlist.append(path); + newItemFound(path); return true; } @@ -294,7 +298,7 @@ public: QNetworkAccessManager m_mgr; QString m_mimeType; QPlaylistFileParser *q_ptr; - QIODevice *m_stream; + QPointer<QIODevice> m_stream; QPlaylistFileParser::FileType m_type; struct ParserJob { @@ -324,13 +328,15 @@ bool QPlaylistFileParserPrivate::processLine(int startIndex, int length) if (!m_currentParser) { const QString urlString = m_root.toString(); const QString &suffix = !urlString.isEmpty() ? QFileInfo(urlString).suffix() : urlString; - const QString &mimeType = m_source->header(QNetworkRequest::ContentTypeHeader).toString(); + QString mimeType; + if (m_source) + mimeType = m_source->header(QNetworkRequest::ContentTypeHeader).toString(); m_type = QPlaylistFileParser::findPlaylistType(suffix, !mimeType.isEmpty() ? mimeType : m_mimeType, m_buffer.constData(), quint32(m_buffer.size())); switch (m_type) { case QPlaylistFileParser::UNKNOWN: - emit q->error(QPlaylistFileParser::FormatError, - QPlaylistFileParser::tr("%1 playlist type is unknown").arg(m_root.toString())); + emit q->error(QMediaPlaylist::FormatError, + QMediaPlaylist::tr("%1 playlist type is unknown").arg(m_root.toString())); q->abort(); return false; case QPlaylistFileParser::M3U: @@ -365,10 +371,10 @@ bool QPlaylistFileParserPrivate::processLine(int startIndex, int length) void QPlaylistFileParserPrivate::handleData() { Q_Q(QPlaylistFileParser); - while (m_source->bytesAvailable() && !m_aborted) { - int expectedBytes = qMin(READ_LIMIT, int(qMin(m_source->bytesAvailable(), + while (m_stream->bytesAvailable() && !m_aborted) { + int expectedBytes = qMin(READ_LIMIT, int(qMin(m_stream->bytesAvailable(), qint64(LINE_LIMIT - m_buffer.size())))); - m_buffer.push_back(m_source->read(expectedBytes)); + m_buffer.push_back(m_stream->read(expectedBytes)); int processedBytes = 0; while (m_scanIndex < m_buffer.length() && !m_aborted) { char s = m_buffer[m_scanIndex]; @@ -379,7 +385,7 @@ void QPlaylistFileParserPrivate::handleData() break; } processedBytes = m_scanIndex + 1; - if (!m_source) { + if (!m_stream) { //some error happened, so exit parsing return; } @@ -391,12 +397,12 @@ void QPlaylistFileParserPrivate::handleData() break; if (m_buffer.length() - processedBytes >= LINE_LIMIT) { - emit q->error(QPlaylistFileParser::FormatError, QPlaylistFileParser::tr("invalid line in playlist file")); + emit q->error(QMediaPlaylist::FormatError, QMediaPlaylist::tr("invalid line in playlist file")); q->abort(); break; } - if (m_source->isFinished() && !m_source->bytesAvailable()) { + if (!m_stream->bytesAvailable() && (!m_source || !m_source->isFinished())) { //last line processLine(processedBytes, -1); break; @@ -489,6 +495,10 @@ QPlaylistFileParser::FileType QPlaylistFileParser::findPlaylistType(const QStrin if (mimeType != UNKNOWN) return mimeType; + mimeType = findBySuffixType(mime); + if (mimeType != UNKNOWN) + return mimeType; + FileType suffixType = findBySuffixType(suffix); if (suffixType != UNKNOWN) return suffixType; @@ -513,7 +523,7 @@ void QPlaylistFileParser::start(QIODevice *stream, const QString &mimeType) const bool validStream = stream ? (stream->isOpen() && stream->isReadable()) : false; if (!validStream) { - Q_EMIT error(ResourceError, tr("Invalid stream")); + Q_EMIT error(QMediaPlaylist::AccessDeniedError, QMediaPlaylist::tr("Invalid stream")); return; } @@ -523,10 +533,11 @@ void QPlaylistFileParser::start(QIODevice *stream, const QString &mimeType) return; } + playlist.clear(); d->reset(); d->m_mimeType = mimeType; d->m_stream = stream; - connect(d->m_stream, SIGNAL(readyRead()), this, SLOT(_q_handleData())); + connect(d->m_stream, SIGNAL(readyRead()), this, SLOT(handleData())); d->handleData(); } @@ -536,7 +547,7 @@ void QPlaylistFileParser::start(const QNetworkRequest& request, const QString &m const QUrl &url = request.url(); if (url.isLocalFile() && !QFile::exists(url.toLocalFile())) { - emit error(ResourceError, QString(tr("%1 does not exist")).arg(url.toString())); + emit error(QMediaPlaylist::AccessDeniedError, QString(QMediaPlaylist::tr("%1 does not exist")).arg(url.toString())); return; } @@ -550,6 +561,7 @@ void QPlaylistFileParser::start(const QNetworkRequest& request, const QString &m d->m_root = url; d->m_mimeType = mimeType; d->m_source.reset(d->m_mgr.get(request)); + d->m_stream = d->m_source.get(); connect(d->m_source.data(), SIGNAL(readyRead()), this, SLOT(handleData())); connect(d->m_source.data(), SIGNAL(finished()), this, SLOT(handleData())); connect(d->m_source.data(), SIGNAL(errorOccurred(QNetworkReply::NetworkError)), this, SLOT(handleError())); @@ -568,6 +580,8 @@ void QPlaylistFileParser::abort() if (d->m_stream) disconnect(d->m_stream, SIGNAL(readyRead()), this, SLOT(handleData())); + + playlist.clear(); } void QPlaylistFileParser::handleData() @@ -581,7 +595,7 @@ void QPlaylistFileParserPrivate::handleParserFinished() Q_Q(QPlaylistFileParser); const bool isParserValid = !m_currentParser.isNull(); if (!isParserValid && !m_aborted) - emit q->error(QPlaylistFileParser::FormatNotSupportedError, QPlaylistFileParser::tr("Empty file provided")); + emit q->error(QMediaPlaylist::FormatNotSupportedError, QMediaPlaylist::tr("Empty file provided")); if (isParserValid && !m_aborted) { m_currentParser.reset(); @@ -612,7 +626,7 @@ void QPlaylistFileParserPrivate::reset() m_buffer.clear(); m_root.clear(); m_mimeType.clear(); - m_stream = 0; + m_stream = nullptr; m_type = QPlaylistFileParser::UNKNOWN; m_scanIndex = 0; m_lineIndex = -1; @@ -625,7 +639,7 @@ void QPlaylistFileParser::handleError() { Q_D(QPlaylistFileParser); const QString &errorString = d->m_source->errorString(); - Q_EMIT error(QPlaylistFileParser::NetworkError, errorString); + Q_EMIT error(QMediaPlaylist::NetworkError, errorString); abort(); } diff --git a/src/multimedia/playback/qplaylistfileparser_p.h b/src/multimedia/playback/qplaylistfileparser_p.h index cf96ccdbf..388ce72ed 100644 --- a/src/multimedia/playback/qplaylistfileparser_p.h +++ b/src/multimedia/playback/qplaylistfileparser_p.h @@ -53,6 +53,7 @@ #include "qtmultimediaglobal.h" #include <QtCore/qobject.h> +#include <qmediaplaylist.h> QT_BEGIN_NAMESPACE @@ -77,30 +78,23 @@ public: PLS }; - enum ParserError - { - NoError, - FormatError, - FormatNotSupportedError, - ResourceError, - NetworkError - }; - void start(const QMediaContent &media, QIODevice *stream = nullptr, const QString &mimeType = QString()); void start(const QNetworkRequest &request, const QString &mimeType = QString()); + void start(QIODevice *stream, const QString &mimeType = QString()); void abort(); + QList<QMediaContent> playlist; + Q_SIGNALS: void newItem(const QVariant& content); void finished(); - void error(QPlaylistFileParser::ParserError err, const QString& errorMsg); + void error(QMediaPlaylist::Error err, const QString& errorMsg); private Q_SLOTS: void handleData(); void handleError(); private: - void start(QIODevice *stream, const QString &mimeType = QString()); static FileType findByMimeType(const QString &mime); static FileType findBySuffixType(const QString &suffix); diff --git a/src/multimedia/qmediaserviceproviderplugin.h b/src/multimedia/qmediaserviceproviderplugin.h index 3337b2e72..702ca4f55 100644 --- a/src/multimedia/qmediaserviceproviderplugin.h +++ b/src/multimedia/qmediaserviceproviderplugin.h @@ -202,7 +202,7 @@ public: /*! Service with support for media playback Required Controls: QMediaPlayerControl - Optional Controls: QMediaPlaylistControl, QAudioDeviceControl + Optional Controls: QAudioDeviceControl Video Output Controls (used by QWideoWidget and QGraphicsVideoItem): Required: QVideoOutputControl Optional: QVideoWindowControl, QVideoRendererControl, QVideoWidgetControl diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.cpp b/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.cpp index 320d6801c..1e3eec554 100644 --- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.cpp +++ b/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.cpp @@ -60,7 +60,6 @@ #include <private/qgstreamerplayersession_p.h> #include <private/qgstreamerplayercontrol_p.h> -#include <private/qmediaplaylistnavigator_p.h> #include <qmediaplaylist.h> QT_BEGIN_NAMESPACE diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.h b/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.h index 3d4923d93..f95ebc658 100644 --- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.h +++ b/src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.h @@ -48,7 +48,6 @@ QT_BEGIN_NAMESPACE class QMediaPlayerControl; class QMediaPlaylist; -class QMediaPlaylistNavigator; class QGstreamerMetaData; class QGstreamerPlayerControl; diff --git a/src/plugins/m3u/m3u.json b/src/plugins/m3u/m3u.json deleted file mode 100644 index 2d69fab8e..000000000 --- a/src/plugins/m3u/m3u.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "Keys": ["m3u"] -} diff --git a/src/plugins/m3u/m3u.pro b/src/plugins/m3u/m3u.pro deleted file mode 100644 index d46911e0d..000000000 --- a/src/plugins/m3u/m3u.pro +++ /dev/null @@ -1,12 +0,0 @@ -TARGET = qtmultimedia_m3u -QT += multimedia-private - -HEADERS += qm3uhandler.h -SOURCES += qm3uhandler.cpp - -OTHER_FILES += \ - m3u.json - -PLUGIN_TYPE = playlistformats -PLUGIN_CLASS_NAME = QM3uPlaylistPlugin -load(qt_plugin) diff --git a/src/plugins/m3u/qm3uhandler.cpp b/src/plugins/m3u/qm3uhandler.cpp deleted file mode 100644 index b88e3e292..000000000 --- a/src/plugins/m3u/qm3uhandler.cpp +++ /dev/null @@ -1,229 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qm3uhandler.h" -#include <QtCore/qiodevice.h> -#include <QtCore/qfileinfo.h> -#include <QtCore/qtextstream.h> -#include <QFile> -#include <QUrl> - - -class QM3uPlaylistReader : public QMediaPlaylistReader -{ -public: - QM3uPlaylistReader(QIODevice *device) - :m_ownDevice(false), m_device(device), m_textStream(new QTextStream(m_device)) - { - readItem(); - } - - QM3uPlaylistReader(const QUrl& location) - :m_location(location), m_ownDevice(true) - { - QFile *f = new QFile(location.toLocalFile()); - if (f->open(QIODevice::ReadOnly | QIODevice::Text)) { - m_device = f; - m_textStream = new QTextStream(m_device); - readItem(); - } else { - delete f; - m_device = 0; - m_textStream = 0; - } - } - - virtual ~QM3uPlaylistReader() - { - if (m_ownDevice) { - delete m_device; - } - delete m_textStream; - } - - bool atEnd() const override - { - //we can't just use m_textStream->atEnd(), - //for files with empty lines/comments at end - return nextResource.isNull(); - } - - QMediaContent readItem() override - { - QMediaContent item; - if (!nextResource.isNull()) - item = QMediaContent(nextResource); - - nextResource = QMediaContent(); - - while (m_textStream && !m_textStream->atEnd()) { - QString line = m_textStream->readLine().trimmed(); - if (line.isEmpty() || line[0] == '#' || line.size() > 4096) - continue; - - QUrl fileUrl = QUrl::fromLocalFile(line); - QUrl url(line); - - //m3u may contain url encoded entries or absolute/relative file names - //prefer existing file if any - QList<QUrl> candidates; - if (!m_location.isEmpty()) { - candidates << m_location.resolved(fileUrl); - candidates << m_location.resolved(url); - } - candidates << fileUrl; - candidates << url; - - for (const QUrl &candidate : qAsConst(candidates)) { - if (QFile::exists(candidate.toLocalFile())) { - nextResource = candidate; - break; - } - } - - if (nextResource.isNull()) { - //assume the relative urls are file names, not encoded urls if m3u is local file - if (!m_location.isEmpty() && url.isRelative()) { - if (m_location.scheme() == QLatin1String("file")) - nextResource = m_location.resolved(fileUrl); - else - nextResource = m_location.resolved(url); - } else { - nextResource = QMediaContent(QUrl::fromUserInput(line)); - } - } - - break; - } - - return item; - } - - void close() override - { - } - -private: - QUrl m_location; - bool m_ownDevice; - QIODevice *m_device; - QTextStream *m_textStream; - QMediaContent nextResource; -}; - -class QM3uPlaylistWriter : public QMediaPlaylistWriter -{ -public: - QM3uPlaylistWriter(QIODevice *device) - :m_device(device), m_textStream(new QTextStream(m_device)) - { - } - - virtual ~QM3uPlaylistWriter() - { - delete m_textStream; - } - - bool writeItem(const QMediaContent& item) override - { - *m_textStream << item.request().url().toString() << Qt::endl; - return true; - } - - void close() override - { - } - -private: - QIODevice *m_device; - QTextStream *m_textStream; -}; - - -QM3uPlaylistPlugin::QM3uPlaylistPlugin(QObject *parent) - :QMediaPlaylistIOPlugin(parent) -{ -} - -QM3uPlaylistPlugin::~QM3uPlaylistPlugin() -{ -} - -bool QM3uPlaylistPlugin::canRead(QIODevice *device, const QByteArray &format) const -{ - return device->isReadable() && (format == "m3u" || format == "m3u8" || format.isEmpty()); -} - -bool QM3uPlaylistPlugin::canRead(const QUrl& location, const QByteArray &format) const -{ - if (!QFileInfo(location.toLocalFile()).isReadable()) - return false; - - if (format == "m3u" || format == "m3u8") - return true; - - if (!format.isEmpty()) - return false; - QString localFile = location.toLocalFile().toLower(); - return localFile.endsWith(QLatin1String("m3u")) || localFile.endsWith(QLatin1String("m3u8")); -} - -bool QM3uPlaylistPlugin::canWrite(QIODevice *device, const QByteArray &format) const -{ - return device->isOpen() && device->isWritable() && (format == "m3u" || format == "m3u8"); -} - -QMediaPlaylistReader *QM3uPlaylistPlugin::createReader(QIODevice *device, const QByteArray &format) -{ - Q_UNUSED(format); - return new QM3uPlaylistReader(device); -} - -QMediaPlaylistReader *QM3uPlaylistPlugin::createReader(const QUrl& location, const QByteArray &format) -{ - Q_UNUSED(format); - return new QM3uPlaylistReader(location); -} - -QMediaPlaylistWriter *QM3uPlaylistPlugin::createWriter(QIODevice *device, const QByteArray &format) -{ - Q_UNUSED(format); - return new QM3uPlaylistWriter(device); -} - diff --git a/src/plugins/m3u/qm3uhandler.h b/src/plugins/m3u/qm3uhandler.h deleted file mode 100644 index 1bc0684d3..000000000 --- a/src/plugins/m3u/qm3uhandler.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QM3UHANDLER_H -#define QM3UHANDLER_H - -#include <private/qmediaplaylistioplugin_p.h> -#include <QtCore/QObject> - -QT_USE_NAMESPACE - -class QM3uPlaylistPlugin : public QMediaPlaylistIOPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaplaylistio/5.0" FILE "m3u.json") - -public: - explicit QM3uPlaylistPlugin(QObject *parent = 0); - virtual ~QM3uPlaylistPlugin(); - - bool canRead(QIODevice *device, const QByteArray &format = QByteArray()) const override; - bool canRead(const QUrl& location, const QByteArray &format = QByteArray()) const override; - - bool canWrite(QIODevice *device, const QByteArray &format) const override; - - QMediaPlaylistReader *createReader(QIODevice *device, const QByteArray &format = QByteArray()) override; - QMediaPlaylistReader *createReader(const QUrl& location, const QByteArray &format = QByteArray()) override; - - QMediaPlaylistWriter *createWriter(QIODevice *device, const QByteArray &format) override; -}; - -#endif // QM3UHANDLER_H diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 94592f013..6ddc58e7d 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -7,8 +7,6 @@ TEMPLATE = subdirs QT_FOR_CONFIG += multimedia-private -SUBDIRS += m3u - qtHaveModule(quick) { SUBDIRS += videonode } diff --git a/tests/auto/unit/multimedia.pro b/tests/auto/unit/multimedia.pro index 3e0311a66..f9cd0ac29 100644 --- a/tests/auto/unit/multimedia.pro +++ b/tests/auto/unit/multimedia.pro @@ -15,7 +15,6 @@ SUBDIRS += \ qmediaobject \ qmediaplayer \ qmediaplaylist \ - qmediaplaylistnavigator \ qmediapluginloader \ qmediarecorder \ qmediaservice \ diff --git a/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp b/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp index ed2a9dd42..5963aface 100644 --- a/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp +++ b/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp @@ -792,6 +792,8 @@ void tst_QMediaPlayer::testPlaylist() // Test changing the playlist position, changes the current media, but not the playing state. playlist->setCurrentIndex(1); + QCOMPARE(playlist->currentIndex(), 1); + QCOMPARE(playlist->currentMedia(), content1); QCOMPARE(player->currentMedia(), content1); QCOMPARE(player->state(), QMediaPlayer::StoppedState); QCOMPARE(stateSpy.count(), 0); @@ -827,6 +829,7 @@ void tst_QMediaPlayer::testPlaylist() QCOMPARE(mediaSpy.count(), 1); mockService->setState(QMediaPlayer::StoppedState, QMediaPlayer::EndOfMedia); + QCOMPARE(playlist->currentMedia(), content2); QCOMPARE(player->currentMedia(), content2); QCOMPARE(player->state(), QMediaPlayer::PlayingState); QCOMPARE(stateSpy.count(), 4); diff --git a/tests/auto/unit/qmediaplaylist/qmediaplaylist.pro b/tests/auto/unit/qmediaplaylist/qmediaplaylist.pro index 78a9ea7e8..663d8d92f 100644 --- a/tests/auto/unit/qmediaplaylist/qmediaplaylist.pro +++ b/tests/auto/unit/qmediaplaylist/qmediaplaylist.pro @@ -1,8 +1,6 @@ CONFIG += testcase TARGET = tst_qmediaplaylist -include (../qmultimedia_common/mockplaylist.pri) - QT += multimedia-private testlib SOURCES += \ diff --git a/tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp b/tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp index e33c97140..3b2f93fee 100644 --- a/tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp +++ b/tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp @@ -30,32 +30,12 @@ #include <QDebug> #include "qmediaservice.h" #include "qmediaplaylist.h" -#include <private/qmediaplaylistcontrol_p.h> -#include <private/qmediaplaylistnavigator_p.h> #include <private/qmediapluginloader_p.h> -#include "qm3uhandler.h" - //TESTED_COMPONENT=src/multimedia -#include "mockplaylistservice.h" -#include "mockmediaplaylistcontrol.h" -#include "mockreadonlyplaylistprovider.h" - QT_USE_NAMESPACE -class MockPlaylistObject : public QMediaObject -{ - Q_OBJECT -public: - MockPlaylistObject(QObject *parent = 0) - : QMediaObject(parent, mockService = new MockPlaylistService) - { - } - - MockPlaylistService *mockService; -}; - class tst_QMediaPlaylist : public QObject { Q_OBJECT @@ -77,7 +57,6 @@ private slots: void playbackMode(); void playbackMode_data(); void shuffle(); - void readOnlyPlaylist(); void setMediaObject(); void testCurrentIndexChanged_signal(); @@ -87,11 +66,6 @@ private slots: void testPlaybackModeChanged_signal(); void testEnums(); - void mediaPlayListProvider(); - // TC for Abstract control classes - void mediaPlayListControl(); - - private: QMediaContent content1; QMediaContent content2; @@ -125,7 +99,6 @@ void tst_QMediaPlaylist::construction() void tst_QMediaPlaylist::append() { QMediaPlaylist playlist; - QVERIFY(!playlist.isReadOnly()); playlist.addMedia(content1); QCOMPARE(playlist.mediaCount(), 1); @@ -175,7 +148,6 @@ void tst_QMediaPlaylist::append() void tst_QMediaPlaylist::insert() { QMediaPlaylist playlist; - QVERIFY(!playlist.isReadOnly()); playlist.addMedia(content1); QCOMPARE(playlist.mediaCount(), 1); @@ -468,6 +440,7 @@ void tst_QMediaPlaylist::saveAndLoad() QVERIFY(playlist.error() != QMediaPlaylist::NoError); QVERIFY(!playlist.errorString().isEmpty()); + res = playlist.save(QUrl::fromLocalFile(QLatin1String("tmp.unsupported_format")), "unsupported_format"); QVERIFY(!res); QVERIFY(playlist.error() != QMediaPlaylist::NoError); @@ -475,11 +448,13 @@ void tst_QMediaPlaylist::saveAndLoad() loadedSignal.clear(); errorSignal.clear(); - playlist.load(QUrl::fromLocalFile(QLatin1String("tmp.unsupported_format")), "unsupported_format"); + QUrl testFileName = QUrl::fromLocalFile(QFINDTESTDATA("testdata") + "/testfile"); + playlist.load(testFileName, "unsupported_format"); QTRY_VERIFY(loadedSignal.isEmpty()); QCOMPARE(errorSignal.size(), 1); QVERIFY(playlist.error() == QMediaPlaylist::FormatNotSupportedError); QVERIFY(!playlist.errorString().isEmpty()); + QVERIFY(playlist.mediaCount() == 3); res = playlist.save(&buffer, "m3u"); @@ -703,73 +678,6 @@ void tst_QMediaPlaylist::shuffle() } -void tst_QMediaPlaylist::readOnlyPlaylist() -{ - MockPlaylistObject mediaObject; - mediaObject.mockService->mockControl->setReadOnly(true); - - QMediaPlaylist playlist; - mediaObject.bind(&playlist); - - QVERIFY(playlist.isReadOnly()); - QVERIFY(!playlist.isEmpty()); - QCOMPARE(playlist.mediaCount(), 3); - - QCOMPARE(playlist.media(0), content1); - QCOMPARE(playlist.media(1), content2); - QCOMPARE(playlist.media(2), content3); - QCOMPARE(playlist.media(3), QMediaContent()); - - //it's a read only playlist, so all the modification should fail - QVERIFY(!playlist.addMedia(content1)); - QCOMPARE(playlist.mediaCount(), 3); - QVERIFY(!playlist.addMedia(QList<QMediaContent>() << content1 << content2)); - QCOMPARE(playlist.mediaCount(), 3); - QVERIFY(!playlist.insertMedia(1, content1)); - QCOMPARE(playlist.mediaCount(), 3); - QVERIFY(!playlist.insertMedia(1, QList<QMediaContent>() << content1 << content2)); - QCOMPARE(playlist.mediaCount(), 3); - QVERIFY(!playlist.removeMedia(1)); - QCOMPARE(playlist.mediaCount(), 3); - QVERIFY(!playlist.removeMedia(0,2)); - QCOMPARE(playlist.mediaCount(), 3); - QVERIFY(!playlist.clear()); - QCOMPARE(playlist.mediaCount(), 3); - - //but it is still allowed to append/insert an empty list - QVERIFY(playlist.addMedia(QList<QMediaContent>())); - QVERIFY(playlist.insertMedia(1, QList<QMediaContent>())); - - playlist.shuffle(); - //it's still the same - QCOMPARE(playlist.media(0), content1); - QCOMPARE(playlist.media(1), content2); - QCOMPARE(playlist.media(2), content3); - QCOMPARE(playlist.media(3), QMediaContent()); - - - //load to read only playlist should fail, - //unless underlaying provider supports it - QBuffer buffer; - buffer.open(QBuffer::ReadWrite); - buffer.write(QByteArray("file:///1\nfile:///2")); - buffer.seek(0); - - QSignalSpy errorSignal(&playlist, SIGNAL(loadFailed())); - playlist.load(&buffer, "m3u"); - QCOMPARE(errorSignal.size(), 1); - QCOMPARE(playlist.error(), QMediaPlaylist::AccessDeniedError); - QVERIFY(!playlist.errorString().isEmpty()); - QCOMPARE(playlist.mediaCount(), 3); - - errorSignal.clear(); - playlist.load(QUrl::fromLocalFile(QLatin1String("tmp.m3u")), "m3u"); - - QCOMPARE(errorSignal.size(), 1); - QCOMPARE(playlist.error(), QMediaPlaylist::AccessDeniedError); - QVERIFY(!playlist.errorString().isEmpty()); - QCOMPARE(playlist.mediaCount(), 3); -} void tst_QMediaPlaylist::setMediaObject() { @@ -779,8 +687,6 @@ void tst_QMediaPlaylist::setMediaObject() QMediaContent content3(QUrl(QLatin1String("test://video/movie2.mp4"))); { - MockPlaylistObject mediaObject; - QMediaPlaylist playlist; QSignalSpy currentIndexSpy(&playlist, SIGNAL(currentIndexChanged(int))); QSignalSpy playbackModeSpy(&playlist, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode))); @@ -792,9 +698,6 @@ void tst_QMediaPlaylist::setMediaObject() QVERIFY(playlist.isEmpty()); - mediaObject.bind(&playlist); - - // Playlist is now using the service's control, nothing should have changed QVERIFY(playlist.isEmpty()); QCOMPARE(playlist.currentIndex(), -1); QCOMPARE(playlist.playbackMode(), QMediaPlaylist::Sequential); @@ -806,15 +709,14 @@ void tst_QMediaPlaylist::setMediaObject() QCOMPARE(mediaRemovedSpy.count(), 0); QCOMPARE(mediaChangedSpy.count(), 0); - // add items to service's playlist control + // add items to playlist playlist.addMedia(content0); playlist.addMedia(content1); playlist.setCurrentIndex(1); - playlist.setPlaybackMode(QMediaPlaylist::Random); + playlist.shuffle(); QCOMPARE(playlist.mediaCount(), 2); QCOMPARE(playlist.currentIndex(), 1); QCOMPARE(playlist.currentMedia(), content1); - QCOMPARE(playlist.playbackMode(), QMediaPlaylist::Random); currentIndexSpy.clear(); playbackModeSpy.clear(); @@ -823,24 +725,8 @@ void tst_QMediaPlaylist::setMediaObject() mediaAboutToBeRemovedSpy.clear(); mediaRemovedSpy.clear(); mediaChangedSpy.clear(); - - // unbind the playlist, reverting back to the internal control. - // playlist content should't have changed. - mediaObject.unbind(&playlist); - QCOMPARE(playlist.mediaCount(), 2); - QCOMPARE(playlist.currentIndex(), 1); - QCOMPARE(playlist.currentMedia(), content1); - QCOMPARE(playlist.playbackMode(), QMediaPlaylist::Random); - QCOMPARE(playbackModeSpy.count(), 0); - QCOMPARE(mediaAboutToBeInsertedSpy.count(), 0); - QCOMPARE(mediaInsertedSpy.count(), 0); - QCOMPARE(mediaAboutToBeRemovedSpy.count(), 0); - QCOMPARE(mediaRemovedSpy.count(), 0); - QCOMPARE(mediaChangedSpy.count(), 0); } { - MockPlaylistObject mediaObject; - QMediaPlaylist playlist; QVERIFY(playlist.isEmpty()); // Add items to playlist before binding to the service (internal control) @@ -858,8 +744,6 @@ void tst_QMediaPlaylist::setMediaObject() QSignalSpy mediaRemovedSpy(&playlist, SIGNAL(mediaRemoved(int, int))); QSignalSpy mediaChangedSpy(&playlist, SIGNAL(mediaChanged(int, int))); - // Bind playlist, content should be unchanged - mediaObject.bind(&playlist); QCOMPARE(playlist.mediaCount(), 3); QCOMPARE(playlist.currentIndex(), 2); QCOMPARE(playlist.currentMedia(), content2); @@ -875,7 +759,7 @@ void tst_QMediaPlaylist::setMediaObject() // Clear playlist content (service's playlist control) playlist.clear(); playlist.setCurrentIndex(-1); - playlist.setPlaybackMode(QMediaPlaylist::Random); + playlist.shuffle(); currentIndexSpy.clear(); playbackModeSpy.clear(); @@ -884,168 +768,6 @@ void tst_QMediaPlaylist::setMediaObject() mediaAboutToBeRemovedSpy.clear(); mediaRemovedSpy.clear(); mediaChangedSpy.clear(); - - // unbind playlist from service, reverting back to the internal control. - // playlist should still be empty - mediaObject.unbind(&playlist); - QCOMPARE(playlist.mediaCount(), 0); - QCOMPARE(playlist.currentIndex(), -1); - QCOMPARE(playlist.currentMedia(), QMediaContent()); - QCOMPARE(playlist.playbackMode(), QMediaPlaylist::Random); - QCOMPARE(playbackModeSpy.count(), 0); - QCOMPARE(mediaAboutToBeInsertedSpy.count(), 0); - QCOMPARE(mediaInsertedSpy.count(), 0); - QCOMPARE(mediaAboutToBeRemovedSpy.count(), 0); - QCOMPARE(mediaRemovedSpy.count(), 0); - QCOMPARE(mediaChangedSpy.count(), 0); - } - { - MockPlaylistObject mediaObject; - - QMediaPlaylist playlist; - QVERIFY(playlist.isEmpty()); - // Add items to playlist before attaching to media player (internal control) - playlist.addMedia(content0); - playlist.addMedia(content1); - playlist.setCurrentIndex(-1); - playlist.setPlaybackMode(QMediaPlaylist::CurrentItemOnce); - - // Add items to service's playlist before binding - QMediaPlaylistProvider *pp = mediaObject.mockService->mockControl->playlistProvider(); - pp->addMedia(content2); - pp->addMedia(content3); - mediaObject.mockService->mockControl->setCurrentIndex(1); - mediaObject.mockService->mockControl->setPlaybackMode(QMediaPlaylist::Random); - - QSignalSpy currentIndexSpy(&playlist, SIGNAL(currentIndexChanged(int))); - QSignalSpy playbackModeSpy(&playlist, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode))); - QSignalSpy mediaAboutToBeInsertedSpy(&playlist, SIGNAL(mediaAboutToBeInserted(int, int))); - QSignalSpy mediaInsertedSpy(&playlist, SIGNAL(mediaInserted(int, int))); - QSignalSpy mediaAboutToBeRemovedSpy(&playlist, SIGNAL(mediaAboutToBeRemoved(int, int))); - QSignalSpy mediaRemovedSpy(&playlist, SIGNAL(mediaRemoved(int, int))); - QSignalSpy mediaChangedSpy(&playlist, SIGNAL(mediaChanged(int, int))); - - // Bind playlist, it should contain only what was explicitly added to the playlist. - // Anything that was present in the service's control should have been cleared - mediaObject.bind(&playlist); - QCOMPARE(playlist.mediaCount(), 2); - QCOMPARE(playlist.currentIndex(), -1); - QCOMPARE(playlist.playbackMode(), QMediaPlaylist::CurrentItemOnce); - QCOMPARE(currentIndexSpy.count(), 0); - QCOMPARE(playbackModeSpy.count(), 0); - QCOMPARE(mediaAboutToBeInsertedSpy.count(), 0); - QCOMPARE(mediaInsertedSpy.count(), 0); - QCOMPARE(mediaAboutToBeRemovedSpy.count(), 0); - QCOMPARE(mediaRemovedSpy.count(), 0); - QCOMPARE(mediaChangedSpy.count(), 0); - - // do some changes - playlist.removeMedia(0); // content0 - playlist.addMedia(content3); - playlist.setCurrentIndex(0); - - currentIndexSpy.clear(); - playbackModeSpy.clear(); - mediaAboutToBeInsertedSpy.clear(); - mediaInsertedSpy.clear(); - mediaAboutToBeRemovedSpy.clear(); - mediaRemovedSpy.clear(); - mediaChangedSpy.clear(); - - // unbind playlist from service - mediaObject.unbind(&playlist); - QCOMPARE(playlist.mediaCount(), 2); - QCOMPARE(playlist.currentIndex(), 0); - QCOMPARE(playlist.currentMedia(), content1); - QCOMPARE(playlist.playbackMode(), QMediaPlaylist::CurrentItemOnce); - QCOMPARE(currentIndexSpy.count(), 0); - QCOMPARE(playbackModeSpy.count(), 0); - QCOMPARE(mediaAboutToBeInsertedSpy.count(), 0); - QCOMPARE(mediaInsertedSpy.count(), 0); - QCOMPARE(mediaAboutToBeRemovedSpy.count(), 0); - QCOMPARE(mediaRemovedSpy.count(), 0); - QCOMPARE(mediaChangedSpy.count(), 0); - - // bind again, nothing should have changed - mediaObject.bind(&playlist); - QCOMPARE(playlist.mediaCount(), 2); - QCOMPARE(playlist.currentIndex(), 0); - QCOMPARE(playlist.currentMedia(), content1); - QCOMPARE(playlist.playbackMode(), QMediaPlaylist::CurrentItemOnce); - QCOMPARE(currentIndexSpy.count(), 0); - QCOMPARE(playbackModeSpy.count(), 0); - QCOMPARE(mediaAboutToBeInsertedSpy.count(), 0); - QCOMPARE(mediaInsertedSpy.count(), 0); - QCOMPARE(mediaAboutToBeRemovedSpy.count(), 0); - QCOMPARE(mediaRemovedSpy.count(), 0); - QCOMPARE(mediaChangedSpy.count(), 0); - } - { - MockPlaylistObject mediaObject; - mediaObject.mockService->mockControl->setReadOnly(true); - - QMediaPlaylist playlist; - QVERIFY(playlist.isEmpty()); - // Add items to playlist before binding to the service internal control) - playlist.addMedia(content0); - playlist.addMedia(content1); - playlist.setCurrentIndex(-1); - playlist.setPlaybackMode(QMediaPlaylist::CurrentItemOnce); - - QSignalSpy currentIndexSpy(&playlist, SIGNAL(currentIndexChanged(int))); - QSignalSpy playbackModeSpy(&playlist, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode))); - QSignalSpy mediaAboutToBeInsertedSpy(&playlist, SIGNAL(mediaAboutToBeInserted(int, int))); - QSignalSpy mediaInsertedSpy(&playlist, SIGNAL(mediaInserted(int, int))); - QSignalSpy mediaAboutToBeRemovedSpy(&playlist, SIGNAL(mediaAboutToBeRemoved(int, int))); - QSignalSpy mediaRemovedSpy(&playlist, SIGNAL(mediaRemoved(int, int))); - QSignalSpy mediaChangedSpy(&playlist, SIGNAL(mediaChanged(int, int))); - - // Bind playlist. Since the service's control is read-only, no synchronization - // should be done with the internal control. The mediaRemoved() and mediaInserted() - // should be emitted to notify about the change. - mediaObject.bind(&playlist); - QCOMPARE(playlist.mediaCount(), 3); - QCOMPARE(playlist.currentIndex(), -1); - QCOMPARE(playlist.playbackMode(), QMediaPlaylist::CurrentItemOnce); - QCOMPARE(currentIndexSpy.count(), 0); - QCOMPARE(playbackModeSpy.count(), 0); - - QCOMPARE(mediaAboutToBeRemovedSpy.count(), 1); - QCOMPARE(mediaAboutToBeRemovedSpy.last().at(0).toInt(), 0); - QCOMPARE(mediaAboutToBeRemovedSpy.last().at(1).toInt(), 1); - QCOMPARE(mediaRemovedSpy.count(), 1); - QCOMPARE(mediaRemovedSpy.last().at(0).toInt(), 0); - QCOMPARE(mediaRemovedSpy.last().at(1).toInt(), 1); - - QCOMPARE(mediaAboutToBeInsertedSpy.count(), 1); - QCOMPARE(mediaAboutToBeInsertedSpy.last().at(0).toInt(), 0); - QCOMPARE(mediaAboutToBeInsertedSpy.last().at(1).toInt(), 2); - QCOMPARE(mediaInsertedSpy.count(), 1); - QCOMPARE(mediaInsertedSpy.last().at(0).toInt(), 0); - QCOMPARE(mediaInsertedSpy.last().at(1).toInt(), 2); - - QCOMPARE(mediaChangedSpy.count(), 0); - - currentIndexSpy.clear(); - playbackModeSpy.clear(); - mediaAboutToBeInsertedSpy.clear(); - mediaInsertedSpy.clear(); - mediaAboutToBeRemovedSpy.clear(); - mediaRemovedSpy.clear(); - mediaChangedSpy.clear(); - - // detach playlist from player - mediaObject.unbind(&playlist); - QCOMPARE(playlist.mediaCount(), 3); - QCOMPARE(playlist.currentIndex(), -1); - QCOMPARE(playlist.playbackMode(), QMediaPlaylist::CurrentItemOnce); - QCOMPARE(currentIndexSpy.count(), 0); - QCOMPARE(playbackModeSpy.count(), 0); - QCOMPARE(mediaAboutToBeInsertedSpy.count(), 0); - QCOMPARE(mediaInsertedSpy.count(), 0); - QCOMPARE(mediaAboutToBeRemovedSpy.count(), 0); - QCOMPARE(mediaRemovedSpy.count(), 0); - QCOMPARE(mediaChangedSpy.count(), 0); } } @@ -1108,6 +830,7 @@ void tst_QMediaPlaylist::testLoaded_signal() QVERIFY(spy.size()== 0); QBuffer buffer; + buffer.setData(QByteArray("foo.mp3")); buffer.open(QBuffer::ReadWrite); //load the playlist @@ -1183,11 +906,6 @@ void tst_QMediaPlaylist::testPlaybackModeChanged_signal() playlist.setPlaybackMode(QMediaPlaylist::Loop); QVERIFY(playlist.playbackMode()== QMediaPlaylist::Loop); QVERIFY(spy.size() == 4); - - // Set playback mode to the playlist - playlist.setPlaybackMode(QMediaPlaylist::Random); - QVERIFY(playlist.playbackMode()== QMediaPlaylist::Random); - QVERIFY(spy.size() == 5); } void tst_QMediaPlaylist::testEnums() @@ -1210,22 +928,6 @@ void tst_QMediaPlaylist::testEnums() QVERIFY(playlist.error() == QMediaPlaylist::FormatNotSupportedError); } -// MaemoAPI-1849:test QMediaPlayListControl constructor -void tst_QMediaPlaylist::mediaPlayListControl() -{ - // To check changes in abstract classe's pure virtual functions - QObject parent; - MockMediaPlaylistControl plylistctrl(false, &parent); -} - -// MaemoAPI-1852:test constructor -void tst_QMediaPlaylist::mediaPlayListProvider() -{ - // srcs of QMediaPlaylistProvider is incomplete - QObject parent; - MockReadOnlyPlaylistProvider provider(&parent); -} - QTEST_MAIN(tst_QMediaPlaylist) #include "tst_qmediaplaylist.moc" diff --git a/tests/auto/unit/qmediaplaylistnavigator/qmediaplaylistnavigator.pro b/tests/auto/unit/qmediaplaylistnavigator/qmediaplaylistnavigator.pro deleted file mode 100644 index 042e6ac4c..000000000 --- a/tests/auto/unit/qmediaplaylistnavigator/qmediaplaylistnavigator.pro +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG += testcase -TARGET = tst_qmediaplaylistnavigator - -QT += multimedia-private testlib - -SOURCES += tst_qmediaplaylistnavigator.cpp - diff --git a/tests/auto/unit/qmediaplaylistnavigator/tst_qmediaplaylistnavigator.cpp b/tests/auto/unit/qmediaplaylistnavigator/tst_qmediaplaylistnavigator.cpp deleted file mode 100644 index ad7ec7179..000000000 --- a/tests/auto/unit/qmediaplaylistnavigator/tst_qmediaplaylistnavigator.cpp +++ /dev/null @@ -1,509 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//TESTED_COMPONENT=src/multimedia - -#include <QtTest/QtTest> -#include <QDebug> -#include <private/qmedianetworkplaylistprovider_p.h> -#include <private/qmediaplaylistnavigator_p.h> - -QT_USE_NAMESPACE -class tst_QMediaPlaylistNavigator : public QObject -{ - Q_OBJECT -public slots: - void init(); - void cleanup(); - -private slots: - void construction(); - void setPlaylist(); - void linearPlayback(); - void loopPlayback(); - void currentItemOnce(); - void currentItemInLoop(); - void randomPlayback(); - - void testItemAt(); - void testNextIndex(); - void testPreviousIndex(); - void testCurrentIndexChangedSignal(); - void testPlaybackModeChangedSignal(); - void testSurroundingItemsChangedSignal(); - void testActivatedSignal(); -}; - -void tst_QMediaPlaylistNavigator::init() -{ - qRegisterMetaType<QMediaPlaylist::PlaybackMode>("QMediaPlaylist::PlaybackMode"); - qRegisterMetaType<QMediaContent>("QMediaContent"); -} - -void tst_QMediaPlaylistNavigator::cleanup() -{ -} - -void tst_QMediaPlaylistNavigator::construction() -{ - QMediaNetworkPlaylistProvider playlist; - QCOMPARE(playlist.mediaCount(), 0); - - QMediaPlaylistNavigator navigator(&playlist); - QVERIFY(navigator.currentItem().isNull()); - QCOMPARE(navigator.currentIndex(), -1); -} - -void tst_QMediaPlaylistNavigator::setPlaylist() -{ - QMediaPlaylistNavigator navigator(0); - QVERIFY(navigator.playlist() != 0); - QCOMPARE(navigator.playlist()->mediaCount(), 0); - QCOMPARE(navigator.playlist()->media(0), QMediaContent()); - QVERIFY(navigator.playlist()->isReadOnly() ); - - QMediaNetworkPlaylistProvider playlist; - QCOMPARE(playlist.mediaCount(), 0); - - navigator.setPlaylist(&playlist); - QCOMPARE(navigator.playlist(), (QMediaPlaylistProvider*)&playlist); - QCOMPARE(navigator.playlist()->mediaCount(), 0); - QVERIFY(!navigator.playlist()->isReadOnly() ); -} - -void tst_QMediaPlaylistNavigator::linearPlayback() -{ - QMediaNetworkPlaylistProvider playlist; - QMediaPlaylistNavigator navigator(&playlist); - - navigator.setPlaybackMode(QMediaPlaylist::Sequential); - navigator.jump(0); - QVERIFY(navigator.currentItem().isNull()); - QCOMPARE(navigator.currentIndex(), -1); - - QMediaContent content1(QUrl(QLatin1String("file:///1"))); - playlist.addMedia(content1); - navigator.jump(0); - QVERIFY(!navigator.currentItem().isNull()); - - QCOMPARE(navigator.currentIndex(), 0); - QCOMPARE(navigator.currentItem(), content1); - QCOMPARE(navigator.nextItem(), QMediaContent()); - QCOMPARE(navigator.nextItem(2), QMediaContent()); - QCOMPARE(navigator.previousItem(), QMediaContent()); - QCOMPARE(navigator.previousItem(2), QMediaContent()); - - QMediaContent content2(QUrl(QLatin1String("file:///2"))); - playlist.addMedia(content2); - QCOMPARE(navigator.currentIndex(), 0); - QCOMPARE(navigator.currentItem(), content1); - QCOMPARE(navigator.nextItem(), content2); - QCOMPARE(navigator.nextItem(2), QMediaContent()); - QCOMPARE(navigator.previousItem(), QMediaContent()); - QCOMPARE(navigator.previousItem(2), QMediaContent()); - - navigator.jump(1); - QCOMPARE(navigator.currentIndex(), 1); - QCOMPARE(navigator.currentItem(), content2); - QCOMPARE(navigator.nextItem(), QMediaContent()); - QCOMPARE(navigator.nextItem(2), QMediaContent()); - QCOMPARE(navigator.previousItem(), content1); - QCOMPARE(navigator.previousItem(2), QMediaContent()); - - navigator.jump(0); - navigator.next(); - QCOMPARE(navigator.currentIndex(), 1); - navigator.next(); - QCOMPARE(navigator.currentIndex(), -1); - navigator.next();//jump to the first item - QCOMPARE(navigator.currentIndex(), 0); - - navigator.previous(); - QCOMPARE(navigator.currentIndex(), -1); - navigator.previous();//jump to the last item - QCOMPARE(navigator.currentIndex(), 1); -} - -void tst_QMediaPlaylistNavigator::loopPlayback() -{ - QMediaNetworkPlaylistProvider playlist; - QMediaPlaylistNavigator navigator(&playlist); - - navigator.setPlaybackMode(QMediaPlaylist::Loop); - navigator.jump(0); - QVERIFY(navigator.currentItem().isNull()); - QCOMPARE(navigator.currentIndex(), -1); - - QMediaContent content1(QUrl(QLatin1String("file:///1"))); - playlist.addMedia(content1); - navigator.jump(0); - QVERIFY(!navigator.currentItem().isNull()); - - QCOMPARE(navigator.currentIndex(), 0); - QCOMPARE(navigator.currentItem(), content1); - QCOMPARE(navigator.nextItem(), content1); - QCOMPARE(navigator.nextItem(2), content1); - QCOMPARE(navigator.previousItem(), content1); - QCOMPARE(navigator.previousItem(2), content1); - - QMediaContent content2(QUrl(QLatin1String("file:///2"))); - playlist.addMedia(content2); - QCOMPARE(navigator.currentIndex(), 0); - QCOMPARE(navigator.currentItem(), content1); - QCOMPARE(navigator.nextItem(), content2); - QCOMPARE(navigator.nextItem(2), content1); //loop over end of the list - QCOMPARE(navigator.previousItem(), content2); - QCOMPARE(navigator.previousItem(2), content1); - - navigator.jump(1); - QCOMPARE(navigator.currentIndex(), 1); - QCOMPARE(navigator.currentItem(), content2); - QCOMPARE(navigator.nextItem(), content1); - QCOMPARE(navigator.nextItem(2), content2); - QCOMPARE(navigator.previousItem(), content1); - QCOMPARE(navigator.previousItem(2), content2); - - navigator.jump(0); - navigator.next(); - QCOMPARE(navigator.currentIndex(), 1); - navigator.next(); - QCOMPARE(navigator.currentIndex(), 0); - navigator.previous(); - QCOMPARE(navigator.currentIndex(), 1); - navigator.previous(); - QCOMPARE(navigator.currentIndex(), 0); -} - -void tst_QMediaPlaylistNavigator::currentItemOnce() -{ - QMediaNetworkPlaylistProvider playlist; - QMediaPlaylistNavigator navigator(&playlist); - - navigator.setPlaybackMode(QMediaPlaylist::CurrentItemOnce); - - QCOMPARE(navigator.playbackMode(), QMediaPlaylist::CurrentItemOnce); - QCOMPARE(navigator.currentIndex(), -1); - - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); - - QCOMPARE(navigator.currentIndex(), -1); - navigator.next(); - QCOMPARE(navigator.currentIndex(), -1); - - navigator.jump(1); - QCOMPARE(navigator.currentIndex(), 1); - navigator.next(); - QCOMPARE(navigator.currentIndex(), -1); - navigator.next(); - QCOMPARE(navigator.currentIndex(), -1); - navigator.previous(); - QCOMPARE(navigator.currentIndex(), -1); - navigator.jump(1); - navigator.previous(); - QCOMPARE(navigator.currentIndex(), -1); -} - -void tst_QMediaPlaylistNavigator::currentItemInLoop() -{ - QMediaNetworkPlaylistProvider playlist; - QMediaPlaylistNavigator navigator(&playlist); - - navigator.setPlaybackMode(QMediaPlaylist::CurrentItemInLoop); - - QCOMPARE(navigator.playbackMode(), QMediaPlaylist::CurrentItemInLoop); - QCOMPARE(navigator.currentIndex(), -1); - - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); - - QCOMPARE(navigator.currentIndex(), -1); - navigator.next(); - QCOMPARE(navigator.currentIndex(), -1); - navigator.jump(1); - navigator.next(); - QCOMPARE(navigator.currentIndex(), 1); - navigator.next(); - QCOMPARE(navigator.currentIndex(), 1); - navigator.previous(); - QCOMPARE(navigator.currentIndex(), 1); - navigator.previous(); - QCOMPARE(navigator.currentIndex(), 1); -} - -void tst_QMediaPlaylistNavigator::randomPlayback() -{ - QMediaNetworkPlaylistProvider playlist; - QMediaPlaylistNavigator navigator(&playlist); - - navigator.setPlaybackMode(QMediaPlaylist::Random); - - QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); - QCOMPARE(navigator.currentIndex(), -1); - - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); - - playlist.shuffle(); - - QCOMPARE(navigator.currentIndex(), -1); - navigator.next(); - int pos1 = navigator.currentIndex(); - navigator.next(); - int pos2 = navigator.currentIndex(); - navigator.next(); - int pos3 = navigator.currentIndex(); - - QVERIFY(pos1 != -1); - QVERIFY(pos2 != -1); - QVERIFY(pos3 != -1); - - navigator.previous(); - QCOMPARE(navigator.currentIndex(), pos2); - navigator.next(); - QCOMPARE(navigator.currentIndex(), pos3); - navigator.next(); - int pos4 = navigator.currentIndex(); - navigator.previous(); - QCOMPARE(navigator.currentIndex(), pos3); - navigator.previous(); - QCOMPARE(navigator.currentIndex(), pos2); - navigator.previous(); - QCOMPARE(navigator.currentIndex(), pos1); - navigator.previous(); - int pos0 = navigator.currentIndex(); - QVERIFY(pos0 != -1); - navigator.next(); - navigator.next(); - navigator.next(); - navigator.next(); - QCOMPARE(navigator.currentIndex(), pos4); - -} - -void tst_QMediaPlaylistNavigator::testItemAt() -{ - QMediaNetworkPlaylistProvider playlist; - QMediaPlaylistNavigator navigator(&playlist); - navigator.setPlaybackMode(QMediaPlaylist::Random); - QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); - QCOMPARE(navigator.currentIndex(), -1); - - //Adding the media to the playlist - QMediaContent content = QMediaContent(QUrl(QLatin1String("file:///1"))); - playlist.addMedia(content); - - //Currently it is not pointing to any index , Returns Null mediacontent - QCOMPARE(navigator.currentIndex(), -1); - QCOMPARE(navigator.itemAt(navigator.currentIndex()),QMediaContent()); - navigator.next(); - - //Points to the added media - int pos1 = navigator.currentIndex(); - QCOMPARE(content,navigator.itemAt(pos1)); -} - -void tst_QMediaPlaylistNavigator::testNextIndex() -{ - QMediaNetworkPlaylistProvider playlist; - QMediaPlaylistNavigator navigator(&playlist); - navigator.setPlaybackMode(QMediaPlaylist::Random); - QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); - QCOMPARE(navigator.currentIndex(), -1); - - //Adding the media to the playlist - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); - - playlist.shuffle(); - - //Currently it is not pointing to any index - QCOMPARE(navigator.currentIndex(), -1); - navigator.next(); - int pos1 = navigator.currentIndex(); - //Pointing to the next index - navigator.next(); - int pos2 = navigator.currentIndex(); - navigator.next(); - int pos3 = navigator.currentIndex(); - - //Pointing to the previous index - navigator.previous(); - QCOMPARE(navigator.nextIndex(1), pos3); - navigator.previous(); - QCOMPARE(navigator.nextIndex(1), pos2); - QCOMPARE(navigator.nextIndex(2), pos3); - navigator.previous(); - QCOMPARE(navigator.nextIndex(1), pos1); -} - -void tst_QMediaPlaylistNavigator::testPreviousIndex() -{ - QMediaNetworkPlaylistProvider playlist; - QMediaPlaylistNavigator navigator(&playlist); - navigator.setPlaybackMode(QMediaPlaylist::Random); - QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); - QCOMPARE(navigator.currentIndex(), -1); - - //Adding the media to the playlist - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); - playlist.shuffle(); - - //Currently it is not pointing to any index - QCOMPARE(navigator.currentIndex(), -1); - - //pointing to next index - navigator.next(); - int pos1 = navigator.currentIndex(); - navigator.next(); - int pos2 = navigator.currentIndex(); - navigator.next(); - int pos3 = navigator.currentIndex(); - QCOMPARE(navigator.previousIndex(1), pos2); - QCOMPARE(navigator.previousIndex(2), pos1); - navigator.next(); - QCOMPARE(navigator.previousIndex(1), pos3); -} - -void tst_QMediaPlaylistNavigator::testCurrentIndexChangedSignal() -{ - QMediaNetworkPlaylistProvider playlist; - QMediaPlaylistNavigator navigator(&playlist); - QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Sequential); - QCOMPARE(navigator.currentIndex(), -1); - - //Creating a QSignalSpy object for currentIndexChanged() signal - QSignalSpy spy(&navigator,SIGNAL(currentIndexChanged(int))); - QVERIFY(spy.count() == 0); - - //Adding the media to the playlist - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); - - //Currently it is not pointing to any index - QCOMPARE(navigator.currentIndex(), -1); - navigator.next(); - QVERIFY(spy.count() == 1); - int pos1 = navigator.currentIndex(); - //Pointing to the next index - navigator.next(); - QVERIFY(navigator.previousIndex(1) == pos1); - QVERIFY(spy.count() == 2); -} - -void tst_QMediaPlaylistNavigator::testPlaybackModeChangedSignal() -{ - QMediaNetworkPlaylistProvider playlist; - QMediaPlaylistNavigator navigator(&playlist); - navigator.setPlaybackMode(QMediaPlaylist::Random); - QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); - QCOMPARE(navigator.currentIndex(), -1); - - //Creating a QSignalSpy object for currentIndexChanged() signal - QSignalSpy spy(&navigator,SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode))); - QVERIFY(spy.count() == 0); - - //Adding the media to the playlist - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); - - //set the play back mode to sequential - navigator.setPlaybackMode(QMediaPlaylist::Sequential); - QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Sequential); - QVERIFY(spy.count() == 1); - - //set the play back mode to loop - navigator.setPlaybackMode(QMediaPlaylist::Loop); - QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Loop); - QVERIFY(spy.count() == 2); -} - -void tst_QMediaPlaylistNavigator::testSurroundingItemsChangedSignal() -{ - QMediaNetworkPlaylistProvider playlist; - QMediaPlaylistNavigator navigator(&playlist); - navigator.setPlaybackMode(QMediaPlaylist::Random); - QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); - QCOMPARE(navigator.currentIndex(), -1); - - //Creating a QSignalSpy object for surroundingItemsChanged()signal - QSignalSpy spy(&navigator,SIGNAL(surroundingItemsChanged())); - QVERIFY(spy.count() == 0); - - //Adding the media to the playlist - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); - QVERIFY(spy.count() == 1); - - //set the play back mode to sequential - navigator.setPlaybackMode(QMediaPlaylist::Sequential); - QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Sequential); - QVERIFY(spy.count() == 2); - - //Point to the next index - navigator.next(); - QVERIFY(spy.count() == 3); -} - -void tst_QMediaPlaylistNavigator::testActivatedSignal() -{ - QMediaNetworkPlaylistProvider playlist; - QMediaPlaylistNavigator navigator(&playlist); - navigator.setPlaybackMode(QMediaPlaylist::Random); - QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); - QCOMPARE(navigator.currentIndex(), -1); - - //Creating a QSignalSpy object for surroundingItemsChanged()signal - QSignalSpy spy(&navigator,SIGNAL(activated(QMediaContent))); - QVERIFY(spy.count() == 0); - - //Adding the media to the playlist - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); - playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); - playlist.shuffle(); - - //Point to the next index - navigator.next(); - QVERIFY(spy.count() == 1); - - //Jump to 0th item - navigator.jump(0); - QVERIFY(spy.count() == 2); - - //move to previous item - navigator.previous(); - QVERIFY(spy.count() == 3); -} - -QTEST_MAIN(tst_QMediaPlaylistNavigator) -#include "tst_qmediaplaylistnavigator.moc" diff --git a/tests/auto/unit/qmultimedia_common/mockmediaplaylistcontrol.h b/tests/auto/unit/qmultimedia_common/mockmediaplaylistcontrol.h deleted file mode 100644 index cc56e9adb..000000000 --- a/tests/auto/unit/qmultimedia_common/mockmediaplaylistcontrol.h +++ /dev/null @@ -1,136 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MOCKMEDIAPLAYLISTCONTROL_H -#define MOCKMEDIAPLAYLISTCONTROL_H - -#include <private/qmediaplaylistcontrol_p.h> -#include <private/qmediaplaylistnavigator_p.h> -#include <private/qmedianetworkplaylistprovider_p.h> - -#include "mockreadonlyplaylistprovider.h" - -class MockMediaPlaylistControl : public QMediaPlaylistControl -{ -public: - MockMediaPlaylistControl(bool readonly = false, QObject *parent = 0) - : QMediaPlaylistControl(parent) - , m_navigator(0) - , m_playlist(0) - , m_ownsProvider(false) - , m_readOnly(readonly) - { - reset(); - } - - ~MockMediaPlaylistControl() - { - } - - void reset() - { - delete m_navigator; - if (m_ownsProvider) - delete m_playlist; - - if (m_readOnly) - m_playlist = new MockReadOnlyPlaylistProvider(this); - else - m_playlist = new QMediaNetworkPlaylistProvider(this); - - m_ownsProvider = true; - m_navigator = new QMediaPlaylistNavigator(m_playlist, this); - } - - void setReadOnly(bool ro) - { - if (m_readOnly == ro) - return; - - m_readOnly = ro; - reset(); - } - - QMediaPlaylistProvider* playlistProvider() const { return m_playlist; } - bool setPlaylistProvider(QMediaPlaylistProvider *newProvider) - { - bool bMediaContentChanged = false; - int i = 0; - for (; i < playlistProvider()->mediaCount(); i++) { - if (playlistProvider()->media(i).request().url().toString() - != newProvider->media(i).request().url().toString()) { - bMediaContentChanged = true; - break; - } - } - - if (playlistProvider()->mediaCount() != newProvider->mediaCount() || bMediaContentChanged ) { - emit playlistProviderChanged(); - emit currentMediaChanged(newProvider->media(i)); - } - - if (m_ownsProvider) - delete m_playlist; - m_playlist = newProvider; - m_ownsProvider = false; - - m_navigator->setPlaylist(newProvider); - return true; - } - - int currentIndex() const { return m_navigator->currentIndex(); } - void setCurrentIndex(int position) - { - if (position != currentIndex()) - emit currentIndexChanged(position); - m_navigator->jump(position); - } - - int nextIndex(int steps) const { return m_navigator->nextIndex(steps); } - int previousIndex(int steps) const { return m_navigator->previousIndex(steps); } - - void next() { m_navigator->next(); } - void previous() { m_navigator->previous(); } - - QMediaPlaylist::PlaybackMode playbackMode() const { return m_navigator->playbackMode(); } - void setPlaybackMode(QMediaPlaylist::PlaybackMode mode) - { - if (playbackMode() != mode) - emit playbackModeChanged(mode); - - m_navigator->setPlaybackMode(mode); - } - -private: - QMediaPlaylistNavigator *m_navigator; - QMediaPlaylistProvider *m_playlist; - bool m_ownsProvider; - bool m_readOnly; -}; - -#endif // MOCKMEDIAPLAYLISTCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockplaylist.pri b/tests/auto/unit/qmultimedia_common/mockplaylist.pri deleted file mode 100644 index c27c839c5..000000000 --- a/tests/auto/unit/qmultimedia_common/mockplaylist.pri +++ /dev/null @@ -1,8 +0,0 @@ -INCLUDEPATH *= $$PWD \ - ../../../src/multimedia \ - -HEADERS *= \ - ../qmultimedia_common/mockmediaplaylistsourcecontrol.h \ - ../qmultimedia_common/mockmediaplaylistcontrol.h \ - ../qmultimedia_common/mockreadonlyplaylistprovider.h \ - ../qmultimedia_common/mockplaylistservice.h diff --git a/tests/auto/unit/qmultimedia_common/mockplaylistservice.h b/tests/auto/unit/qmultimedia_common/mockplaylistservice.h deleted file mode 100644 index cb1971a44..000000000 --- a/tests/auto/unit/qmultimedia_common/mockplaylistservice.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MOCKPLAYLISTSERVICE_H -#define MOCKPLAYLISTSERVICE_H - -#include "qmediaservice.h" -#include "mockmediaplaylistcontrol.h" - -class MockPlaylistService : public QMediaService -{ - Q_OBJECT - -public: - MockPlaylistService():QMediaService(0) - { - mockControl = new MockMediaPlaylistControl(false, this); - } - - ~MockPlaylistService() - { - } - - QMediaControl* requestControl(const char *iid) - { - if (qstrcmp(iid, QMediaPlaylistControl_iid) == 0) - return mockControl; - return 0; - } - - void releaseControl(QMediaControl *) - { - } - - MockMediaPlaylistControl *mockControl; -}; - - -#endif // MOCKPLAYLISTSERVICE_H diff --git a/tests/auto/unit/qmultimedia_common/mockreadonlyplaylistprovider.h b/tests/auto/unit/qmultimedia_common/mockreadonlyplaylistprovider.h deleted file mode 100644 index f0117d653..000000000 --- a/tests/auto/unit/qmultimedia_common/mockreadonlyplaylistprovider.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MOCKREADONLYPLAYLISTPROVIDER_H -#define MOCKREADONLYPLAYLISTPROVIDER_H - -#include <private/qmediaplaylistprovider_p.h> - -class MockReadOnlyPlaylistProvider : public QMediaPlaylistProvider -{ -public: - MockReadOnlyPlaylistProvider(QObject *parent) - :QMediaPlaylistProvider(parent) - { - m_items.append(QMediaContent(QUrl(QLatin1String("file:///1")))); - m_items.append(QMediaContent(QUrl(QLatin1String("file:///2")))); - m_items.append(QMediaContent(QUrl(QLatin1String("file:///3")))); - } - - int mediaCount() const { return m_items.size(); } - QMediaContent media(int index) const - { - return index >=0 && index < mediaCount() ? m_items.at(index) : QMediaContent(); - } - -private: - QList<QMediaContent> m_items; -}; - -#endif // MOCKREADONLYPLAYLISTPROVIDER_H |