| 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 test suite of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ | 
| 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 General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
| 21 | ** included in the packaging of this file. Please review the following | 
| 22 | ** information to ensure the GNU General Public License requirements will | 
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 24 | ** | 
| 25 | ** $QT_END_LICENSE$ | 
| 26 | ** | 
| 27 | ****************************************************************************/ | 
| 28 |  | 
| 29 | #ifndef MOCKMEDIAPLAYERCONTROL_H | 
| 30 | #define MOCKMEDIAPLAYERCONTROL_H | 
| 31 |  | 
| 32 | #include "qmediaplayercontrol.h" | 
| 33 |  | 
| 34 | class MockMediaPlayerControl : public QMediaPlayerControl | 
| 35 | { | 
| 36 |     friend class MockMediaPlayerService; | 
| 37 |  | 
| 38 | public: | 
| 39 |     MockMediaPlayerControl() | 
| 40 |         : QMediaPlayerControl(0) | 
| 41 |         , _state(QMediaPlayer::StoppedState) | 
| 42 |         , _mediaStatus(QMediaPlayer::NoMedia) | 
| 43 |         , _error(QMediaPlayer::NoError) | 
| 44 |         , _duration(0) | 
| 45 |         , _position(0) | 
| 46 |         , _volume(100) | 
| 47 |         , _muted(false) | 
| 48 |         , _bufferStatus(0) | 
| 49 |         , _audioAvailable(false) | 
| 50 |         , _videoAvailable(false) | 
| 51 |         , _isSeekable(true) | 
| 52 |         , _playbackRate(qreal(1.0)) | 
| 53 |         , _stream(0) | 
| 54 |         , _isValid(false) | 
| 55 |     {} | 
| 56 |  | 
| 57 |     QMediaPlayer::State state() const { return _state; } | 
| 58 |     QMediaPlayer::MediaStatus mediaStatus() const { return _mediaStatus; } | 
| 59 |  | 
| 60 |     qint64 duration() const { return _duration; } | 
| 61 |  | 
| 62 |     qint64 position() const { return _position; } | 
| 63 |  | 
| 64 |     void setPosition(qint64 position) { if (position != _position) emit positionChanged(position: _position = position); } | 
| 65 |  | 
| 66 |     int volume() const { return _volume; } | 
| 67 |     void setVolume(int volume) { emit volumeChanged(volume: _volume = volume); } | 
| 68 |  | 
| 69 |     bool isMuted() const { return _muted; } | 
| 70 |     void setMuted(bool muted) { if (muted != _muted) emit mutedChanged(mute: _muted = muted); } | 
| 71 |  | 
| 72 |     int bufferStatus() const { return _bufferStatus; } | 
| 73 |  | 
| 74 |     bool isAudioAvailable() const { return _audioAvailable; } | 
| 75 |     bool isVideoAvailable() const { return _videoAvailable; } | 
| 76 |  | 
| 77 |     bool isSeekable() const { return _isSeekable; } | 
| 78 |     QMediaTimeRange availablePlaybackRanges() const { return QMediaTimeRange(_seekRange.first, _seekRange.second); } | 
| 79 |     void setSeekRange(qint64 minimum, qint64 maximum) { _seekRange = qMakePair(x: minimum, y: maximum); } | 
| 80 |  | 
| 81 |     qreal playbackRate() const { return _playbackRate; } | 
| 82 |     void setPlaybackRate(qreal rate) { if (rate != _playbackRate) emit playbackRateChanged(rate: _playbackRate = rate); } | 
| 83 |  | 
| 84 |     QMediaContent media() const { return _media; } | 
| 85 |     void setMedia(const QMediaContent &content, QIODevice *stream) | 
| 86 |     { | 
| 87 |         _stream = stream; | 
| 88 |         _media = content; | 
| 89 |         _mediaStatus = _media.isNull() ? QMediaPlayer::NoMedia : QMediaPlayer::LoadingMedia; | 
| 90 |         if (_state != QMediaPlayer::StoppedState) | 
| 91 |             emit stateChanged(newState: _state = QMediaPlayer::StoppedState); | 
| 92 |         emit mediaStatusChanged(status: _mediaStatus); | 
| 93 |         emit mediaChanged(content: _media = content); | 
| 94 |     } | 
| 95 |     QIODevice *mediaStream() const { return _stream; } | 
| 96 |  | 
| 97 |     void play() { if (_isValid && !_media.isNull() && _state != QMediaPlayer::PlayingState) emit stateChanged(newState: _state = QMediaPlayer::PlayingState); } | 
| 98 |     void pause() { if (_isValid && !_media.isNull() && _state != QMediaPlayer::PausedState) emit stateChanged(newState: _state = QMediaPlayer::PausedState); } | 
| 99 |     void stop() { if (_state != QMediaPlayer::StoppedState) emit stateChanged(newState: _state = QMediaPlayer::StoppedState); } | 
| 100 |  | 
| 101 |     QMediaPlayer::State _state; | 
| 102 |     QMediaPlayer::MediaStatus _mediaStatus; | 
| 103 |     QMediaPlayer::Error _error; | 
| 104 |     qint64 _duration; | 
| 105 |     qint64 _position; | 
| 106 |     int _volume; | 
| 107 |     bool _muted; | 
| 108 |     int _bufferStatus; | 
| 109 |     bool _audioAvailable; | 
| 110 |     bool _videoAvailable; | 
| 111 |     bool _isSeekable; | 
| 112 |     QPair<qint64, qint64> _seekRange; | 
| 113 |     qreal _playbackRate; | 
| 114 |     QMediaContent _media; | 
| 115 |     QIODevice *_stream; | 
| 116 |     bool _isValid; | 
| 117 |     QString _errorString; | 
| 118 | }; | 
| 119 |  | 
| 120 | #endif // MOCKMEDIAPLAYERCONTROL_H | 
| 121 |  |