14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 #include <cxesoundplayersymbian.h> |
17 #include <cxesoundplayersymbian.h> |
18 #include <AudioPreference.h> |
18 #include <AudioPreference.h> |
|
19 #include <ProfileEngineSDKCRKeys.h> |
19 #include "cxutils.h" |
20 #include "cxutils.h" |
20 #include "cxecameradevicecontrolsymbian.h" |
21 #include "cxecameradevicecontrolsymbian.h" |
21 #include "cxestate.h" |
22 #include "cxestate.h" |
|
23 #include "cxesettings.h" |
|
24 |
22 |
25 |
23 const TUint KCxeAudioPriority = KAudioPriorityCameraTone; |
26 const TUint KCxeAudioPriority = KAudioPriorityCameraTone; |
24 //const TUint KCxeAudioPriority = KAudioPriorityVideoRecording; |
|
25 |
27 |
26 _LIT(KCxeCaptureSound, "z:\\system\\sounds\\digital\\capture.wav"); |
28 _LIT(KCxeCaptureSound, "z:\\system\\sounds\\digital\\capture.wav"); |
27 _LIT(KCxeVideoStartSound, "z:\\system\\sounds\\digital\\videoStart.wav"); |
29 _LIT(KCxeVideoStartSound, "z:\\system\\sounds\\digital\\videoStart.wav"); |
28 _LIT(KCxeVideoStopSound, "z:\\system\\sounds\\digital\\videoStop.wav"); |
30 _LIT(KCxeVideoStopSound, "z:\\system\\sounds\\digital\\videoStop.wav"); |
29 _LIT(KCxeAutoFocusSound, "z:\\system\\sounds\\digital\\autoFocus.wav"); |
31 _LIT(KCxeAutoFocusSound, "z:\\system\\sounds\\digital\\autoFocus.wav"); |
30 |
32 |
31 |
33 |
32 CxeSoundPlayerSymbian::CxeSoundPlayerSymbian(CaptureSound soundId) : |
34 CxeSoundPlayerSymbian::CxeSoundPlayerSymbian(CaptureSound soundId, |
|
35 CxeSettings &settings) : |
33 CxeStateMachine("CxeSoundPlayerSymbian"), |
36 CxeStateMachine("CxeSoundPlayerSymbian"), |
34 mAudioPlayer(NULL), |
37 mAudioPlayer(NULL), |
35 mSoundId(soundId) |
38 mSoundId(soundId), |
36 { |
39 mUseSound(true), |
37 CX_DEBUG_ENTER_FUNCTION(); |
40 mCaptureSoundForced(false), |
|
41 mSettings(settings) |
|
42 { |
|
43 CX_DEBUG_ENTER_FUNCTION(); |
|
44 |
|
45 checkCaptureSoundSettings(); |
|
46 |
|
47 // connect to setting changed signal in order to monitor |
|
48 // profile warning tone changes |
|
49 connect(&mSettings, |
|
50 SIGNAL(settingValueChanged(long int, unsigned long int, QVariant)), |
|
51 this, SLOT(enableSound(long int, unsigned long int, QVariant))); |
38 |
52 |
39 qRegisterMetaType<CxeSoundPlayerSymbian::State>(); |
53 qRegisterMetaType<CxeSoundPlayerSymbian::State>(); |
40 initializeStates(); |
54 initializeStates(); |
41 |
55 |
42 doOpen(); |
56 doOpen(); |
50 delete mAudioPlayer; |
64 delete mAudioPlayer; |
51 |
65 |
52 CX_DEBUG_EXIT_FUNCTION(); |
66 CX_DEBUG_EXIT_FUNCTION(); |
53 } |
67 } |
54 |
68 |
|
69 /*! |
|
70 * Plays the current sound file if soundplayer is in correct state. Once |
|
71 * playing is finished or there is an error playComplete signal is emitted. |
|
72 * \sa playComplete() |
|
73 */ |
55 void CxeSoundPlayerSymbian::play() |
74 void CxeSoundPlayerSymbian::play() |
56 { |
75 { |
57 CX_DEBUG_ENTER_FUNCTION(); |
76 CX_DEBUG_ENTER_FUNCTION(); |
58 CX_DEBUG(("CxeSoundPlayerSymbian::play mSoundId: %d, state: %d", mSoundId, state())); |
77 CX_DEBUG(("CxeSoundPlayerSymbian::play mSoundId: %d, state: %d", mSoundId, state())); |
59 |
78 |
60 // Only play the capture sound if CMdaAudioPlayerUtility is initialised |
79 // Only play the capture sound if CMdaAudioPlayerUtility is initialised |
61 if (state() == Ready) { |
80 if (state() == Ready) { |
62 //! @todo: Define & implement what to do, when sound is already playing. |
81 |
63 // Important for sequence mode. |
82 if (mUseSound) { |
64 setState(Playing); |
83 //! @todo: Define & implement what to do, when sound is already playing. |
65 mAudioPlayer->Play(); |
84 // Important for sequence mode. |
|
85 setState(Playing); |
|
86 mAudioPlayer->Play(); |
|
87 } else { |
|
88 CX_DEBUG(("CxeSoundPlayerSymbian::play capture sounds turned off")); |
|
89 |
|
90 // sounds are off and we don't play the sound, |
|
91 // act as the sound has been played |
|
92 emit playComplete(KErrNone); |
|
93 } |
|
94 |
66 } else if( state() == NotReady ) { |
95 } else if( state() == NotReady ) { |
67 // Here sound loading has failed. |
96 // Here sound loading has failed. |
68 // Emit signal with error code. |
97 // Emit signal with error code. |
69 emit playComplete(KErrNotReady); |
98 emit playComplete(KErrNotReady); |
70 } |
99 } |
71 |
100 |
72 CX_DEBUG_EXIT_FUNCTION(); |
101 CX_DEBUG_EXIT_FUNCTION(); |
73 } |
102 } |
74 |
103 |
75 |
104 |
143 setState(NotReady); |
173 setState(NotReady); |
144 } |
174 } |
145 } |
175 } |
146 |
176 |
147 |
177 |
148 void CxeSoundPlayerSymbian::handleStateChanged(int /*newStateId*/, CxeError::Id /*error*/) |
178 void CxeSoundPlayerSymbian::handleStateChanged(int newStateId, CxeError::Id error) |
149 { |
179 { |
|
180 Q_UNUSED(newStateId); |
|
181 Q_UNUSED(error); |
150 // No implementation needed, because state is not visible outside of this class |
182 // No implementation needed, because state is not visible outside of this class |
151 } |
183 } |
152 |
184 |
|
185 /*! |
|
186 * Returns the current sound player state. |
|
187 * \return Current state |
|
188 */ |
153 CxeSoundPlayerSymbian::State CxeSoundPlayerSymbian::state() const |
189 CxeSoundPlayerSymbian::State CxeSoundPlayerSymbian::state() const |
154 { |
190 { |
155 return static_cast<State>(stateId()); |
191 return static_cast<State>(stateId()); |
156 } |
192 } |
157 |
193 |
|
194 /*! |
|
195 * Initialize CxeStateMachine. |
|
196 */ |
158 void CxeSoundPlayerSymbian::initializeStates() |
197 void CxeSoundPlayerSymbian::initializeStates() |
159 { |
198 { |
160 // addState(id, name, allowed next states) |
199 // addState(id, name, allowed next states) |
161 addState(new CxeState(NotReady, "NotReady", Opening)); |
200 addState(new CxeState(NotReady, "NotReady", Opening)); |
162 addState(new CxeState(Opening, "Opening", NotReady | Ready)); |
201 addState(new CxeState(Opening, "Opening", NotReady | Ready)); |
163 addState(new CxeState(Ready, "Ready", Playing | Opening | NotReady)); |
202 addState(new CxeState(Ready, "Ready", Playing | Opening | NotReady)); |
164 addState(new CxeState(Playing, "Playing", Ready | Opening | NotReady)); |
203 addState(new CxeState(Playing, "Playing", Ready | Opening | NotReady)); |
165 |
204 |
166 setInitialState(NotReady); |
205 setInitialState(NotReady); |
167 } |
206 } |
|
207 |
|
208 /*! |
|
209 * Enables or disables the capture sound. If capture sound is forced to |
|
210 * be always on, then the capture sound cannot be disabled. |
|
211 * |
|
212 * \param uid UID of the changed setting |
|
213 * \param key Key of the changed setting |
|
214 * \param value New setting value |
|
215 */ |
|
216 void CxeSoundPlayerSymbian::enableSound(long int uid, unsigned long int key, QVariant value) |
|
217 { |
|
218 |
|
219 // selftimer is only interested in warning tones |
|
220 if (uid == KCRUidProfileEngine.iUid && key == KProEngActiveWarningTones) { |
|
221 CX_DEBUG_IN_FUNCTION(); |
|
222 // possible values are: |
|
223 // 0 -> warning tones off |
|
224 // 1 -> warning tones on |
|
225 bool warningTonesEnabled = (value.toInt() == 1); |
|
226 |
|
227 // update sound |
|
228 mUseSound = mCaptureSoundForced || warningTonesEnabled; |
|
229 } |
|
230 |
|
231 CX_DEBUG(("CxeSoundPlayerSymbian::enableSound <> Use sound [%d]", |
|
232 mUseSound)); |
|
233 } |
|
234 |
|
235 /*! |
|
236 * Checks the initial capture sound settings based on profile warning tones |
|
237 * and whether the capture sound is forced to be always on. Connects settings |
|
238 * signal for capture sounds changes to enableCaptureSound slot. |
|
239 * |
|
240 * \sa enableCaptureSound() |
|
241 */ |
|
242 void CxeSoundPlayerSymbian::checkCaptureSoundSettings() |
|
243 { |
|
244 |
|
245 CX_DEBUG_ENTER_FUNCTION(); |
|
246 |
|
247 QVariant value(0); |
|
248 |
|
249 // get current profile setting for using camerasound |
|
250 // camera sound follows warning tone setting |
|
251 unsigned long int key = KProEngActiveWarningTones; |
|
252 long int uid = KCRUidProfileEngine.iUid; |
|
253 mSettings.get(uid, key, Cxe::Repository, value); |
|
254 |
|
255 // possible values are: |
|
256 // 0 -> warning tones off |
|
257 // 1 -> warning tones on |
|
258 bool warningTonesEnabled = (value.toInt() == 1); |
|
259 CX_DEBUG(("Warning tones enabled [%d]", value.toInt())); |
|
260 |
|
261 // check whether capture sound is forced or not |
|
262 int forced = 0; |
|
263 mSettings.get(CxeSettingIds::CAPTURE_SOUND_ALWAYS_ON, forced); |
|
264 // 0 -> capture sound not forced |
|
265 // 1 -> capture sound forced on |
|
266 mCaptureSoundForced = (forced == 1); |
|
267 CX_DEBUG(("Capture sound forced [%d]", forced)); |
|
268 |
|
269 // use sound if forced on or warningtones are enabled |
|
270 mUseSound = mCaptureSoundForced || warningTonesEnabled; |
|
271 CX_DEBUG(("Use sound [%d]", mUseSound)); |
|
272 |
|
273 CX_DEBUG_EXIT_FUNCTION(); |
|
274 } |
|
275 |
|
276 |
|
277 // end of file |
|
278 |