|
1 /* |
|
2 * Copyright (c) 2005-2006 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: Class that handles playback of tones in AudioMessage applicationn |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <avkon.hrh> |
|
21 #include <aknappui.h> |
|
22 #include <AudioPreference.h> |
|
23 #include <aknsoundsystem.h> |
|
24 #include <aknSoundinfo.h> |
|
25 |
|
26 #include "audiomessagebeep.h" |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // --------------------------------------------------------- |
|
31 // CAudioMessageBeep::Constructor |
|
32 // --------------------------------------------------------- |
|
33 // |
|
34 CAudioMessageBeep::CAudioMessageBeep() |
|
35 : iState( EVRToneIdle ) |
|
36 { |
|
37 } |
|
38 |
|
39 |
|
40 // --------------------------------------------------------- |
|
41 // CAudioMessageBeep::ConstructL |
|
42 // --------------------------------------------------------- |
|
43 // |
|
44 void CAudioMessageBeep::ConstructL() |
|
45 { |
|
46 iPlayer = CMdaAudioToneUtility::NewL( *this ); |
|
47 |
|
48 iSoundSystem = ( static_cast< CAknAppUi* >( |
|
49 CEikonEnv::Static()->EikAppUi())->KeySounds() ); |
|
50 } |
|
51 |
|
52 |
|
53 // --------------------------------------------------------- |
|
54 // CAudioMessageBeep::NewL |
|
55 // --------------------------------------------------------- |
|
56 // |
|
57 CAudioMessageBeep* CAudioMessageBeep::NewL() |
|
58 { |
|
59 CAudioMessageBeep* self = new ( ELeave ) CAudioMessageBeep; |
|
60 CleanupStack::PushL( self ); |
|
61 self->ConstructL(); |
|
62 CleanupStack::Pop( self ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 |
|
67 // --------------------------------------------------------- |
|
68 // CAudioMessageBeep::Destructor |
|
69 // --------------------------------------------------------- |
|
70 // |
|
71 CAudioMessageBeep::~CAudioMessageBeep() |
|
72 { |
|
73 if ( iPlayer ) |
|
74 { |
|
75 switch ( iPlayer->State() ) |
|
76 { |
|
77 case EMdaAudioToneUtilityNotReady: |
|
78 { |
|
79 iPlayer->CancelPrepare(); |
|
80 break; |
|
81 } |
|
82 case EMdaAudioToneUtilityPlaying: |
|
83 { |
|
84 iPlayer->CancelPlay(); |
|
85 break; |
|
86 } |
|
87 } |
|
88 } |
|
89 delete iPlayer; |
|
90 } |
|
91 |
|
92 |
|
93 // --------------------------------------------------------- |
|
94 // CAudioMessageBeep::PrepareToneL |
|
95 // Starts preparing the specified tone, preparing completes |
|
96 // with call-back to MatoPrepareComplete |
|
97 // --------------------------------------------------------- |
|
98 // |
|
99 void CAudioMessageBeep::PrepareToneL( TInt aToneId ) |
|
100 { |
|
101 if ( iState != EVRToneIdle ) |
|
102 { |
|
103 iQueuedTone = aToneId; |
|
104 return; |
|
105 } |
|
106 |
|
107 // Retrieve the tone |
|
108 CAknSoundInfo* info = CAknSoundInfo::NewL(); |
|
109 CleanupStack::PushL( info ); |
|
110 User::LeaveIfError( iSoundSystem->RequestSoundInfoL( |
|
111 aToneId, *info ) ); |
|
112 |
|
113 iPreparedTone = aToneId; |
|
114 iState = EVRTonePreparing; |
|
115 |
|
116 iPlayer->PrepareToPlayDesSequence( *info->iSequence ); |
|
117 CleanupStack::PopAndDestroy( info ); |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------- |
|
121 // CAudioMessageBeep::PrepareTone |
|
122 // Non-leaving version of PrepareToneL |
|
123 // --------------------------------------------------------- |
|
124 // |
|
125 void CAudioMessageBeep::PrepareTone( TInt aToneId ) |
|
126 { |
|
127 TRAP_IGNORE( PrepareToneL( aToneId ) ); |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------- |
|
131 // CAudioMessageBeep::PlayTone |
|
132 // Starts playback of specified tone. Completes with call-back to |
|
133 // MatoPlayComplete |
|
134 // --------------------------------------------------------- |
|
135 // |
|
136 void CAudioMessageBeep::PlayTone( TInt aToneId ) |
|
137 { |
|
138 if ( iState != EVRToneIdle || iPreparedTone != aToneId || |
|
139 iPlayer->State() == EMdaAudioToneUtilityPlaying ) |
|
140 { |
|
141 // Preparing an unprepared tone synchronously is not supported, |
|
142 // tone playback is skipped |
|
143 return; |
|
144 } |
|
145 |
|
146 // Preferences need to be set according to tone |
|
147 switch ( aToneId ) |
|
148 { |
|
149 case EAvkonSIDVoiceRecordingStartTone: |
|
150 { |
|
151 iPlayer->SetPriority( KAudioPriorityRecording, |
|
152 TMdaPriorityPreference( KAudioPrefVoiceRecStart ) ); |
|
153 break; |
|
154 } |
|
155 case EAvkonSIDVoiceRecordingStopTone: |
|
156 { |
|
157 iPlayer->SetPriority( KAudioPriorityRecording, |
|
158 TMdaPriorityPreference( KAudioPrefVoiceRecStop ) ); |
|
159 break; |
|
160 } |
|
161 default: |
|
162 { |
|
163 break; |
|
164 } |
|
165 } |
|
166 |
|
167 iState = EVRTonePlaying; |
|
168 |
|
169 iPlayer->Play(); |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------- |
|
173 // CAudioMessageBeep::MatoPrepareComplete |
|
174 // --------------------------------------------------------- |
|
175 // |
|
176 void CAudioMessageBeep::MatoPrepareComplete(TInt aError) |
|
177 { |
|
178 if ( aError ) |
|
179 { |
|
180 iPreparedTone = 0; |
|
181 } |
|
182 |
|
183 iState = EVRToneIdle; |
|
184 |
|
185 // Prepare the next tone in queue |
|
186 if ( iQueuedTone ) |
|
187 { |
|
188 TRAP_IGNORE( PrepareToneL( iQueuedTone ) ); |
|
189 iQueuedTone = 0; |
|
190 } |
|
191 |
|
192 |
|
193 } |
|
194 |
|
195 |
|
196 // --------------------------------------------------------- |
|
197 // CAudioMessageBeep::MatoPlayComplete |
|
198 // --------------------------------------------------------- |
|
199 // |
|
200 #ifdef _DEBUG |
|
201 void CAudioMessageBeep::MatoPlayComplete(TInt aError ) |
|
202 { |
|
203 RDebug::Print( _L("AudioMessage: Tone %d played, error %d"), iPreparedTone, aError ); |
|
204 #else |
|
205 void CAudioMessageBeep::MatoPlayComplete(TInt /*aError*/ ) |
|
206 { |
|
207 #endif |
|
208 |
|
209 iState = EVRToneIdle; |
|
210 |
|
211 // Prepare the next tone in queue |
|
212 if ( iQueuedTone ) |
|
213 { |
|
214 TRAP_IGNORE( PrepareToneL( iQueuedTone ) ); |
|
215 iQueuedTone = 0; |
|
216 } |
|
217 } |