| 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 QDECLARATIVEAUDIO_P_H |
| 41 | #define QDECLARATIVEAUDIO_P_H |
| 42 | |
| 43 | // |
| 44 | // W A R N I N G |
| 45 | // ------------- |
| 46 | // |
| 47 | // This file is not part of the Qt API. It exists for the convenience |
| 48 | // of other Qt classes. This header file may change from version to |
| 49 | // version without notice, or even be removed. |
| 50 | // |
| 51 | // We mean it. |
| 52 | // |
| 53 | |
| 54 | #include <QtCore/qbasictimer.h> |
| 55 | #include <QtQml/qqmlparserstatus.h> |
| 56 | #include <QtQml/qqml.h> |
| 57 | #include <QtQml/qjsvalue.h> |
| 58 | |
| 59 | #include <qmediaplayer.h> |
| 60 | |
| 61 | QT_BEGIN_NAMESPACE |
| 62 | |
| 63 | class QTimerEvent; |
| 64 | class QMediaPlayerControl; |
| 65 | class QMediaService; |
| 66 | class QMediaServiceProvider; |
| 67 | class QMetaDataReaderControl; |
| 68 | class QDeclarativePlaylist; |
| 69 | class QDeclarativeMediaBaseAnimation; |
| 70 | class QDeclarativeMediaMetaData; |
| 71 | class QMediaAvailabilityControl; |
| 72 | |
| 73 | class QDeclarativeAudio : public QObject, public QQmlParserStatus |
| 74 | { |
| 75 | Q_OBJECT |
| 76 | Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) |
| 77 | Q_PROPERTY(QDeclarativePlaylist *playlist READ playlist WRITE setPlaylist NOTIFY playlistChanged REVISION 1) |
| 78 | Q_PROPERTY(int loops READ loopCount WRITE setLoopCount NOTIFY loopCountChanged) |
| 79 | Q_PROPERTY(PlaybackState playbackState READ playbackState NOTIFY playbackStateChanged) |
| 80 | Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay NOTIFY autoPlayChanged) |
| 81 | Q_PROPERTY(bool autoLoad READ isAutoLoad WRITE setAutoLoad NOTIFY autoLoadChanged) |
| 82 | Q_PROPERTY(Status status READ status NOTIFY statusChanged) |
| 83 | Q_PROPERTY(int duration READ duration NOTIFY durationChanged) |
| 84 | Q_PROPERTY(int position READ position NOTIFY positionChanged) |
| 85 | Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged) |
| 86 | Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) |
| 87 | Q_PROPERTY(bool hasAudio READ hasAudio NOTIFY hasAudioChanged) |
| 88 | Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged) |
| 89 | Q_PROPERTY(qreal bufferProgress READ bufferProgress NOTIFY bufferProgressChanged) |
| 90 | Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged) |
| 91 | Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged) |
| 92 | Q_PROPERTY(Error error READ error NOTIFY errorChanged) |
| 93 | Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) |
| 94 | Q_PROPERTY(QDeclarativeMediaMetaData *metaData READ metaData CONSTANT) |
| 95 | Q_PROPERTY(QObject *mediaObject READ mediaObject NOTIFY mediaObjectChanged SCRIPTABLE false DESIGNABLE false) |
| 96 | Q_PROPERTY(Availability availability READ availability NOTIFY availabilityChanged) |
| 97 | Q_PROPERTY(AudioRole audioRole READ audioRole WRITE setAudioRole NOTIFY audioRoleChanged REVISION 1) |
| 98 | Q_PROPERTY(QString customAudioRole READ customAudioRole WRITE setCustomAudioRole NOTIFY customAudioRoleChanged REVISION 3) |
| 99 | Q_PROPERTY(int notifyInterval READ notifyInterval WRITE setNotifyInterval NOTIFY notifyIntervalChanged REVISION 2) |
| 100 | Q_PROPERTY(QVariant videoOutput READ videoOutput WRITE setVideoOutput NOTIFY videoOutputChanged REVISION 15) |
| 101 | Q_ENUMS(Status) |
| 102 | Q_ENUMS(Error) |
| 103 | Q_ENUMS(Loop) |
| 104 | Q_ENUMS(PlaybackState) |
| 105 | Q_ENUMS(Availability) |
| 106 | Q_ENUMS(AudioRole) |
| 107 | Q_INTERFACES(QQmlParserStatus) |
| 108 | public: |
| 109 | enum Status |
| 110 | { |
| 111 | UnknownStatus = QMediaPlayer::UnknownMediaStatus, |
| 112 | NoMedia = QMediaPlayer::NoMedia, |
| 113 | Loading = QMediaPlayer::LoadingMedia, |
| 114 | Loaded = QMediaPlayer::LoadedMedia, |
| 115 | Stalled = QMediaPlayer::StalledMedia, |
| 116 | Buffering = QMediaPlayer::BufferingMedia, |
| 117 | Buffered = QMediaPlayer::BufferedMedia, |
| 118 | EndOfMedia = QMediaPlayer::EndOfMedia, |
| 119 | InvalidMedia = QMediaPlayer::InvalidMedia |
| 120 | }; |
| 121 | |
| 122 | enum Error |
| 123 | { |
| 124 | NoError = QMediaPlayer::NoError, |
| 125 | ResourceError = QMediaPlayer::ResourceError, |
| 126 | FormatError = QMediaPlayer::FormatError, |
| 127 | NetworkError = QMediaPlayer::NetworkError, |
| 128 | AccessDenied = QMediaPlayer::AccessDeniedError, |
| 129 | ServiceMissing = QMediaPlayer::ServiceMissingError |
| 130 | }; |
| 131 | |
| 132 | enum Loop |
| 133 | { |
| 134 | Infinite = -1 |
| 135 | }; |
| 136 | |
| 137 | enum PlaybackState |
| 138 | { |
| 139 | PlayingState = QMediaPlayer::PlayingState, |
| 140 | PausedState = QMediaPlayer::PausedState, |
| 141 | StoppedState = QMediaPlayer::StoppedState |
| 142 | }; |
| 143 | |
| 144 | enum Availability { |
| 145 | Available = QMultimedia::Available, |
| 146 | Busy = QMultimedia::Busy, |
| 147 | Unavailable = QMultimedia::ServiceMissing, |
| 148 | ResourceMissing = QMultimedia::ResourceError |
| 149 | }; |
| 150 | |
| 151 | enum AudioRole { |
| 152 | UnknownRole = QAudio::UnknownRole, |
| 153 | AccessibilityRole = QAudio::AccessibilityRole, |
| 154 | AlarmRole = QAudio::AlarmRole, |
| 155 | CustomRole = QAudio::CustomRole, |
| 156 | GameRole = QAudio::GameRole, |
| 157 | MusicRole = QAudio::MusicRole, |
| 158 | NotificationRole = QAudio::NotificationRole, |
| 159 | RingtoneRole = QAudio::RingtoneRole, |
| 160 | SonificationRole = QAudio::SonificationRole, |
| 161 | VideoRole = QAudio::VideoRole, |
| 162 | VoiceCommunicationRole = QAudio::VoiceCommunicationRole |
| 163 | }; |
| 164 | |
| 165 | QDeclarativeAudio(QObject *parent = 0); |
| 166 | ~QDeclarativeAudio(); |
| 167 | |
| 168 | QVariant videoOutput() const; |
| 169 | void setVideoOutput(const QVariant &); |
| 170 | |
| 171 | bool hasAudio() const; |
| 172 | bool hasVideo() const; |
| 173 | |
| 174 | Status status() const; |
| 175 | Error error() const; |
| 176 | PlaybackState playbackState() const; |
| 177 | void setPlaybackState(QMediaPlayer::State playbackState); |
| 178 | |
| 179 | void classBegin() override; |
| 180 | void componentComplete() override; |
| 181 | |
| 182 | QObject *mediaObject() { return m_player; } |
| 183 | |
| 184 | Availability availability() const; |
| 185 | |
| 186 | AudioRole audioRole() const; |
| 187 | void setAudioRole(AudioRole audioRole); |
| 188 | QString customAudioRole() const; |
| 189 | void setCustomAudioRole(const QString &audioRole); |
| 190 | |
| 191 | QUrl source() const; |
| 192 | void setSource(const QUrl &url); |
| 193 | |
| 194 | QDeclarativePlaylist *playlist() const; |
| 195 | void setPlaylist(QDeclarativePlaylist *playlist); |
| 196 | |
| 197 | int loopCount() const; |
| 198 | void setLoopCount(int loopCount); |
| 199 | |
| 200 | int duration() const; |
| 201 | |
| 202 | int position() const; |
| 203 | |
| 204 | qreal volume() const; |
| 205 | void setVolume(qreal volume); |
| 206 | |
| 207 | bool isMuted() const; |
| 208 | void setMuted(bool muted); |
| 209 | |
| 210 | qreal bufferProgress() const; |
| 211 | |
| 212 | bool isSeekable() const; |
| 213 | |
| 214 | qreal playbackRate() const; |
| 215 | void setPlaybackRate(qreal rate); |
| 216 | |
| 217 | QString errorString() const; |
| 218 | |
| 219 | QDeclarativeMediaMetaData *metaData() const; |
| 220 | |
| 221 | bool isAutoLoad() const; |
| 222 | void setAutoLoad(bool autoLoad); |
| 223 | |
| 224 | bool autoPlay() const; |
| 225 | void setAutoPlay(bool autoplay); |
| 226 | int notifyInterval() const; |
| 227 | void setNotifyInterval(int); |
| 228 | |
| 229 | public Q_SLOTS: |
| 230 | void play(); |
| 231 | void pause(); |
| 232 | void stop(); |
| 233 | void seek(int position); |
| 234 | |
| 235 | Q_REVISION(1) QJSValue supportedAudioRoles() const; |
| 236 | |
| 237 | Q_SIGNALS: |
| 238 | Q_REVISION(1) void playlistChanged(); |
| 239 | |
| 240 | void sourceChanged(); |
| 241 | void autoLoadChanged(); |
| 242 | void loopCountChanged(); |
| 243 | |
| 244 | void playbackStateChanged(); |
| 245 | void autoPlayChanged(); |
| 246 | |
| 247 | void paused(); |
| 248 | void stopped(); |
| 249 | void playing(); |
| 250 | |
| 251 | void statusChanged(); |
| 252 | |
| 253 | void durationChanged(); |
| 254 | void positionChanged(); |
| 255 | |
| 256 | void volumeChanged(); |
| 257 | void mutedChanged(); |
| 258 | void hasAudioChanged(); |
| 259 | void hasVideoChanged(); |
| 260 | |
| 261 | void bufferProgressChanged(); |
| 262 | |
| 263 | void seekableChanged(); |
| 264 | void playbackRateChanged(); |
| 265 | |
| 266 | Q_REVISION(1) void audioRoleChanged(); |
| 267 | Q_REVISION(3) void customAudioRoleChanged(); |
| 268 | |
| 269 | void availabilityChanged(Availability availability); |
| 270 | |
| 271 | void errorChanged(); |
| 272 | void error(QDeclarativeAudio::Error error, const QString &errorString); |
| 273 | |
| 274 | void mediaObjectChanged(); |
| 275 | Q_REVISION(2) void notifyIntervalChanged(); |
| 276 | Q_REVISION(15) void videoOutputChanged(); |
| 277 | |
| 278 | private Q_SLOTS: |
| 279 | void _q_error(QMediaPlayer::Error); |
| 280 | void _q_availabilityChanged(QMultimedia::AvailabilityStatus); |
| 281 | void _q_statusChanged(); |
| 282 | void _q_mediaChanged(const QMediaContent&); |
| 283 | |
| 284 | private: |
| 285 | Q_DISABLE_COPY(QDeclarativeAudio) |
| 286 | |
| 287 | QDeclarativePlaylist *m_playlist; |
| 288 | bool m_autoPlay; |
| 289 | bool m_autoLoad; |
| 290 | bool m_loaded; |
| 291 | bool m_muted; |
| 292 | bool m_complete; |
| 293 | bool m_emitPlaylistChanged; |
| 294 | int m_loopCount; |
| 295 | int m_runningCount; |
| 296 | int m_position; |
| 297 | qreal m_vol; |
| 298 | qreal m_playbackRate; |
| 299 | AudioRole m_audioRole; |
| 300 | QString m_customAudioRole; |
| 301 | |
| 302 | QMediaPlayer::State m_playbackState; |
| 303 | QMediaPlayer::MediaStatus m_status; |
| 304 | QMediaPlayer::Error m_error; |
| 305 | QString m_errorString; |
| 306 | QUrl m_source; |
| 307 | QMediaContent m_content; |
| 308 | |
| 309 | QScopedPointer<QDeclarativeMediaMetaData> m_metaData; |
| 310 | |
| 311 | QMediaPlayer *m_player; |
| 312 | int m_notifyInterval; |
| 313 | QVariant m_videoOutput; |
| 314 | |
| 315 | friend class QDeclarativeMediaBaseAnimation; |
| 316 | }; |
| 317 | |
| 318 | QT_END_NAMESPACE |
| 319 | |
| 320 | QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeAudio)) |
| 321 | |
| 322 | #endif |
| 323 | |