|
1 /* |
|
2 * Copyright (c) 2006-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: Wrapper for CMIDClip and CMIDTone class initialisations. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <centralrepository.h> |
|
21 #include <ProfileEngineSDKCRKeys.h> |
|
22 |
|
23 #include "CMIDSound.h" |
|
24 #include "CMIDTone.h" |
|
25 #include "CMIDClip.h" |
|
26 #include "logger.h" |
|
27 #include "fs_methodcall.h" |
|
28 #include "com_nokia_mid_sound_Sound.h" |
|
29 |
|
30 |
|
31 CMIDSound* CMIDSound::NewL(JNIEnv& aJni, jobject aPeer) |
|
32 { |
|
33 JELOG2(EJavaUI); |
|
34 |
|
35 CMIDSound* self = new CMIDSound(); |
|
36 if (self != NULL) |
|
37 { |
|
38 self->attachToVm(aJni, aPeer); |
|
39 } |
|
40 return self; |
|
41 } |
|
42 |
|
43 CMIDSound::~CMIDSound() |
|
44 { |
|
45 delete iMIDSound; |
|
46 |
|
47 // CENREP |
|
48 if (iProfileListener) |
|
49 { |
|
50 iProfileListener->StopListening(); |
|
51 delete iProfileListener; |
|
52 } |
|
53 delete iRepository; |
|
54 } |
|
55 |
|
56 void CMIDSound::HandleNotifyInt(TUint32 aId, TInt aNewValue) |
|
57 { |
|
58 JELOG2(EJavaUI); |
|
59 if (aId == KProEngActiveWarningTones) |
|
60 { |
|
61 if (iMIDSound) |
|
62 { |
|
63 iMIDSound->SetVolume(aNewValue == 0 ? 0 : iRealVolume); |
|
64 } |
|
65 } |
|
66 } |
|
67 |
|
68 void CMIDSound::SendEvent(TInt aEventType) |
|
69 { |
|
70 /** |
|
71 *Callback to Java |
|
72 */ |
|
73 JELOG2(EJavaUI); |
|
74 |
|
75 jclass javaPeerClass = mJniEnv->FindClass("com/nokia/mid/sound/Sound"); |
|
76 |
|
77 jmethodID soundStateChangeCallback = mJniEnv->GetMethodID( |
|
78 javaPeerClass /*mJavaPeerClass */, "soundStateChanged", "(I)V"); |
|
79 |
|
80 |
|
81 mJniEnv->CallVoidMethod(mJavaPeerObject, soundStateChangeCallback, |
|
82 aEventType); |
|
83 } |
|
84 |
|
85 CMIDSound::CMIDSound() |
|
86 : java::util::FunctionServer("CMIDSoundFunctionServer"), |
|
87 iMIDSound(0) |
|
88 { |
|
89 JELOG2(EJavaUI); |
|
90 createServerToNewThread(); |
|
91 } |
|
92 |
|
93 int CMIDSound::InitProfileListener() |
|
94 { |
|
95 TRAPD(err, CallMethodL(this, &CMIDSound::InitProfileListenerL, this)); |
|
96 return err; |
|
97 } |
|
98 |
|
99 void CMIDSound::InitProfileListenerL() |
|
100 { |
|
101 JELOG2(EJavaUI); |
|
102 // repository for profile |
|
103 iRepository = CRepository::NewL(KCRUidProfileEngine); |
|
104 |
|
105 // get notifies about changes in KProEngActiveWarningTones |
|
106 iProfileListener = CCenRepNotifyHandler::NewL(*this, |
|
107 *iRepository, |
|
108 CCenRepNotifyHandler::EIntKey, |
|
109 KProEngActiveWarningTones); |
|
110 |
|
111 // Changes will be informed to HandleNotifyInt |
|
112 iProfileListener->StartListeningL(); |
|
113 } |
|
114 |
|
115 TBool CMIDSound::IsAudioEnabled(/*CMIDSound* aSelf*/) |
|
116 { |
|
117 JELOG2(EJavaUI); |
|
118 TInt isProfileOn = 0; |
|
119 TInt error = iRepository->Get(KProEngActiveWarningTones, isProfileOn); |
|
120 TBool retVal = EFalse; |
|
121 |
|
122 // If getting profile status fails do not play any tones. |
|
123 if ((isProfileOn == 1) && |
|
124 (error == KErrNone)) |
|
125 { |
|
126 retVal = ETrue; |
|
127 } |
|
128 return retVal; |
|
129 } |
|
130 |
|
131 void CMIDSound::SetBeep(TInt aFreq, TInt64 aDuration) |
|
132 { |
|
133 JELOG2(EJavaUI); |
|
134 iFreq = aFreq; |
|
135 iDur = aDuration; |
|
136 } |
|
137 |
|
138 TInt CMIDSound::Init(TInt aType, const TDesC8* aData) |
|
139 { |
|
140 JELOG2(EJavaUI); |
|
141 TRAPD(err, CallMethodL(this, &CMIDSound::InitL, aType, aData, this)); |
|
142 return err; |
|
143 } |
|
144 |
|
145 void CMIDSound::InitL(TInt aType, const TDesC8* aData) |
|
146 { |
|
147 JELOG2(EJavaUI); |
|
148 |
|
149 if (iMIDSound) |
|
150 { |
|
151 if (iMIDSound->State() == CMIDSoundImpl::EInitialising) |
|
152 { |
|
153 return; |
|
154 } |
|
155 if (iMIDSound->State() == CMIDSoundImpl::EReadyToPlay || |
|
156 iMIDSound->State() == CMIDSoundImpl::EPlaying) |
|
157 { |
|
158 iMIDSound->Release(); |
|
159 } |
|
160 } |
|
161 |
|
162 CMIDSoundImpl* soundImpl = NULL; |
|
163 switch (aType) |
|
164 { |
|
165 case com_nokia_mid_sound_Sound_FORMAT_TONE: //Tone |
|
166 { |
|
167 soundImpl = CMIDTone::NewL(*aData, this); |
|
168 break; |
|
169 } |
|
170 case com_nokia_mid_sound_Sound_FORMAT_BEEP: //Beep |
|
171 { |
|
172 soundImpl = CMIDTone::NewL(iFreq, iDur, this); |
|
173 break; |
|
174 } |
|
175 case com_nokia_mid_sound_Sound_FORMAT_WAV: //Wav |
|
176 { |
|
177 soundImpl = CMIDClip::NewL(aData, this); |
|
178 break; |
|
179 } |
|
180 default: |
|
181 { |
|
182 break; |
|
183 } |
|
184 } |
|
185 |
|
186 if (soundImpl) |
|
187 { |
|
188 if (soundImpl->State() != CMIDSoundImpl::EReadyToPlay) |
|
189 { |
|
190 TInt state = soundImpl->State(); |
|
191 delete soundImpl; |
|
192 User::Leave(KErrNotReady); |
|
193 } |
|
194 iRealVolume = soundImpl->Volume(); |
|
195 } |
|
196 |
|
197 delete iMIDSound; |
|
198 iMIDSound = soundImpl; |
|
199 } |
|
200 |
|
201 TInt CMIDSound::Play(TInt aLoop) |
|
202 { |
|
203 JELOG2(EJavaUI); |
|
204 TInt err; |
|
205 CallMethodL(err, this, &CMIDSound::DoPlay, aLoop, this); |
|
206 return err; |
|
207 } |
|
208 |
|
209 TInt CMIDSound::DoPlay(TInt aLoop) |
|
210 { |
|
211 JELOG2(EJavaUI); |
|
212 |
|
213 if (iMIDSound) |
|
214 { |
|
215 TInt state = iMIDSound->State(); |
|
216 if (state != CMIDSoundImpl::EReadyToPlay) |
|
217 { |
|
218 return state; |
|
219 } |
|
220 } |
|
221 else |
|
222 { |
|
223 return CMIDSoundImpl::ENotSupported; |
|
224 } |
|
225 if (!IsAudioEnabled()) |
|
226 { |
|
227 iMIDSound->SetVolume(0); |
|
228 } |
|
229 return iMIDSound->Play(aLoop); |
|
230 } |
|
231 |
|
232 void CMIDSound::Resume() |
|
233 { |
|
234 JELOG2(EJavaUI); |
|
235 CallMethod(this, &CMIDSound::DoResume, this); |
|
236 } |
|
237 |
|
238 void CMIDSound::DoResume() |
|
239 { |
|
240 JELOG2(EJavaUI); |
|
241 iMIDSound->Resume(); |
|
242 } |
|
243 |
|
244 void CMIDSound::Stop() |
|
245 { |
|
246 JELOG2(EJavaUI); |
|
247 CallMethod(this, &CMIDSound::DoStop, this); |
|
248 } |
|
249 |
|
250 void CMIDSound::DoStop() |
|
251 { |
|
252 JELOG2(EJavaUI); |
|
253 iMIDSound->Stop(); |
|
254 } |
|
255 |
|
256 TInt CMIDSound::SoundVolume() |
|
257 { |
|
258 JELOG2(EJavaUI); |
|
259 TInt result; |
|
260 CallMethodL(result, this, &CMIDSound::Volume, this); |
|
261 return result; |
|
262 } |
|
263 |
|
264 TInt CMIDSound::Volume() |
|
265 { |
|
266 JELOG2(EJavaUI); |
|
267 return iMIDSound->Volume(); |
|
268 } |
|
269 |
|
270 void CMIDSound::SetVolume(TInt aVolume) |
|
271 { |
|
272 JELOG2(EJavaUI); |
|
273 CallMethod(this, &CMIDSound::DoSetVolume, aVolume, this); |
|
274 } |
|
275 |
|
276 void CMIDSound::DoSetVolume(TInt aVolume) |
|
277 { |
|
278 JELOG2(EJavaUI); |
|
279 iRealVolume = aVolume; |
|
280 TInt currentState = iMIDSound->State(); |
|
281 if ((currentState == CMIDSoundImpl::EReadyToPlay) || |
|
282 (currentState == CMIDSoundImpl::EPlaying)) |
|
283 { |
|
284 iMIDSound->SetVolume(IsAudioEnabled() ? aVolume : 0); |
|
285 } |
|
286 } |
|
287 |
|
288 |
|
289 TInt CMIDSound::PlayerState() |
|
290 { |
|
291 JELOG2(EJavaUI); |
|
292 TInt result; |
|
293 CallMethodL(result, this, &CMIDSound::State, this); |
|
294 return result; |
|
295 } |
|
296 |
|
297 TInt CMIDSound::State() |
|
298 { |
|
299 JELOG2(EJavaUI); |
|
300 return iMIDSound->State(); |
|
301 } |
|
302 |
|
303 void CMIDSound::Release() |
|
304 { |
|
305 JELOG2(EJavaUI); |
|
306 CallMethod(this, &CMIDSound::DoRelease, this); |
|
307 } |
|
308 |
|
309 void CMIDSound::DoRelease() |
|
310 { |
|
311 JELOG2(EJavaUI); |
|
312 iMIDSound->Release(); |
|
313 } |