|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "s60audioplayersession.h" |
|
43 #include <QtCore/qdebug.h> |
|
44 #include <QtCore/qvariant.h> |
|
45 |
|
46 S60AudioPlayerSession::S60AudioPlayerSession(QObject *parent) |
|
47 : S60MediaPlayerSession(parent) |
|
48 , m_player(0) |
|
49 , m_audioEndpoint("Default") |
|
50 { |
|
51 #ifdef HAS_AUDIOROUTING |
|
52 m_audioOutput = 0; |
|
53 #endif //HAS_AUDIOROUTING |
|
54 QT_TRAP_THROWING(m_player = CAudioPlayer::NewL(*this, 0, EMdaPriorityPreferenceNone)); |
|
55 m_player->RegisterForAudioLoadingNotification(*this); |
|
56 } |
|
57 |
|
58 S60AudioPlayerSession::~S60AudioPlayerSession() |
|
59 { |
|
60 #ifdef HAS_AUDIOROUTING |
|
61 if (m_audioOutput) |
|
62 m_audioOutput->UnregisterObserver(*this); |
|
63 delete m_audioOutput; |
|
64 #endif |
|
65 m_player->Close(); |
|
66 delete m_player; |
|
67 } |
|
68 |
|
69 void S60AudioPlayerSession::doLoadL(const TDesC &path) |
|
70 { |
|
71 #ifdef HAS_AUDIOROUTING |
|
72 // m_audioOutput needs to be reinitialized after MapcInitComplete |
|
73 if (m_audioOutput) |
|
74 m_audioOutput->UnregisterObserver(*this); |
|
75 delete m_audioOutput; |
|
76 m_audioOutput = NULL; |
|
77 #endif //HAS_AUDIOROUTING |
|
78 m_player->OpenFileL(path); |
|
79 } |
|
80 |
|
81 qint64 S60AudioPlayerSession::doGetDurationL() const |
|
82 { |
|
83 return m_player->Duration().Int64() / qint64(1000); |
|
84 } |
|
85 |
|
86 qint64 S60AudioPlayerSession::doGetPositionL() const |
|
87 { |
|
88 TTimeIntervalMicroSeconds ms = 0; |
|
89 m_player->GetPosition(ms); |
|
90 return ms.Int64() / qint64(1000); |
|
91 } |
|
92 |
|
93 bool S60AudioPlayerSession::isVideoAvailable() const |
|
94 { |
|
95 return false; |
|
96 } |
|
97 bool S60AudioPlayerSession::isAudioAvailable() const |
|
98 { |
|
99 return true; // this is a bit happy scenario, but we do emit error that we can't play |
|
100 } |
|
101 |
|
102 void S60AudioPlayerSession::MaloLoadingStarted() |
|
103 { |
|
104 buffering(); |
|
105 } |
|
106 |
|
107 void S60AudioPlayerSession::MaloLoadingComplete() |
|
108 { |
|
109 buffered(); |
|
110 } |
|
111 |
|
112 void S60AudioPlayerSession::doPlay() |
|
113 { |
|
114 // For some reason loading progress callbalck are not called on emulator |
|
115 #ifdef __WINSCW__ |
|
116 buffering(); |
|
117 #endif |
|
118 m_player->Play(); |
|
119 #ifdef __WINSCW__ |
|
120 buffered(); |
|
121 #endif |
|
122 |
|
123 } |
|
124 |
|
125 void S60AudioPlayerSession::doPauseL() |
|
126 { |
|
127 m_player->Pause(); |
|
128 } |
|
129 |
|
130 void S60AudioPlayerSession::doStop() |
|
131 { |
|
132 m_player->Stop(); |
|
133 } |
|
134 |
|
135 void S60AudioPlayerSession::doSetVolumeL(int volume) |
|
136 { |
|
137 m_player->SetVolume((volume / 100.0) * m_player->MaxVolume()); |
|
138 } |
|
139 |
|
140 void S60AudioPlayerSession::doSetPositionL(qint64 microSeconds) |
|
141 { |
|
142 m_player->SetPosition(TTimeIntervalMicroSeconds(microSeconds)); |
|
143 } |
|
144 |
|
145 void S60AudioPlayerSession::updateMetaDataEntriesL() |
|
146 { |
|
147 metaDataEntries().clear(); |
|
148 int numberOfMetaDataEntries = 0; |
|
149 |
|
150 m_player->GetNumberOfMetaDataEntries(numberOfMetaDataEntries); |
|
151 |
|
152 for (int i = 0; i < numberOfMetaDataEntries; i++) { |
|
153 CMMFMetaDataEntry *entry = NULL; |
|
154 entry = m_player->GetMetaDataEntryL(i); |
|
155 metaDataEntries().insert(QString::fromUtf16(entry->Name().Ptr(), entry->Name().Length()), QString::fromUtf16(entry->Value().Ptr(), entry->Value().Length())); |
|
156 delete entry; |
|
157 } |
|
158 emit metaDataChanged(); |
|
159 } |
|
160 |
|
161 int S60AudioPlayerSession::doGetBufferStatusL() const |
|
162 { |
|
163 int progress = 0; |
|
164 m_player->GetAudioLoadingProgressL(progress); |
|
165 return progress; |
|
166 } |
|
167 |
|
168 #ifdef S60_DRM_SUPPORTED |
|
169 void S60AudioPlayerSession::MdapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration) |
|
170 #else |
|
171 void S60AudioPlayerSession::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration) |
|
172 #endif |
|
173 { |
|
174 Q_UNUSED(aDuration); |
|
175 setError(aError); |
|
176 #ifdef HAS_AUDIOROUTING |
|
177 TRAPD(err, |
|
178 m_audioOutput = CAudioOutput::NewL(*m_player); |
|
179 m_audioOutput->RegisterObserverL(*this); |
|
180 ); |
|
181 setActiveEndpoint(m_audioEndpoint); |
|
182 setError(err); |
|
183 #endif //HAS_AUDIOROUTING |
|
184 loaded(); |
|
185 } |
|
186 |
|
187 #ifdef S60_DRM_SUPPORTED |
|
188 void S60AudioPlayerSession::MdapcPlayComplete(TInt aError) |
|
189 #else |
|
190 void S60AudioPlayerSession::MapcPlayComplete(TInt aError) |
|
191 #endif |
|
192 { |
|
193 setError(aError); |
|
194 endOfMedia(); |
|
195 } |
|
196 |
|
197 void S60AudioPlayerSession::doSetAudioEndpoint(const QString& audioEndpoint) |
|
198 { |
|
199 m_audioEndpoint = audioEndpoint; |
|
200 } |
|
201 |
|
202 QString S60AudioPlayerSession::activeEndpoint() const |
|
203 { |
|
204 QString outputName = QString("Default"); |
|
205 #ifdef HAS_AUDIOROUTING |
|
206 if (m_audioOutput) { |
|
207 CAudioOutput::TAudioOutputPreference output = m_audioOutput->AudioOutput(); |
|
208 outputName = qStringFromTAudioOutputPreference(output); |
|
209 } |
|
210 #endif |
|
211 return outputName; |
|
212 } |
|
213 |
|
214 QString S60AudioPlayerSession::defaultEndpoint() const |
|
215 { |
|
216 QString outputName = QString("Default"); |
|
217 #ifdef HAS_AUDIOROUTING |
|
218 if (m_audioOutput) { |
|
219 CAudioOutput::TAudioOutputPreference output = m_audioOutput->DefaultAudioOutput(); |
|
220 outputName = qStringFromTAudioOutputPreference(output); |
|
221 } |
|
222 #endif |
|
223 return outputName; |
|
224 } |
|
225 |
|
226 void S60AudioPlayerSession::setActiveEndpoint(const QString& name) |
|
227 { |
|
228 #ifdef HAS_AUDIOROUTING |
|
229 CAudioOutput::TAudioOutputPreference output = CAudioOutput::ENoPreference; |
|
230 |
|
231 if (name == QString("Default")) |
|
232 output = CAudioOutput::ENoPreference; |
|
233 else if (name == QString("All")) |
|
234 output = CAudioOutput::EAll; |
|
235 else if (name == QString("None")) |
|
236 output = CAudioOutput::ENoOutput; |
|
237 else if (name == QString("Earphone")) |
|
238 output = CAudioOutput::EPrivate; |
|
239 else if (name == QString("Speaker")) |
|
240 output = CAudioOutput::EPublic; |
|
241 |
|
242 if (m_audioOutput) { |
|
243 TRAPD(err, m_audioOutput->SetAudioOutputL(output)); |
|
244 setError(err); |
|
245 |
|
246 if (m_audioEndpoint != name) { |
|
247 m_audioEndpoint = name; |
|
248 emit activeEndpointChanged(name); |
|
249 } |
|
250 } |
|
251 #endif |
|
252 } |
|
253 #ifdef HAS_AUDIOROUTING |
|
254 void S60AudioPlayerSession::DefaultAudioOutputChanged(CAudioOutput& aAudioOutput, |
|
255 CAudioOutput::TAudioOutputPreference aNewDefault) |
|
256 { |
|
257 // Emit already implemented in setActiveEndpoint function |
|
258 Q_UNUSED(aAudioOutput) |
|
259 Q_UNUSED(aNewDefault) |
|
260 } |
|
261 |
|
262 QString S60AudioPlayerSession::qStringFromTAudioOutputPreference(CAudioOutput::TAudioOutputPreference output) const |
|
263 { |
|
264 if (output == CAudioOutput::ENoPreference) |
|
265 return QString("Default"); |
|
266 else if (output == CAudioOutput::EAll) |
|
267 return QString("All"); |
|
268 else if (output == CAudioOutput::ENoOutput) |
|
269 return QString("None"); |
|
270 else if (output == CAudioOutput::EPrivate) |
|
271 return QString("Earphone"); |
|
272 else if (output == CAudioOutput::EPublic) |
|
273 return QString("Speaker"); |
|
274 return QString("Default"); |
|
275 } |
|
276 #endif |