| 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 | #include "qmediaplayercontrol.h" | 
| 41 | #include "qmediacontrol_p.h" | 
| 42 | #include "qmediaplayer.h" | 
| 43 |  | 
| 44 | QT_BEGIN_NAMESPACE | 
| 45 |  | 
| 46 |  | 
| 47 | /*! | 
| 48 |     \class QMediaPlayerControl | 
| 49 |     \obsolete | 
| 50 |     \inmodule QtMultimedia | 
| 51 |  | 
| 52 |  | 
| 53 |     \ingroup multimedia_control | 
| 54 |  | 
| 55 |  | 
| 56 |     \brief The QMediaPlayerControl class provides access to the media playing | 
| 57 |     functionality of a QMediaService. | 
| 58 |  | 
| 59 |     If a QMediaService can play media is will implement QMediaPlayerControl. | 
| 60 |     This control provides a means to set the \l {setMedia()}{media} to play, | 
| 61 |     \l {play()}{start}, \l {pause()} {pause} and \l {stop()}{stop} playback, | 
| 62 |     \l {setPosition()}{seek}, and control the \l {setVolume()}{volume}. | 
| 63 |     It also provides feedback on the \l {duration()}{duration} of the media, | 
| 64 |     the current \l {position()}{position}, and \l {bufferStatus()}{buffering} | 
| 65 |     progress. | 
| 66 |  | 
| 67 |     The functionality provided by this control is exposed to application | 
| 68 |     code through the QMediaPlayer class. | 
| 69 |  | 
| 70 |     The interface name of QMediaPlayerControl is \c org.qt-project.qt.mediaplayercontrol/5.0 as | 
| 71 |     defined in QMediaPlayerControl_iid. | 
| 72 |  | 
| 73 |     \sa QMediaService::requestControl(), QMediaPlayer | 
| 74 | */ | 
| 75 |  | 
| 76 | /*! | 
| 77 |     \macro QMediaPlayerControl_iid | 
| 78 |  | 
| 79 |     \c org.qt-project.qt.mediaplayercontrol/5.0 | 
| 80 |  | 
| 81 |     Defines the interface name of the QMediaPlayerControl class. | 
| 82 |  | 
| 83 |     \relates QMediaPlayerControl | 
| 84 | */ | 
| 85 |  | 
| 86 | /*! | 
| 87 |     Destroys a media player control. | 
| 88 | */ | 
| 89 | QMediaPlayerControl::~QMediaPlayerControl() | 
| 90 | { | 
| 91 | } | 
| 92 |  | 
| 93 | /*! | 
| 94 |     Constructs a new media player control with the given \a parent. | 
| 95 | */ | 
| 96 | QMediaPlayerControl::QMediaPlayerControl(QObject *parent): | 
| 97 |     QMediaControl(*new QMediaControlPrivate, parent) | 
| 98 | { | 
| 99 | } | 
| 100 |  | 
| 101 | /*! | 
| 102 |     \fn QMediaPlayerControl::state() const | 
| 103 |  | 
| 104 |     Returns the state of a player control. | 
| 105 | */ | 
| 106 |  | 
| 107 | /*! | 
| 108 |     \fn QMediaPlayerControl::stateChanged(QMediaPlayer::State newState) | 
| 109 |  | 
| 110 |     Signals that the state of a player control has changed to \a newState. | 
| 111 |  | 
| 112 |     \sa state() | 
| 113 | */ | 
| 114 |  | 
| 115 | /*! | 
| 116 |     \fn QMediaPlayerControl::mediaStatus() const | 
| 117 |  | 
| 118 |     Returns the status of the current media. | 
| 119 | */ | 
| 120 |  | 
| 121 |  | 
| 122 | /*! | 
| 123 |     \fn QMediaPlayerControl::mediaStatusChanged(QMediaPlayer::MediaStatus status) | 
| 124 |  | 
| 125 |     Signals that the \a status of the current media has changed. | 
| 126 |  | 
| 127 |     \sa mediaStatus() | 
| 128 | */ | 
| 129 |  | 
| 130 |  | 
| 131 | /*! | 
| 132 |     \fn QMediaPlayerControl::duration() const | 
| 133 |  | 
| 134 |     Returns the duration of the current media in milliseconds. | 
| 135 | */ | 
| 136 |  | 
| 137 | /*! | 
| 138 |     \fn QMediaPlayerControl::durationChanged(qint64 duration) | 
| 139 |  | 
| 140 |     Signals that the \a duration of the current media has changed. | 
| 141 |  | 
| 142 |     \sa duration() | 
| 143 | */ | 
| 144 |  | 
| 145 | /*! | 
| 146 |     \fn QMediaPlayerControl::position() const | 
| 147 |  | 
| 148 |     Returns the current playback position in milliseconds. | 
| 149 | */ | 
| 150 |  | 
| 151 | /*! | 
| 152 |     \fn QMediaPlayerControl::setPosition(qint64 position) | 
| 153 |  | 
| 154 |     Sets the playback \a position of the current media.  This will initiate a seek and it may take | 
| 155 |     some time for playback to reach the position set. | 
| 156 | */ | 
| 157 |  | 
| 158 | /*! | 
| 159 |     \fn QMediaPlayerControl::positionChanged(qint64 position) | 
| 160 |  | 
| 161 |     Signals the playback \a position has changed. | 
| 162 |  | 
| 163 |     This is only emitted in when there has been a discontinous change in the playback postion, such | 
| 164 |     as a seek or the position being reset. | 
| 165 |  | 
| 166 |     \sa position() | 
| 167 | */ | 
| 168 |  | 
| 169 | /*! | 
| 170 |     \fn QMediaPlayerControl::volume() const | 
| 171 |  | 
| 172 |     Returns the audio volume of a player control. | 
| 173 | */ | 
| 174 |  | 
| 175 | /*! | 
| 176 |     \fn QMediaPlayerControl::setVolume(int volume) | 
| 177 |  | 
| 178 |     Sets the audio \a volume of a player control. | 
| 179 |  | 
| 180 |     The volume is scaled linearly, ranging from \c 0 (silence) to \c 100 (full volume). | 
| 181 | */ | 
| 182 |  | 
| 183 | /*! | 
| 184 |     \fn QMediaPlayerControl::volumeChanged(int volume) | 
| 185 |  | 
| 186 |     Signals the audio \a volume of a player control has changed. | 
| 187 |  | 
| 188 |     \sa volume() | 
| 189 | */ | 
| 190 |  | 
| 191 | /*! | 
| 192 |     \fn QMediaPlayerControl::isMuted() const | 
| 193 |  | 
| 194 |     Returns the mute state of a player control. | 
| 195 | */ | 
| 196 |  | 
| 197 | /*! | 
| 198 |     \fn QMediaPlayerControl::setMuted(bool mute) | 
| 199 |  | 
| 200 |     Sets the \a mute state of a player control. | 
| 201 | */ | 
| 202 |  | 
| 203 | /*! | 
| 204 |     \fn QMediaPlayerControl::mutedChanged(bool mute) | 
| 205 |  | 
| 206 |     Signals a change in the \a mute status of a player control. | 
| 207 |  | 
| 208 |     \sa isMuted() | 
| 209 | */ | 
| 210 |  | 
| 211 | /*! | 
| 212 |     \fn QMediaPlayerControl::bufferStatus() const | 
| 213 |  | 
| 214 |     Returns the buffering progress of the current media.  Progress is measured in the percentage | 
| 215 |     of the buffer filled. | 
| 216 | */ | 
| 217 |  | 
| 218 | /*! | 
| 219 |     \fn QMediaPlayerControl::bufferStatusChanged(int percentFilled) | 
| 220 |  | 
| 221 |     Signal the amount of the local buffer filled as a percentage by \a percentFilled. | 
| 222 |  | 
| 223 |     \sa bufferStatus() | 
| 224 | */ | 
| 225 |  | 
| 226 | /*! | 
| 227 |     \fn QMediaPlayerControl::isAudioAvailable() const | 
| 228 |  | 
| 229 |     Identifies if there is audio output available for the current media. | 
| 230 |  | 
| 231 |     Returns true if audio output is available and false otherwise. | 
| 232 | */ | 
| 233 |  | 
| 234 | /*! | 
| 235 |     \fn QMediaPlayerControl::audioAvailableChanged(bool audioAvailable) | 
| 236 |  | 
| 237 |     Signals that there has been a change in the availability of audio output \a audioAvailable. | 
| 238 |  | 
| 239 |     \sa isAudioAvailable() | 
| 240 | */ | 
| 241 |  | 
| 242 | /*! | 
| 243 |     \fn QMediaPlayerControl::isVideoAvailable() const | 
| 244 |  | 
| 245 |     Identifies if there is video output available for the current media. | 
| 246 |  | 
| 247 |     Returns true if video output is available and false otherwise. | 
| 248 | */ | 
| 249 |  | 
| 250 | /*! | 
| 251 |     \fn QMediaPlayerControl::videoAvailableChanged(bool videoAvailable) | 
| 252 |  | 
| 253 |     Signal that the availability of visual content has changed to \a videoAvailable. | 
| 254 |  | 
| 255 |     \sa isVideoAvailable() | 
| 256 | */ | 
| 257 |  | 
| 258 | /*! | 
| 259 |     \fn QMediaPlayerControl::isSeekable() const | 
| 260 |  | 
| 261 |     Identifies if the current media is seekable. | 
| 262 |  | 
| 263 |     Returns true if it possible to seek within the current media, and false otherwise. | 
| 264 | */ | 
| 265 |  | 
| 266 | /*! | 
| 267 |     \fn QMediaPlayerControl::seekableChanged(bool seekable) | 
| 268 |  | 
| 269 |     Signals that the \a seekable state of a player control has changed. | 
| 270 |  | 
| 271 |     \sa isSeekable() | 
| 272 | */ | 
| 273 |  | 
| 274 | /*! | 
| 275 |     \fn QMediaPlayerControl::availablePlaybackRanges() const | 
| 276 |  | 
| 277 |     Returns a range of times in milliseconds that can be played back. | 
| 278 |  | 
| 279 |     Usually for local files this is a continuous interval equal to [0..duration()] | 
| 280 |     or an empty time range if seeking is not supported, but for network sources | 
| 281 |     it refers to the buffered parts of the media. | 
| 282 | */ | 
| 283 |  | 
| 284 | /*! | 
| 285 |     \fn QMediaPlayerControl::availablePlaybackRangesChanged(const QMediaTimeRange &ranges) | 
| 286 |  | 
| 287 |     Signals that the available media playback \a ranges have changed. | 
| 288 |  | 
| 289 |     \sa QMediaPlayerControl::availablePlaybackRanges() | 
| 290 | */ | 
| 291 |  | 
| 292 | /*! | 
| 293 |     \fn qreal QMediaPlayerControl::playbackRate() const | 
| 294 |  | 
| 295 |     Returns the rate of playback. | 
| 296 | */ | 
| 297 |  | 
| 298 | /*! | 
| 299 |     \fn QMediaPlayerControl::setPlaybackRate(qreal rate) | 
| 300 |  | 
| 301 |     Sets the \a rate of playback. | 
| 302 | */ | 
| 303 |  | 
| 304 | /*! | 
| 305 |     \fn QMediaPlayerControl::media() const | 
| 306 |  | 
| 307 |     Returns the current media source. | 
| 308 | */ | 
| 309 |  | 
| 310 | /*! | 
| 311 |     \fn QMediaPlayerControl::mediaStream() const | 
| 312 |  | 
| 313 |     Returns the current media stream. This is only a valid if a stream was passed to setMedia(). | 
| 314 |  | 
| 315 |     \sa setMedia() | 
| 316 | */ | 
| 317 |  | 
| 318 | /*! | 
| 319 |     \fn QMediaPlayerControl::setMedia(const QMediaContent &media, QIODevice *stream) | 
| 320 |  | 
| 321 |     Sets the current \a media source.  If a \a stream is supplied; data will be read from that | 
| 322 |     instead of attempting to resolve the media source.  The media source may still be used to | 
| 323 |     supply media information such as mime type. | 
| 324 |  | 
| 325 |     Setting the media to a null QMediaContent will cause the control to discard all | 
| 326 |     information relating to the current media source and to cease all I/O operations related | 
| 327 |     to that media. | 
| 328 |  | 
| 329 |     Qt resource files are never passed as is. If the service supports | 
| 330 |     QMediaServiceProviderHint::StreamPlayback, a \a stream is supplied, pointing to an opened | 
| 331 |     QFile. Otherwise, the resource is copied into a temporary file and \a media contains the | 
| 332 |     url to that file. | 
| 333 | */ | 
| 334 |  | 
| 335 | /*! | 
| 336 |     \fn QMediaPlayerControl::mediaChanged(const QMediaContent& content) | 
| 337 |  | 
| 338 |     Signals that the current media \a content has changed. | 
| 339 | */ | 
| 340 |  | 
| 341 | /*! | 
| 342 |     \fn QMediaPlayerControl::play() | 
| 343 |  | 
| 344 |     Starts playback of the current media. | 
| 345 |  | 
| 346 |     If successful the player control will immediately enter the \l {QMediaPlayer::PlayingState} | 
| 347 |     {playing} state. | 
| 348 |  | 
| 349 |     \sa state() | 
| 350 | */ | 
| 351 |  | 
| 352 | /*! | 
| 353 |     \fn QMediaPlayerControl::pause() | 
| 354 |  | 
| 355 |     Pauses playback of the current media. | 
| 356 |  | 
| 357 |     If successful the player control will immediately enter the \l {QMediaPlayer::PausedState} | 
| 358 |     {paused} state. | 
| 359 |  | 
| 360 |     \sa state(), play(), stop() | 
| 361 | */ | 
| 362 |  | 
| 363 | /*! | 
| 364 |     \fn QMediaPlayerControl::stop() | 
| 365 |  | 
| 366 |     Stops playback of the current media. | 
| 367 |  | 
| 368 |     If successful the player control will immediately enter the \l {QMediaPlayer::StoppedState} | 
| 369 |     {stopped} state. | 
| 370 | */ | 
| 371 |  | 
| 372 | /*! | 
| 373 |     \fn QMediaPlayerControl::error(int error, const QString &errorString) | 
| 374 |  | 
| 375 |     Signals that an \a error has occurred.  The \a errorString provides a more detailed explanation. | 
| 376 | */ | 
| 377 |  | 
| 378 | /*! | 
| 379 |     \fn QMediaPlayerControl::playbackRateChanged(qreal rate) | 
| 380 |  | 
| 381 |     Signal emitted when playback rate changes to \a rate. | 
| 382 | */ | 
| 383 |  | 
| 384 | QT_END_NAMESPACE | 
| 385 |  | 
| 386 | #include "moc_qmediaplayercontrol.cpp" | 
| 387 |  |