summaryrefslogtreecommitdiffstats
path: root/src/multimedia
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-12-15 17:24:21 +0100
committerLars Knoll <lars.knoll@qt.io>2021-01-20 15:11:26 +0000
commit3fcc619cb4300e2e07b3615b0b887938532c22cc (patch)
treec82b97737e9a6c141692744ec43c8763d8b8b461 /src/multimedia
parent1aceb4feb8ffab96773d919fa49408af8dc24e12 (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>
Diffstat (limited to 'src/multimedia')
-rw-r--r--src/multimedia/controls/controls.pri4
-rw-r--r--src/multimedia/controls/qmediaplaylistcontrol.cpp206
-rw-r--r--src/multimedia/controls/qmediaplaylistcontrol_p.h102
-rw-r--r--src/multimedia/playback/playback.pri8
-rw-r--r--src/multimedia/playback/qmedianetworkplaylistprovider.cpp284
-rw-r--r--src/multimedia/playback/qmedianetworkplaylistprovider_p.h96
-rw-r--r--src/multimedia/playback/qmediaplayer.cpp1
-rw-r--r--src/multimedia/playback/qmediaplaylist.cpp495
-rw-r--r--src/multimedia/playback/qmediaplaylist.h17
-rw-r--r--src/multimedia/playback/qmediaplaylist_p.h115
-rw-r--r--src/multimedia/playback/qmediaplaylistioplugin.cpp188
-rw-r--r--src/multimedia/playback/qmediaplaylistioplugin_p.h125
-rw-r--r--src/multimedia/playback/qmediaplaylistnavigator.cpp544
-rw-r--r--src/multimedia/playback/qmediaplaylistnavigator_p.h118
-rw-r--r--src/multimedia/playback/qmediaplaylistprovider.cpp321
-rw-r--r--src/multimedia/playback/qmediaplaylistprovider_p.h122
-rw-r--r--src/multimedia/playback/qplaylistfileparser.cpp52
-rw-r--r--src/multimedia/playback/qplaylistfileparser_p.h16
-rw-r--r--src/multimedia/qmediaserviceproviderplugin.h2
19 files changed, 298 insertions, 2518 deletions
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