|
1 |
|
2 /**************************************************************************** |
|
3 ** |
|
4 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
5 ** All rights reserved. |
|
6 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
7 ** |
|
8 ** This file is part of the Qt Mobility Components. |
|
9 ** |
|
10 ** $QT_BEGIN_LICENSE:LGPL$ |
|
11 ** No Commercial Usage |
|
12 ** This file contains pre-release code and may not be distributed. |
|
13 ** You may use this file in accordance with the terms and conditions |
|
14 ** contained in the Technology Preview License Agreement accompanying |
|
15 ** this package. |
|
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 2.1 as published by the Free Software |
|
20 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
21 ** packaging of this file. Please review the following information to |
|
22 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
24 ** |
|
25 ** In addition, as a special exception, Nokia gives you certain additional |
|
26 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
28 ** |
|
29 ** If you have questions regarding the use of this file, please contact |
|
30 ** Nokia at qt-info@nokia.com. |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** |
|
39 ** $QT_END_LICENSE$ |
|
40 ** |
|
41 ****************************************************************************/ |
|
42 |
|
43 #include "s60mediaplayercontrol.h" |
|
44 #include "s60mediaplayersession.h" |
|
45 |
|
46 #include <QtCore/qdir.h> |
|
47 #include <QtCore/qurl.h> |
|
48 #include <QtCore/qdebug.h> |
|
49 |
|
50 S60MediaPlayerControl::S60MediaPlayerControl(MS60MediaPlayerResolver& mediaPlayerResolver, QObject *parent) |
|
51 : QMediaPlayerControl(parent), |
|
52 m_mediaPlayerResolver(mediaPlayerResolver), |
|
53 m_session(NULL), |
|
54 m_stream(NULL) |
|
55 { |
|
56 } |
|
57 |
|
58 S60MediaPlayerControl::~S60MediaPlayerControl() |
|
59 { |
|
60 } |
|
61 |
|
62 qint64 S60MediaPlayerControl::position() const |
|
63 { |
|
64 if (m_session) |
|
65 return m_session->position(); |
|
66 return 0; |
|
67 } |
|
68 |
|
69 qint64 S60MediaPlayerControl::duration() const |
|
70 { |
|
71 if (m_session) |
|
72 return m_session->duration(); |
|
73 return -1; |
|
74 } |
|
75 |
|
76 QMediaPlayer::State S60MediaPlayerControl::state() const |
|
77 { |
|
78 if (m_session) |
|
79 return m_session->state(); |
|
80 return QMediaPlayer::StoppedState; |
|
81 } |
|
82 |
|
83 QMediaPlayer::MediaStatus S60MediaPlayerControl::mediaStatus() const |
|
84 { |
|
85 if (m_session) |
|
86 return m_session->mediaStatus(); |
|
87 return m_mediaSettings.mediaStatus(); |
|
88 } |
|
89 |
|
90 int S60MediaPlayerControl::bufferStatus() const |
|
91 { |
|
92 if (m_session) |
|
93 return m_session->bufferStatus(); |
|
94 return 0; |
|
95 } |
|
96 |
|
97 int S60MediaPlayerControl::volume() const |
|
98 { |
|
99 if (m_session) |
|
100 return m_session->volume(); |
|
101 return m_mediaSettings.volume(); |
|
102 } |
|
103 |
|
104 bool S60MediaPlayerControl::isMuted() const |
|
105 { |
|
106 if (m_session) |
|
107 return m_session->isMuted(); |
|
108 return m_mediaSettings.isMuted(); |
|
109 } |
|
110 |
|
111 bool S60MediaPlayerControl::isSeekable() const |
|
112 { |
|
113 if (m_session) |
|
114 return m_session->isSeekable(); |
|
115 return false; |
|
116 } |
|
117 |
|
118 QMediaTimeRange S60MediaPlayerControl::availablePlaybackRanges() const |
|
119 { |
|
120 QMediaTimeRange ranges; |
|
121 |
|
122 if(m_session && m_session->isSeekable()) |
|
123 ranges.addInterval(0, m_session->duration()); |
|
124 |
|
125 return ranges; |
|
126 } |
|
127 |
|
128 qreal S60MediaPlayerControl::playbackRate() const |
|
129 { |
|
130 //None of symbian players supports this. |
|
131 return m_mediaSettings.playbackRate(); |
|
132 } |
|
133 |
|
134 void S60MediaPlayerControl::setPlaybackRate(qreal rate) |
|
135 { |
|
136 //None of symbian players supports this. |
|
137 m_mediaSettings.setPlaybackRate(rate); |
|
138 emit playbackRateChanged(playbackRate()); |
|
139 |
|
140 } |
|
141 |
|
142 void S60MediaPlayerControl::setPosition(qint64 pos) |
|
143 { |
|
144 if (m_session) |
|
145 m_session->setPosition(pos); |
|
146 } |
|
147 |
|
148 void S60MediaPlayerControl::play() |
|
149 { |
|
150 if (m_session) |
|
151 m_session->play(); |
|
152 } |
|
153 |
|
154 void S60MediaPlayerControl::pause() |
|
155 { |
|
156 if (m_session) |
|
157 m_session->pause(); |
|
158 } |
|
159 |
|
160 void S60MediaPlayerControl::stop() |
|
161 { |
|
162 if (m_session) |
|
163 m_session->stop(); |
|
164 } |
|
165 |
|
166 void S60MediaPlayerControl::setVolume(int volume) |
|
167 { |
|
168 int boundVolume = qBound(0, volume, 100); |
|
169 if (boundVolume == m_mediaSettings.volume()) |
|
170 return; |
|
171 |
|
172 m_mediaSettings.setVolume(boundVolume); |
|
173 if (m_session) |
|
174 m_session->setVolume(boundVolume); |
|
175 |
|
176 emit volumeChanged(boundVolume); |
|
177 } |
|
178 |
|
179 void S60MediaPlayerControl::setMuted(bool muted) |
|
180 { |
|
181 if (m_mediaSettings.isMuted() == muted) |
|
182 return; |
|
183 |
|
184 m_mediaSettings.setMuted(muted); |
|
185 if (m_session) |
|
186 m_session->setMuted(muted); |
|
187 |
|
188 emit mutedChanged(muted); |
|
189 } |
|
190 |
|
191 QMediaContent S60MediaPlayerControl::media() const |
|
192 { |
|
193 return m_currentResource; |
|
194 } |
|
195 |
|
196 const QIODevice *S60MediaPlayerControl::mediaStream() const |
|
197 { |
|
198 return m_stream; |
|
199 } |
|
200 |
|
201 void S60MediaPlayerControl::setMedia(const QMediaContent &source, QIODevice *stream) |
|
202 { |
|
203 Q_UNUSED(stream) |
|
204 // we don't want to set & load media again when it is already loaded |
|
205 if (m_session && m_currentResource == source) |
|
206 return; |
|
207 |
|
208 // store to variable as session is created based on the content type. |
|
209 m_currentResource = source; |
|
210 S60MediaPlayerSession *newSession = m_mediaPlayerResolver.PlayerSession(); |
|
211 m_mediaSettings.setMediaStatus(QMediaPlayer::UnknownMediaStatus); |
|
212 |
|
213 if (m_session) |
|
214 m_session->reset(); |
|
215 else { |
|
216 emit mediaStatusChanged(QMediaPlayer::UnknownMediaStatus); |
|
217 emit error(QMediaPlayer::NoError, QString()); |
|
218 } |
|
219 |
|
220 m_session = newSession; |
|
221 |
|
222 if (m_session) |
|
223 m_session->load(source.canonicalUrl()); |
|
224 else { |
|
225 QMediaPlayer::MediaStatus status = (source.isNull()) ? QMediaPlayer::NoMedia : QMediaPlayer::InvalidMedia; |
|
226 m_mediaSettings.setMediaStatus(status); |
|
227 emit stateChanged(QMediaPlayer::StoppedState); |
|
228 emit error((source.isNull()) ? QMediaPlayer::NoError : QMediaPlayer::ResourceError, |
|
229 (source.isNull()) ? "" : tr("Media couldn't be resolved")); |
|
230 emit mediaStatusChanged(status); |
|
231 } |
|
232 emit mediaChanged(m_currentResource); |
|
233 } |
|
234 |
|
235 S60MediaPlayerSession* S60MediaPlayerControl::session() |
|
236 { |
|
237 return m_session; |
|
238 } |
|
239 |
|
240 void S60MediaPlayerControl::setVideoOutput(QObject *output) |
|
241 { |
|
242 S60MediaPlayerSession *session = NULL; |
|
243 session = m_mediaPlayerResolver.VideoPlayerSession(); |
|
244 session->setVideoRenderer(output); |
|
245 } |
|
246 |
|
247 bool S60MediaPlayerControl::isAudioAvailable() const |
|
248 { |
|
249 if (m_session) |
|
250 return m_session->isAudioAvailable(); |
|
251 return false; |
|
252 } |
|
253 |
|
254 bool S60MediaPlayerControl::isVideoAvailable() const |
|
255 { |
|
256 if (m_session) |
|
257 return m_session->isVideoAvailable(); |
|
258 return false; |
|
259 } |
|
260 |
|
261 const S60MediaSettings& S60MediaPlayerControl::mediaControlSettings() const |
|
262 { |
|
263 return m_mediaSettings; |
|
264 } |