|
1 /* This file is part of the KDE project. |
|
2 |
|
3 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
|
5 This library is free software: you can redistribute it and/or modify |
|
6 it under the terms of the GNU Lesser General Public License as published by |
|
7 the Free Software Foundation, either version 2.1 or 3 of the License. |
|
8 |
|
9 This library is distributed in the hope that it will be useful, |
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 GNU Lesser General Public License for more details. |
|
13 |
|
14 You should have received a copy of the GNU Lesser General Public License |
|
15 along with this library. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
|
17 */ |
|
18 |
|
19 #include <QUrl> |
|
20 |
|
21 #include "audioplayer.h" |
|
22 #include "utils.h" |
|
23 |
|
24 QT_BEGIN_NAMESPACE |
|
25 |
|
26 using namespace Phonon; |
|
27 using namespace Phonon::MMF; |
|
28 |
|
29 /*! \class MMF::AudioPlayer |
|
30 \internal |
|
31 */ |
|
32 |
|
33 //----------------------------------------------------------------------------- |
|
34 // Constructor / destructor |
|
35 //----------------------------------------------------------------------------- |
|
36 |
|
37 MMF::AudioPlayer::AudioPlayer() |
|
38 { |
|
39 construct(); |
|
40 } |
|
41 |
|
42 MMF::AudioPlayer::AudioPlayer(const AbstractPlayer& player) |
|
43 : AbstractMediaPlayer(player) |
|
44 { |
|
45 construct(); |
|
46 } |
|
47 |
|
48 void MMF::AudioPlayer::construct() |
|
49 { |
|
50 TRACE_CONTEXT(AudioPlayer::AudioPlayer, EAudioApi); |
|
51 TRACE_ENTRY_0(); |
|
52 |
|
53 TRAPD(err, m_player.reset(CPlayerType::NewL(*this, 0, EMdaPriorityPreferenceNone))); |
|
54 if (KErrNone != err) { |
|
55 changeState(ErrorState); |
|
56 } |
|
57 |
|
58 TRACE_EXIT_0(); |
|
59 } |
|
60 |
|
61 MMF::AudioPlayer::~AudioPlayer() |
|
62 { |
|
63 TRACE_CONTEXT(AudioPlayer::~AudioPlayer, EAudioApi); |
|
64 TRACE_ENTRY_0(); |
|
65 |
|
66 TRACE_EXIT_0(); |
|
67 } |
|
68 |
|
69 //----------------------------------------------------------------------------- |
|
70 // Public API |
|
71 //----------------------------------------------------------------------------- |
|
72 |
|
73 void MMF::AudioPlayer::doPlay() |
|
74 { |
|
75 m_player->Play(); |
|
76 } |
|
77 |
|
78 void MMF::AudioPlayer::doPause() |
|
79 { |
|
80 m_player->Pause(); |
|
81 } |
|
82 |
|
83 void MMF::AudioPlayer::doStop() |
|
84 { |
|
85 m_player->Stop(); |
|
86 } |
|
87 |
|
88 void MMF::AudioPlayer::doSeek(qint64 ms) |
|
89 { |
|
90 m_player->SetPosition(TTimeIntervalMicroSeconds(ms * 1000)); |
|
91 } |
|
92 |
|
93 int MMF::AudioPlayer::setDeviceVolume(int mmfVolume) |
|
94 { |
|
95 /* In SDK 3.1, SetVolume() returns void. If we're compiling against |
|
96 * 3.1, we handle it with ifdefs. However, if we compile against a later |
|
97 * SDK but are _running_ against 3.1, we avoid returning from an undefined |
|
98 * stack by doing a runtime check of the SDK version. */ |
|
99 #if !defined(__SERIES60_31__) |
|
100 const int err = m_player->SetVolume(mmfVolume); |
|
101 if (QSysInfo::s60Version() >= QSysInfo::SV_S60_5_0) |
|
102 return err; |
|
103 else |
|
104 return KErrNone; |
|
105 #else |
|
106 m_player->SetVolume(mmfVolume); |
|
107 return KErrNone; |
|
108 #endif |
|
109 } |
|
110 |
|
111 int MMF::AudioPlayer::openFile(RFile& file) |
|
112 { |
|
113 TRAPD(err, m_player->OpenFileL(file)); |
|
114 |
|
115 #ifdef QT_PHONON_MMF_AUDIO_DRM |
|
116 if (KErrNone == err) { |
|
117 // There appears to be a bug in the CDrmPlayerUtility implementation (at least |
|
118 // in S60 5.x) whereby the player does not check whether the loading observer |
|
119 // pointer is null before dereferencing it. Therefore we must register for |
|
120 // loading notification, even though we do nothing in the callback functions. |
|
121 m_player->RegisterForAudioLoadingNotification(*this); |
|
122 } |
|
123 #endif |
|
124 |
|
125 return err; |
|
126 } |
|
127 |
|
128 void MMF::AudioPlayer::close() |
|
129 { |
|
130 m_player->Close(); |
|
131 } |
|
132 |
|
133 bool MMF::AudioPlayer::hasVideo() const |
|
134 { |
|
135 return false; |
|
136 } |
|
137 |
|
138 qint64 MMF::AudioPlayer::currentTime() const |
|
139 { |
|
140 TRACE_CONTEXT(AudioPlayer::currentTime, EAudioApi); |
|
141 |
|
142 TTimeIntervalMicroSeconds us; |
|
143 const TInt err = m_player->GetPosition(us); |
|
144 |
|
145 qint64 result = 0; |
|
146 |
|
147 if (KErrNone == err) { |
|
148 result = toMilliSeconds(us); |
|
149 } else { |
|
150 TRACE("GetPosition err %d", err); |
|
151 |
|
152 // If we don't cast away constness here, we simply have to ignore |
|
153 // the error. |
|
154 const_cast<AudioPlayer*>(this)->setError(NormalError); |
|
155 } |
|
156 |
|
157 return result; |
|
158 } |
|
159 |
|
160 qint64 MMF::AudioPlayer::totalTime() const |
|
161 { |
|
162 return toMilliSeconds(m_player->Duration()); |
|
163 } |
|
164 |
|
165 |
|
166 //----------------------------------------------------------------------------- |
|
167 // Symbian multimedia client observer callbacks |
|
168 //----------------------------------------------------------------------------- |
|
169 |
|
170 #ifdef QT_PHONON_MMF_AUDIO_DRM |
|
171 void MMF::AudioPlayer::MdapcInitComplete(TInt aError, |
|
172 const TTimeIntervalMicroSeconds &) |
|
173 #else |
|
174 void MMF::AudioPlayer::MapcInitComplete(TInt aError, |
|
175 const TTimeIntervalMicroSeconds &) |
|
176 #endif |
|
177 { |
|
178 TRACE_CONTEXT(AudioPlayer::MapcInitComplete, EAudioInternal); |
|
179 TRACE_ENTRY("state %d error %d", state(), aError); |
|
180 |
|
181 __ASSERT_ALWAYS(LoadingState == state(), Utils::panic(InvalidStatePanic)); |
|
182 |
|
183 if (KErrNone == aError) { |
|
184 maxVolumeChanged(m_player->MaxVolume()); |
|
185 |
|
186 emit totalTimeChanged(totalTime()); |
|
187 changeState(StoppedState); |
|
188 } else { |
|
189 // TODO: set different error states according to value of aError? |
|
190 setError(NormalError); |
|
191 } |
|
192 |
|
193 TRACE_EXIT_0(); |
|
194 } |
|
195 |
|
196 #ifdef QT_PHONON_MMF_AUDIO_DRM |
|
197 void MMF::AudioPlayer::MdapcPlayComplete(TInt aError) |
|
198 #else |
|
199 void MMF::AudioPlayer::MapcPlayComplete(TInt aError) |
|
200 #endif |
|
201 { |
|
202 TRACE_CONTEXT(AudioPlayer::MapcPlayComplete, EAudioInternal); |
|
203 TRACE_ENTRY("state %d error %d", state(), aError); |
|
204 |
|
205 stopTickTimer(); |
|
206 |
|
207 if (KErrNone == aError) { |
|
208 changeState(StoppedState); |
|
209 // TODO: move on to m_nextSource |
|
210 } else { |
|
211 // TODO: do something with aError? |
|
212 setError(NormalError); |
|
213 } |
|
214 |
|
215 /* |
|
216 if (aError == KErrNone) { |
|
217 if (m_nextSource.type() == MediaSource::Empty) { |
|
218 emit finished(); |
|
219 } else { |
|
220 setSource(m_nextSource); |
|
221 m_nextSource = MediaSource(); |
|
222 } |
|
223 |
|
224 changeState(StoppedState); |
|
225 } |
|
226 else { |
|
227 m_error = NormalError; |
|
228 changeState(ErrorState); |
|
229 } |
|
230 */ |
|
231 |
|
232 TRACE_EXIT_0(); |
|
233 } |
|
234 |
|
235 CPlayerType *MMF::AudioPlayer::player() const |
|
236 { |
|
237 return m_player.data(); |
|
238 } |
|
239 |
|
240 |
|
241 #ifdef QT_PHONON_MMF_AUDIO_DRM |
|
242 void MMF::AudioPlayer::MaloLoadingStarted() |
|
243 { |
|
244 |
|
245 } |
|
246 |
|
247 void MMF::AudioPlayer::MaloLoadingComplete() |
|
248 { |
|
249 |
|
250 } |
|
251 #endif // QT_PHONON_MMF_AUDIO_DRM |
|
252 |
|
253 |
|
254 QT_END_NAMESPACE |
|
255 |