1 /* |
|
2 * Copyright (c) 2007 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: Handles the playing of sounds and tones for the Camera App* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <AknSoundSystem.h> //CAknKeySoundSystem |
|
21 |
|
22 #include <cameraapp.rsg> |
|
23 #include <vgacamsettings.rsg> |
|
24 |
|
25 #include <avkon.rsg> |
|
26 #include <StringLoader.h> |
|
27 #include <AudioPreference.h> |
|
28 #include <AknAppUi.h> |
|
29 |
|
30 #include "CamSoundPlayer.h" |
|
31 #include "Cam.hrh" |
|
32 #include "camutility.h" |
|
33 |
|
34 // EXTERNAL DATA STRUCTURES |
|
35 |
|
36 // EXTERNAL FUNCTION PROTOTYPES |
|
37 |
|
38 // CONSTANTS |
|
39 |
|
40 |
|
41 _LIT( KCamAutoFocusComplete, "z:\\system\\sounds\\digital\\cameraappFocusSucc.wav" ); |
|
42 //_LIT( KCamAutoFocusFailed, "c:\\system\\sounds\\digital\\focus2.wav" ); NOT DEFINED YET |
|
43 |
|
44 |
|
45 // ============================= LOCAL FUNCTIONS =============================== |
|
46 |
|
47 // ============================ MEMBER FUNCTIONS =============================== |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CCamSoundPlayer::CCamSoundPlayer |
|
51 // C++ default constructor can NOT contain any code, that |
|
52 // might leave. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CCamSoundPlayer::CCamSoundPlayer( MCamSoundPlayerObserver* aObs ) |
|
56 { |
|
57 iObserver = aObs; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CCamSoundPlayer::ConstructL |
|
62 // Symbian 2nd phase constructor can leave. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void CCamSoundPlayer::ConstructL() |
|
66 { |
|
67 iAudioPlayer = CMdaAudioPlayerUtility::NewL( *this, |
|
68 KAudioPriorityCameraTone, |
|
69 TMdaPriorityPreference( KAudioPrefCamera ) ); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CCamSoundPlayer::NewL |
|
74 // Two-phased constructor. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CCamSoundPlayer* CCamSoundPlayer::NewL( MCamSoundPlayerObserver* aObs ) |
|
78 { |
|
79 CCamSoundPlayer* self = new( ELeave ) CCamSoundPlayer( aObs ); |
|
80 |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL(); |
|
83 CleanupStack::Pop(); |
|
84 |
|
85 return self; |
|
86 } |
|
87 |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // CCamSoundPlayer::~CCamSoundPlayer |
|
91 // Destructor |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 CCamSoundPlayer::~CCamSoundPlayer() |
|
95 { |
|
96 PRINT( _L("Camera => ~CCamSoundPlayer") ); |
|
97 if ( iAudioPlayer ) |
|
98 { |
|
99 iAudioPlayer->Close(); |
|
100 delete iAudioPlayer; |
|
101 } |
|
102 |
|
103 PRINT( _L("Camera <= ~CCamSoundPlayer") ); |
|
104 } |
|
105 |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CCamSoundPlayer::InitialiseL |
|
109 // Initialize sound player. |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CCamSoundPlayer::InitialiseL() |
|
113 { |
|
114 if ( iInitialised ) |
|
115 { |
|
116 return; |
|
117 } |
|
118 |
|
119 iKeySoundSystem = static_cast<CAknAppUi*>( CEikonEnv::Static()->AppUi() )->KeySounds(); |
|
120 |
|
121 if ( !iKeySoundSystem ) |
|
122 { |
|
123 return; |
|
124 } |
|
125 |
|
126 TRAPD( error, iKeySoundSystem->AddAppSoundInfoListL( R_CAM_SOUND_LIST ) ); |
|
127 |
|
128 if ( error && error != KErrAlreadyExists ) |
|
129 { |
|
130 User::Leave( error ); |
|
131 } |
|
132 |
|
133 iInitialised = ETrue; |
|
134 } |
|
135 |
|
136 |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CCamSoundPlayer::PlaySound |
|
140 // Plays the requested sound |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 void CCamSoundPlayer::PlaySound( TCamSoundId aSoundId, |
|
144 TBool aEnableCallback ) |
|
145 { |
|
146 PRINT( _L("Camera => CCamSoundPlayer::PlaySound") ); |
|
147 |
|
148 // Get into a known state before we begin |
|
149 switch( aSoundId ) |
|
150 { |
|
151 case ECamVideoStartSoundId: |
|
152 { |
|
153 StartPlaySound( KCamVideoStartTone(), aEnableCallback ); |
|
154 break; |
|
155 } |
|
156 |
|
157 case ECamVideoStopSoundId: |
|
158 { |
|
159 StartPlaySound( KCamVideoStopTone(), aEnableCallback ); |
|
160 break; |
|
161 } |
|
162 |
|
163 case ECamVideoPauseSoundId: |
|
164 { |
|
165 StartPlaySound( KCamVideoPauseTone(), aEnableCallback ); |
|
166 break; |
|
167 } |
|
168 |
|
169 case ECamVideoResumeSoundId: |
|
170 { |
|
171 StartPlaySound( KCamVideoStartTone(), aEnableCallback ); |
|
172 break; |
|
173 } |
|
174 |
|
175 case ECamAutoFocusFailed: |
|
176 { |
|
177 PRINT( _L("Camera <> PlaySound - ECamAutoFocusFailed") ); |
|
178 // Do nothing as no failed WAV sound has been specified |
|
179 break; |
|
180 } |
|
181 |
|
182 case ECamAutoFocusComplete: |
|
183 { |
|
184 PRINT( _L("Camera <> PlaySound - ECamAutoFocusComplete") ); |
|
185 StartPlaySound( KCamAutoFocusComplete(), aEnableCallback ); |
|
186 break; |
|
187 } |
|
188 |
|
189 case ECamStillCaptureSoundId1: |
|
190 { |
|
191 StartPlaySound( KCamCaptureTone1(), aEnableCallback ); |
|
192 break; |
|
193 } |
|
194 |
|
195 case ECamStillCaptureSoundId2: |
|
196 { |
|
197 StartPlaySound( KCamCaptureTone2(), aEnableCallback ); |
|
198 break; |
|
199 } |
|
200 |
|
201 case ECamStillCaptureSoundId3: |
|
202 { |
|
203 StartPlaySound( KCamCaptureTone3(), aEnableCallback ); |
|
204 break; |
|
205 } |
|
206 |
|
207 case ECamStillCaptureSoundId4: |
|
208 { |
|
209 StartPlaySound( KCamCaptureTone4(), aEnableCallback ); |
|
210 break; |
|
211 } |
|
212 |
|
213 case ECamSelfTimerSoundId: |
|
214 { |
|
215 StartPlaySound( KCamSelfTimerTone(), aEnableCallback ); |
|
216 break; |
|
217 } |
|
218 |
|
219 default: |
|
220 { |
|
221 iEnableCallback = EFalse; |
|
222 break; |
|
223 } |
|
224 } |
|
225 PRINT( _L("Camera <= CCamSoundPlayer::PlaySound") ); |
|
226 } |
|
227 |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // CCamSoundPlayer::StartPlaySound |
|
231 // Starts the opening (and playback) of specified wav file |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 void CCamSoundPlayer::StartPlaySound( const TDesC& aFile, const TBool aEnableCallback ) |
|
235 { |
|
236 PRINT(_L("CCamSoundPlayer::StartPlaySound") ) |
|
237 iAudioPlayer->Stop(); |
|
238 iAudioPlayer->Close(); |
|
239 |
|
240 TInt err = KErrNone; |
|
241 iEnableCallback = aEnableCallback; |
|
242 |
|
243 TRAP( err, iAudioPlayer->OpenFileL( aFile ) ); |
|
244 if ( !err ) |
|
245 { |
|
246 iOpenFileInProgress = ETrue; |
|
247 } |
|
248 else |
|
249 { |
|
250 // The last OpenFileL call hasn't completed yet. |
|
251 err = KErrInUse; |
|
252 } |
|
253 |
|
254 PRINT1(_L("CCamSoundPlayer::StartPlaySound err (%d)"), err ) |
|
255 |
|
256 if ( err && aEnableCallback ) |
|
257 { |
|
258 // Cannot play sound, so notify client. |
|
259 iObserver->PlaySoundComplete(); |
|
260 iEnableCallback = EFalse; |
|
261 } |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 // CCamSoundPlayer::MapcInitComplete |
|
266 // CMdaAudioPlayerUtility initialization complete |
|
267 // --------------------------------------------------------------------------- |
|
268 // |
|
269 void CCamSoundPlayer::MapcInitComplete( TInt aError, |
|
270 const TTimeIntervalMicroSeconds& /*aDuration*/ ) |
|
271 { |
|
272 iOpenFileInProgress = EFalse; |
|
273 |
|
274 if ( !aError ) |
|
275 { |
|
276 iAudioPlayer->Play(); |
|
277 } |
|
278 else |
|
279 { |
|
280 if ( iEnableCallback ) |
|
281 { |
|
282 iObserver->PlaySoundComplete(); |
|
283 iEnableCallback = EFalse; |
|
284 } |
|
285 } |
|
286 } |
|
287 |
|
288 |
|
289 // --------------------------------------------------------------------------- |
|
290 // CCamSoundPlayer::MapcPlayComplete |
|
291 // Playback complete, notify observer |
|
292 // --------------------------------------------------------------------------- |
|
293 // |
|
294 void CCamSoundPlayer::MapcPlayComplete( TInt /*aError*/ ) |
|
295 { |
|
296 if ( iEnableCallback && iObserver) |
|
297 { |
|
298 iObserver->PlaySoundComplete(); |
|
299 iEnableCallback = EFalse; |
|
300 } |
|
301 } |
|
302 |
|
303 |
|
304 |
|
305 // --------------------------------------------------------------------------- |
|
306 // CCamSoundPlayer::DisableSelectionKeySoundL |
|
307 // Called to disable certain key press clicks |
|
308 // --------------------------------------------------------------------------- |
|
309 // |
|
310 void CCamSoundPlayer::DisableSelectionKeySoundL() |
|
311 { |
|
312 if ( iKeySoundSystem && !iSelectionKeySilent ) |
|
313 { |
|
314 iKeySoundSystem->PushContextL( R_CAM_SILENT_OK_KEY_LIST ); |
|
315 iSelectionKeySilent = ETrue; |
|
316 } |
|
317 } |
|
318 |
|
319 |
|
320 // --------------------------------------------------------------------------- |
|
321 // CCamSoundPlayer::EnableSelectionKeySound |
|
322 // Called to enable certain key press clicks |
|
323 // --------------------------------------------------------------------------- |
|
324 // |
|
325 void CCamSoundPlayer::EnableSelectionKeySound() |
|
326 { |
|
327 if ( iKeySoundSystem && iSelectionKeySilent ) |
|
328 { |
|
329 iKeySoundSystem->PopContext(); |
|
330 iSelectionKeySilent = EFalse; |
|
331 } |
|
332 } |
|
333 |
|
334 |
|
335 // --------------------------------------------------------------------------- |
|
336 // CCamSoundPlayer::DisableAllKeySoundsL |
|
337 // Called to disable all key sounds, usually when video recording |
|
338 // --------------------------------------------------------------------------- |
|
339 // |
|
340 void CCamSoundPlayer::DisableAllKeySoundsL() |
|
341 { |
|
342 if ( iKeySoundSystem && !iAllKeysSilent ) |
|
343 { |
|
344 iKeySoundSystem->PushContextL( R_AVKON_SILENT_SKEY_LIST ); |
|
345 iKeySoundSystem->BringToForeground(); |
|
346 iKeySoundSystem->LockContext(); |
|
347 iAllKeysSilent = ETrue; |
|
348 } |
|
349 } |
|
350 |
|
351 |
|
352 // --------------------------------------------------------------------------- |
|
353 // CCamSoundPlayer::EnableAllKeySoundsL |
|
354 // Called to enable all key sounds, usually when video recording |
|
355 // --------------------------------------------------------------------------- |
|
356 // |
|
357 void CCamSoundPlayer::EnableAllKeySounds() |
|
358 { |
|
359 if ( iKeySoundSystem && iAllKeysSilent ) |
|
360 { |
|
361 iKeySoundSystem->ReleaseContext(); |
|
362 iKeySoundSystem->PopContext(); |
|
363 iAllKeysSilent = EFalse; |
|
364 } |
|
365 } |
|
366 |
|
367 // End of File |
|