| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #ifndef QMEDIAPLAYLIST_H |
| 41 | #define QMEDIAPLAYLIST_H |
| 42 | |
| 43 | #include <QtCore/qobject.h> |
| 44 | |
| 45 | #include <QtMultimedia/qmediacontent.h> |
| 46 | #include <QtMultimedia/qmediaobject.h> |
| 47 | #include <QtMultimedia/qmediabindableinterface.h> |
| 48 | #include <QtMultimedia/qmediaenumdebug.h> |
| 49 | |
| 50 | |
| 51 | QT_BEGIN_NAMESPACE |
| 52 | |
| 53 | |
| 54 | class QMediaPlaylistProvider; |
| 55 | |
| 56 | class QMediaPlaylistPrivate; |
| 57 | class Q_MULTIMEDIA_EXPORT QMediaPlaylist : public QObject, public QMediaBindableInterface |
| 58 | { |
| 59 | Q_OBJECT |
| 60 | Q_INTERFACES(QMediaBindableInterface) |
| 61 | Q_PROPERTY(QMediaPlaylist::PlaybackMode playbackMode READ playbackMode WRITE setPlaybackMode NOTIFY playbackModeChanged) |
| 62 | Q_PROPERTY(QMediaContent currentMedia READ currentMedia NOTIFY currentMediaChanged) |
| 63 | Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) |
| 64 | Q_ENUMS(PlaybackMode Error) |
| 65 | |
| 66 | public: |
| 67 | enum PlaybackMode { CurrentItemOnce, CurrentItemInLoop, Sequential, Loop, Random }; |
| 68 | enum Error { NoError, FormatError, FormatNotSupportedError, NetworkError, AccessDeniedError }; |
| 69 | |
| 70 | explicit QMediaPlaylist(QObject *parent = nullptr); |
| 71 | virtual ~QMediaPlaylist(); |
| 72 | |
| 73 | QMediaObject *mediaObject() const override; |
| 74 | |
| 75 | PlaybackMode playbackMode() const; |
| 76 | void setPlaybackMode(PlaybackMode mode); |
| 77 | |
| 78 | int currentIndex() const; |
| 79 | QMediaContent currentMedia() const; |
| 80 | |
| 81 | int nextIndex(int steps = 1) const; |
| 82 | int previousIndex(int steps = 1) const; |
| 83 | |
| 84 | QMediaContent media(int index) const; |
| 85 | |
| 86 | int mediaCount() const; |
| 87 | bool isEmpty() const; |
| 88 | bool isReadOnly() const; |
| 89 | |
| 90 | bool addMedia(const QMediaContent &content); |
| 91 | bool addMedia(const QList<QMediaContent> &items); |
| 92 | bool insertMedia(int index, const QMediaContent &content); |
| 93 | bool insertMedia(int index, const QList<QMediaContent> &items); |
| 94 | bool moveMedia(int from, int to); |
| 95 | bool removeMedia(int pos); |
| 96 | bool removeMedia(int start, int end); |
| 97 | bool clear(); |
| 98 | |
| 99 | void load(const QNetworkRequest &request, const char *format = nullptr); |
| 100 | void load(const QUrl &location, const char *format = nullptr); |
| 101 | void load(QIODevice *device, const char *format = nullptr); |
| 102 | |
| 103 | bool save(const QUrl &location, const char *format = nullptr); |
| 104 | bool save(QIODevice * device, const char *format); |
| 105 | |
| 106 | Error error() const; |
| 107 | QString errorString() const; |
| 108 | |
| 109 | public Q_SLOTS: |
| 110 | void shuffle(); |
| 111 | |
| 112 | void next(); |
| 113 | void previous(); |
| 114 | |
| 115 | void setCurrentIndex(int index); |
| 116 | |
| 117 | Q_SIGNALS: |
| 118 | void currentIndexChanged(int index); |
| 119 | void playbackModeChanged(QMediaPlaylist::PlaybackMode mode); |
| 120 | void currentMediaChanged(const QMediaContent&); |
| 121 | |
| 122 | void mediaAboutToBeInserted(int start, int end); |
| 123 | void mediaInserted(int start, int end); |
| 124 | void mediaAboutToBeRemoved(int start, int end); |
| 125 | void mediaRemoved(int start, int end); |
| 126 | void mediaChanged(int start, int end); |
| 127 | |
| 128 | void loaded(); |
| 129 | void loadFailed(); |
| 130 | |
| 131 | protected: |
| 132 | bool setMediaObject(QMediaObject *object) override; |
| 133 | QMediaPlaylistPrivate *d_ptr; |
| 134 | |
| 135 | private: |
| 136 | Q_DECLARE_PRIVATE(QMediaPlaylist) |
| 137 | Q_PRIVATE_SLOT(d_func(), void _q_loadFailed(QMediaPlaylist::Error, const QString &)) |
| 138 | }; |
| 139 | |
| 140 | QT_END_NAMESPACE |
| 141 | |
| 142 | Q_DECLARE_METATYPE(QMediaPlaylist::PlaybackMode) |
| 143 | Q_DECLARE_METATYPE(QMediaPlaylist::Error) |
| 144 | |
| 145 | Q_MEDIA_ENUM_DEBUG(QMediaPlaylist, PlaybackMode) |
| 146 | Q_MEDIA_ENUM_DEBUG(QMediaPlaylist, Error) |
| 147 | |
| 148 | #endif // QMEDIAPLAYLIST_H |
| 149 | |