|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: File Player Events Info Note |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System Includes |
|
20 #include <e32base.h> |
|
21 #include <mdaaudiotoneplayer.h> |
|
22 #include <AudioPreference.h> |
|
23 #include <e32property.h> |
|
24 #include <coreapplicationuisdomainpskeys.h> |
|
25 |
|
26 // User Includes |
|
27 #include "evttoneplayer.h" |
|
28 #include "evtutilsconsts.h" |
|
29 #include "evttoneutils.h" |
|
30 #include "evtdebug.h" |
|
31 |
|
32 // Constants |
|
33 const TInt KMicroSeconds = 1000000; |
|
34 |
|
35 // ================ Member funtions for CEvtTonePlayer class =============== |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // CEvtTonePlayer::CEvtTonePlayer |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CEvtTonePlayer::CEvtTonePlayer( MEvtTonePlayObserver& aObserver ): |
|
42 iObserver(aObserver) |
|
43 { |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CEvtTonePlayer::~CEvtTonePlayer |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 CEvtTonePlayer::~CEvtTonePlayer() |
|
51 { |
|
52 Stop(); |
|
53 delete iProfileHandler; |
|
54 delete iCallHandler; |
|
55 |
|
56 // Delete the timer |
|
57 if( iTimer ) |
|
58 { |
|
59 StopTimer(); |
|
60 delete iTimer; |
|
61 } |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // CEvtTonePlayer::NewL |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 EXPORT_C CEvtTonePlayer* CEvtTonePlayer::NewL( MEvtTonePlayObserver& aObserver ) |
|
69 { |
|
70 CEvtTonePlayer* self = NewLC( aObserver ); |
|
71 CleanupStack::Pop( self ); |
|
72 return self; |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // CEvtTonePlayer::NewLC |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 EXPORT_C CEvtTonePlayer* CEvtTonePlayer::NewLC( MEvtTonePlayObserver& aObserver ) |
|
80 { |
|
81 CEvtTonePlayer* self = new ( ELeave )CEvtTonePlayer( aObserver ); |
|
82 CleanupStack::PushL( self ); |
|
83 self->ConstructL( ); |
|
84 return self; |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // CEvtTonePlayer::ConstructL |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 void CEvtTonePlayer::ConstructL() |
|
92 { |
|
93 EVTUIDEBUG( "+ CEvtTonePlayer::ConstructL()" ); |
|
94 iProfileHandler = CEvtProfileHandler::NewL( *this ); |
|
95 iCallHandler = CEvtCallHandler::NewL( *this ); |
|
96 EVTUIDEBUG( "- CEvtTonePlayer::ConstructL()" ); |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // CEvtTonePlayer::PlayFileL |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 EXPORT_C void CEvtTonePlayer::PlayFileL( const TFileName& aAudioFileName, |
|
104 TBool aLoop, TInt aTimeInterval ) |
|
105 { |
|
106 EVTUIDEBUG( "+ CEvtTonePlayer::PlayFileL()" ); |
|
107 |
|
108 // Stop if some tone is already playing. |
|
109 Stop(); |
|
110 |
|
111 // Stop the Timer, if it is On |
|
112 StopTimer(); |
|
113 |
|
114 // Play a beep sound if there is an active/incoming call. |
|
115 if( iCallHandler->IsCallActive() || iCallHandler->IsCallIncoming() ) |
|
116 { |
|
117 iPlayerState = ENotReady; |
|
118 iTonePlayer = CMdaAudioToneUtility::NewL( *this ); |
|
119 |
|
120 iTonePlayer->PrepareToPlayDesSequence( KPhoneBeepSequence() ); |
|
121 return; |
|
122 } |
|
123 |
|
124 TBool exist(ETrue); |
|
125 TBool playable(ETrue); |
|
126 |
|
127 // Check if Tone exists and is playable. |
|
128 TRAPD(existErr, exist = EvtToneUtils::IsExistL( aAudioFileName ) ); |
|
129 TRAPD(playableErr, playable = EvtToneUtils::IsExistL( aAudioFileName ) ); |
|
130 |
|
131 // Play tone if, |
|
132 // 1. File exists and is playable |
|
133 // 2. profile is NOT "Silent" |
|
134 if( !(iProfileHandler->IsSilentRingingType() || aAudioFileName.Length() == 0 || |
|
135 existErr || playableErr || !exist || !playable ) ) |
|
136 { |
|
137 // If the Mime type of ring tone is "KRngMimeType", then we need to play that file using |
|
138 // CMdaAudioToneUtility else we need to use CDrmPlayerUtility |
|
139 if ( EvtToneUtils::IsRNGTypeL( aAudioFileName ) ) |
|
140 { |
|
141 // Mime type of tone is "KRngMimeType" |
|
142 iPlayerState = ENotReady; |
|
143 iTonePlayer = CMdaAudioToneUtility::NewL( *this ); |
|
144 |
|
145 // Set the repeat flag based on Audio loop argument. |
|
146 if( aLoop ) |
|
147 iAudioPlayer->SetRepeats( KMdaAudioToneRepeatForever, TTimeIntervalMicroSeconds(KMicroSeconds) ); |
|
148 else |
|
149 iAudioPlayer->SetRepeats( 0 ,TTimeIntervalMicroSeconds(KMicroSeconds) ); |
|
150 |
|
151 iTonePlayer->PrepareToPlayFileSequence( aAudioFileName ); |
|
152 |
|
153 // Start the Timer if we have a Time Interval argument set. |
|
154 if( aTimeInterval ) |
|
155 { |
|
156 StartTimerL( aTimeInterval ); |
|
157 } |
|
158 } |
|
159 else |
|
160 { |
|
161 // Mime type of tone is NOT "KRngMimeType" |
|
162 iPlayerState = ENotReady; |
|
163 iAudioPlayer = CDrmPlayerUtility::NewFilePlayerL( |
|
164 aAudioFileName, |
|
165 *this, |
|
166 KAudioPriorityAlarm, |
|
167 static_cast<TMdaPriorityPreference>( KAudioPrefCalendarAlarm ) ); |
|
168 |
|
169 // Set the repeat flag based on Audio loop argument. |
|
170 if( aLoop ) |
|
171 iAudioPlayer->SetRepeats( KMdaAudioToneRepeatForever, TTimeIntervalMicroSeconds(KMicroSeconds) ); |
|
172 else |
|
173 iAudioPlayer->SetRepeats( 0 ,TTimeIntervalMicroSeconds(KMicroSeconds) ); |
|
174 |
|
175 // Start the Timer if we have a Time Interval argument set. |
|
176 if( aTimeInterval ) |
|
177 { |
|
178 StartTimerL( aTimeInterval ); |
|
179 } |
|
180 } |
|
181 } |
|
182 else |
|
183 { |
|
184 // Since we cannot play the Tone file, Play the Vibra tone if the Vibration settings is ON. |
|
185 if( iProfileHandler->IsVibra() ) |
|
186 { |
|
187 iPlayerState = ENotReady; |
|
188 iTonePlayer = CMdaAudioToneUtility::NewL( *this ); |
|
189 |
|
190 // Set to repeat forever. |
|
191 iTonePlayer->SetRepeats( KMdaAudioToneRepeatForever, TTimeIntervalMicroSeconds(KMicroSeconds) ); |
|
192 |
|
193 // No Sound sequence which is the file to play Vibration ONLY. |
|
194 iTonePlayer->PrepareToPlayDesSequence( KPhoneNoSoundSequence() ); |
|
195 |
|
196 // Start the Timer if we have a Time Interval argument set. |
|
197 if( aTimeInterval ) |
|
198 { |
|
199 StartTimerL( aTimeInterval ); |
|
200 } |
|
201 } |
|
202 // Notify the Tone Player Observer |
|
203 iObserver.TonePlayCompleteL( EFalse ); |
|
204 } |
|
205 |
|
206 EVTUIDEBUG( "- CEvtTonePlayer::PlayFileL()" ); |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // CEvtTonePlayer::StopPlayingL |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 EXPORT_C void CEvtTonePlayer::StopPlayingL( TBool aTimeout ) |
|
214 { |
|
215 EVTUIDEBUG( "+ CEvtTonePlayer::StopPlayingL()" ); |
|
216 // Stop the currently playing tone file. |
|
217 Stop(); |
|
218 |
|
219 // If the tone is stopped NOT because of the time out, then we continue to |
|
220 // play vibration tone till the time out. |
|
221 if( !aTimeout && iProfileHandler->IsVibra() ) |
|
222 { |
|
223 iPlayerState = ENotReady; |
|
224 iTonePlayer = CMdaAudioToneUtility::NewL( *this ); |
|
225 |
|
226 iTonePlayer->SetRepeats( KMdaAudioToneRepeatForever, TTimeIntervalMicroSeconds(KMicroSeconds) ); |
|
227 |
|
228 iTonePlayer->PrepareToPlayDesSequence( KPhoneNoSoundSequence() ); |
|
229 } |
|
230 else |
|
231 { |
|
232 StopTimer(); |
|
233 } |
|
234 |
|
235 // Notify the Tone Player Observer |
|
236 iObserver.TonePlayCompleteL( aTimeout ); |
|
237 EVTUIDEBUG( "- CEvtTonePlayer::StopPlayingL()" ); |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // CEvtTonePlayer::MdapcInitComplete |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void CEvtTonePlayer::MdapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/) |
|
245 { |
|
246 EVTUIDEBUG( "+ CEvtTonePlayer::MdapcInitComplete()" ); |
|
247 if( KErrNone == aError ) |
|
248 { |
|
249 iPlayerState = EReady; |
|
250 if( iAudioPlayer ) |
|
251 { |
|
252 iPlayerState = EPlaying; |
|
253 iAudioPlayer->SetVolume( PlayerVolume(iAudioPlayer->MaxVolume(), iProfileHandler->Volume()) ); |
|
254 iAudioPlayer->SetPriority( KAudioPriorityAlarm, static_cast<TMdaPriorityPreference>( KAudioPrefCalendarAlarm ) ); |
|
255 iAudioPlayer->Play(); |
|
256 } |
|
257 } |
|
258 else |
|
259 { |
|
260 iPlayerState = ENotReady; |
|
261 } |
|
262 EVTUIDEBUG( "- CEvtTonePlayer::MdapcInitComplete()" ); |
|
263 } |
|
264 |
|
265 // --------------------------------------------------------------------------- |
|
266 // CEvtTonePlayer::MdapcPlayComplete |
|
267 // --------------------------------------------------------------------------- |
|
268 // |
|
269 void CEvtTonePlayer::MdapcPlayComplete(TInt /*aError*/) |
|
270 { |
|
271 EVTUIDEBUG( "+ CEvtTonePlayer::MdapcPlayComplete()" ); |
|
272 // Notify the Tone Player Observer |
|
273 TRAPD( err, iObserver.TonePlayCompleteL( EFalse ) ); |
|
274 if(!err) |
|
275 EVTUIDEBUG1( "TonePlayCompleteL Error - %d", err ); |
|
276 EVTUIDEBUG( "- CEvtTonePlayer::MdapcPlayComplete()" ); |
|
277 } |
|
278 |
|
279 // --------------------------------------------------------------------------- |
|
280 // CEvtTonePlayer::MatoPrepareComplete |
|
281 // --------------------------------------------------------------------------- |
|
282 // |
|
283 void CEvtTonePlayer::MatoPrepareComplete(TInt aError) |
|
284 { |
|
285 EVTUIDEBUG( "+ CEvtTonePlayer::MatoPrepareComplete()" ); |
|
286 if( KErrNone == aError ) |
|
287 { |
|
288 iPlayerState = EReady; |
|
289 if( iTonePlayer ) |
|
290 { |
|
291 iPlayerState = EPlaying; |
|
292 iTonePlayer->SetVolume( PlayerVolume(iTonePlayer->MaxVolume(), iProfileHandler->Volume()) ); |
|
293 iTonePlayer->SetPriority( KAudioPriorityAlarm, static_cast<TMdaPriorityPreference>( KAudioPrefCalendarAlarm ) ); |
|
294 iTonePlayer->Play(); |
|
295 } |
|
296 } |
|
297 else |
|
298 { |
|
299 iPlayerState = ENotReady; |
|
300 } |
|
301 EVTUIDEBUG( "- CEvtTonePlayer::MatoPrepareComplete()" ); |
|
302 } |
|
303 |
|
304 // --------------------------------------------------------------------------- |
|
305 // CEvtTonePlayer::MatoPlayComplete |
|
306 // --------------------------------------------------------------------------- |
|
307 // |
|
308 void CEvtTonePlayer::MatoPlayComplete(TInt /*aError*/) |
|
309 { |
|
310 EVTUIDEBUG( "+ CEvtTonePlayer::MdapcPlayComplete()" ); |
|
311 // Notify the Tone Player Observer |
|
312 TRAPD( err, iObserver.TonePlayCompleteL( EFalse ) ); |
|
313 if(!err) |
|
314 EVTUIDEBUG1( "TonePlayCompleteL Error - %d", err ); |
|
315 EVTUIDEBUG( "- CEvtTonePlayer::MdapcPlayComplete()" ); |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // CEvtTonePlayer::Stop |
|
320 // --------------------------------------------------------------------------- |
|
321 // |
|
322 void CEvtTonePlayer::Stop() |
|
323 { |
|
324 EVTUIDEBUG( "+ CEvtTonePlayer::Stop()" ); |
|
325 if( iTonePlayer ) |
|
326 { |
|
327 if( iTonePlayer->State() == EMdaAudioToneUtilityPlaying ) |
|
328 { |
|
329 iTonePlayer->CancelPlay(); |
|
330 } |
|
331 else |
|
332 { |
|
333 iTonePlayer->CancelPrepare(); |
|
334 } |
|
335 } |
|
336 |
|
337 if( iAudioPlayer ) |
|
338 { |
|
339 iAudioPlayer->Stop(); |
|
340 iAudioPlayer->Close(); |
|
341 } |
|
342 |
|
343 if( iTonePlayer ) |
|
344 { |
|
345 delete iTonePlayer; |
|
346 iTonePlayer = NULL; |
|
347 } |
|
348 |
|
349 if( iAudioPlayer ) |
|
350 { |
|
351 delete iAudioPlayer; |
|
352 iAudioPlayer = NULL; |
|
353 } |
|
354 |
|
355 iPlayerState = EStop; |
|
356 EVTUIDEBUG( "- CEvtTonePlayer::Stop()" ); |
|
357 } |
|
358 |
|
359 // --------------------------------------------------------------------------- |
|
360 // CEvtTonePlayer::HandleIncomingCallL() |
|
361 // --------------------------------------------------------------------------- |
|
362 // |
|
363 void CEvtTonePlayer::HandleIncomingCallL() |
|
364 { |
|
365 EVTUIDEBUG( "= CEvtTonePlayer::HandleIncomingCallL()" ); |
|
366 StopTimer(); |
|
367 Stop(); |
|
368 |
|
369 // Notify the Tone Player Observer |
|
370 iObserver.TonePlayCompleteL( EFalse ); |
|
371 } |
|
372 |
|
373 // --------------------------------------------------------------------------- |
|
374 // CEvtTonePlayer::HandleProfileSettingsChange() |
|
375 // --------------------------------------------------------------------------- |
|
376 // |
|
377 void CEvtTonePlayer::HandleProfileSettingsChange() |
|
378 { |
|
379 // Nothing to do now. |
|
380 } |
|
381 |
|
382 // --------------------------------------------------------------------------- |
|
383 // CEvtTonePlayer::StartTimerL |
|
384 // --------------------------------------------------------------------------- |
|
385 // |
|
386 void CEvtTonePlayer::StartTimerL( TInt aTimeInterval ) |
|
387 { |
|
388 if( !iTimer ) |
|
389 { |
|
390 iTimer = CPeriodic::NewL( 0 ); // neutral priority |
|
391 } |
|
392 iTimer->Start( TTimeIntervalMicroSeconds32( aTimeInterval * KMicroSeconds ), |
|
393 TTimeIntervalMicroSeconds32( aTimeInterval * KMicroSeconds ), |
|
394 TCallBack(TickL, this)); |
|
395 } |
|
396 |
|
397 // --------------------------------------------------------------------------- |
|
398 // CEvtTonePlayer::StopTimer |
|
399 // --------------------------------------------------------------------------- |
|
400 // |
|
401 void CEvtTonePlayer::StopTimer( ) |
|
402 { |
|
403 if( iTimer ) |
|
404 { |
|
405 iTimer->Cancel(); |
|
406 } |
|
407 } |
|
408 |
|
409 // --------------------------------------------------------------------------- |
|
410 // CEvtTonePlayer::TickL() |
|
411 // --------------------------------------------------------------------------- |
|
412 // |
|
413 TInt CEvtTonePlayer::TickL(TAny* aObject) |
|
414 { |
|
415 ((CEvtTonePlayer*)aObject)->StopPlayingL( ETrue ); |
|
416 |
|
417 return KErrNone; |
|
418 } |
|
419 |
|
420 // ----------------------------------------------------------------------------- |
|
421 // Set volume between zero and player's maximum volume |
|
422 // ----------------------------------------------------------------------------- |
|
423 // |
|
424 TInt CEvtTonePlayer::PlayerVolume(TInt aPlayerMaxVol, TInt aVol) |
|
425 { |
|
426 const TInt KMaxProfileVolume( 10 ); |
|
427 TInt vol( 0 ); // leave as 0 if using off tone |
|
428 // calculate value between 0 and aPlayerMaxVolume |
|
429 vol = Max( 0, Min( aPlayerMaxVol / KMaxProfileVolume * aVol, aPlayerMaxVol ) ); |
|
430 |
|
431 return vol; |
|
432 } |