15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 // INCLUDE FILES |
19 // INCLUDE FILES |
20 |
20 #include "cmmaplayer.h" |
21 #include "cmmavolumecontrol.h" |
21 #include "cmmavolumecontrol.h" |
22 #include "cmmaplayer.h" |
|
23 #include <jdebug.h> |
22 #include <jdebug.h> |
|
23 #include <mprofile.h> |
|
24 #include <mprofileengine.h> |
|
25 #include <cprofilechangenotifyhandler.h> |
24 |
26 |
25 _LIT(KMMAVolumeErrorMsg, "Can't set volume level"); |
27 _LIT(KMMAVolumeErrorMsg, "Can't set volume level"); |
26 |
28 |
27 const TInt KMMAJavaSoundIndex = 0; |
29 const TInt KMMAJavaSoundIndex = 0; |
|
30 const TInt KMMAProfileSoundIndex = 1; |
28 const TInt KMMAGlobalVolumeSoundIndex = 2; |
31 const TInt KMMAGlobalVolumeSoundIndex = 2; |
|
32 const TInt KAudioEarpiece = 3; |
29 |
33 |
30 void CMMAVolumeControl::StaticSetLevelL(CMMAVolumeControl* aVolumeControl, |
34 void CMMAVolumeControl::StaticSetLevelL(CMMAVolumeControl* aVolumeControl, |
31 TInt aLevel) |
35 TInt aLevel) |
32 { |
36 { |
33 // Java level is the first |
37 // Java level is the first |
48 } |
52 } |
49 |
53 |
50 |
54 |
51 CMMAVolumeControl::~CMMAVolumeControl() |
55 CMMAVolumeControl::~CMMAVolumeControl() |
52 { |
56 { |
|
57 delete iProfChangeNotifier; |
53 iLevels.Close(); |
58 iLevels.Close(); |
54 } |
59 } |
55 |
60 |
56 |
61 |
57 void CMMAVolumeControl::ConstructBaseL() |
62 void CMMAVolumeControl::ConstructBaseL() |
58 { |
63 { |
59 iPlayer->AddStateListenerL(this); |
64 iPlayer->AddStateListenerL(this); |
60 |
65 |
61 // Add level for java, will set in StaticSetLevelL method. |
66 // Add level for javasound, will set in StaticSetLevelL method. |
62 // In constructor iLevels array is empty and Java level will be the first, |
67 SetJavaSoundVolumeLevelL(); |
63 // KMMAJavaSoundIndex. |
68 |
64 AddLevelL(); |
69 SetProfileSoundVolumeLevelL(); |
65 |
70 |
|
71 // Sets level to 0 if profile isn't on |
66 iLevel = CalculateLevel(); |
72 iLevel = CalculateLevel(); |
67 |
73 |
68 // The default value is not yet known. Volume control may change the |
74 // The default value is not yet known. Volume control may change the |
69 // volume of the controller before it has been retrieved so when the |
75 // volume of the controller before it has been retrieved so when the |
70 // state of the player is changed the Java volume is retrieved from |
76 // state of the player is changed the Java volume is retrieved from |
71 // the controller. |
77 // the controller. |
72 iLevels[ KMMAJavaSoundIndex ] = KErrNotFound; |
78 iLevels[ KMMAJavaSoundIndex ] = KErrNotFound; |
73 } |
79 } |
|
80 |
|
81 void CMMAVolumeControl::SetJavaSoundVolumeLevelL() |
|
82 { |
|
83 // In constructor iLevels array is empty and Java level will be the first, |
|
84 // KMMAJavaSoundIndex. |
|
85 AddLevelL(); |
|
86 } |
|
87 |
|
88 void CMMAVolumeControl::SetProfileSoundVolumeLevelL() |
|
89 { |
|
90 // Add level for profile, level's index will be 1, KMMAProfileSoundIndex |
|
91 AddLevelL(); |
|
92 } |
|
93 |
|
94 void CMMAVolumeControl::SetProfilesBasedSoundMutingL() |
|
95 { |
|
96 //Get the current active profile id. |
|
97 MProfileEngine* lProfileEngine = CreateProfileEngineL(); |
|
98 iProfileId =lProfileEngine->ActiveProfileId(); |
|
99 lProfileEngine->Release(); |
|
100 |
|
101 // if profile is silent or meeting and no headset or bluetooth device |
|
102 // connected,set profile volume level to 0, otherwise keep the original |
|
103 // value 100 |
|
104 if ( (EProfileSilentId == iProfileId || EProfileMeetingId == iProfileId)&& |
|
105 iAudioOutputPreference != KAudioEarpiece ) |
|
106 { |
|
107 iLevels[ KMMAProfileSoundIndex ] = 0; |
|
108 } |
|
109 |
|
110 // Gets notfication about profile changes |
|
111 // Notification is sent to MProfileChangeObserver::HandleActiveProfileEventL() |
|
112 iProfChangeNotifier = CProfileChangeNotifyHandler::NewL( this ); |
|
113 // Sets level to 0 if profile isn't on |
|
114 iLevel = CalculateLevel(); |
|
115 |
|
116 } |
|
117 void CMMAVolumeControl::HandleActiveProfileEventL(TProfileEvent aProfileEvent, |
|
118 TInt aProfileId) |
|
119 { |
|
120 switch (aProfileEvent) |
|
121 { |
|
122 case EProfileNewActiveProfile: |
|
123 { |
|
124 // New profile is activated |
|
125 // Update the volume level, if profile is changed to silent or meeting |
|
126 // then mute it, if no headset or bluetooth device is connected |
|
127 // else set it to max volume level |
|
128 TInt level = 0; |
|
129 iProfileId = aProfileId; |
|
130 |
|
131 if ( EProfileSilentId != aProfileId && |
|
132 EProfileMeetingId != aProfileId) |
|
133 { |
|
134 |
|
135 level = KMMAVolumeMaxLevel; |
|
136 } |
|
137 else if (iAudioOutputPreference == KAudioEarpiece) |
|
138 { |
|
139 level = KMMAVolumeMaxLevel; |
|
140 } |
|
141 else |
|
142 { |
|
143 level = 0; |
|
144 } |
|
145 TRAPD( error, SetVolumeLevelL( KMMAProfileSoundIndex, level ) ); |
|
146 if ( error != KErrNone ) |
|
147 { |
|
148 iPlayer->PostStringEvent( CMMAPlayerEvent::EError, |
|
149 KMMAVolumeErrorMsg ); |
|
150 } |
|
151 break; |
|
152 } |
|
153 default: // do nothing |
|
154 break; |
|
155 } |
|
156 } |
|
157 |
|
158 |
74 |
159 |
75 const TDesC& CMMAVolumeControl::ClassName() const |
160 const TDesC& CMMAVolumeControl::ClassName() const |
76 { |
161 { |
77 return KMMAVolumeControlName; |
162 return KMMAVolumeControlName; |
78 } |
163 } |
169 EXPORT_C void CMMAVolumeControl::SetVolumeLevelL(TInt aLevelIndex, |
254 EXPORT_C void CMMAVolumeControl::SetVolumeLevelL(TInt aLevelIndex, |
170 TInt aVolumeLevel) |
255 TInt aVolumeLevel) |
171 { |
256 { |
172 DEBUG_INT2("CMMAVolumeControl::SetVolumeLevelL - setting index %d, level %d", |
257 DEBUG_INT2("CMMAVolumeControl::SetVolumeLevelL - setting index %d, level %d", |
173 aLevelIndex, aVolumeLevel); |
258 aLevelIndex, aVolumeLevel); |
174 if (0 >= iLevels.Count() || iLevels.Count() > 3) |
259 if (0 >= iLevels.Count() || iLevels.Count() > 4) |
175 { |
260 { |
176 return ; |
261 return ; |
177 } |
262 } |
178 TInt oldVolumeLevel = iLevels[ aLevelIndex ]; |
263 TInt oldVolumeLevel = iLevels[ aLevelIndex ]; |
179 iLevels[ aLevelIndex ] = aVolumeLevel; |
264 iLevels[ aLevelIndex ] = aVolumeLevel; |
212 } |
297 } |
213 |
298 |
214 *aVolumeLevel = iLevels[ aLevelIndex ]; |
299 *aVolumeLevel = iLevels[ aLevelIndex ]; |
215 |
300 |
216 DEBUG_INT("CMMAVolumeControl::GetVolumeLevelL - level %d", *aVolumeLevel); |
301 DEBUG_INT("CMMAVolumeControl::GetVolumeLevelL - level %d", *aVolumeLevel); |
|
302 } |
|
303 |
|
304 EXPORT_C void CMMAVolumeControl::SetAudioOutputPreferenceL( |
|
305 TInt aRoutingPreference) |
|
306 { |
|
307 iAudioOutputPreference = aRoutingPreference; |
|
308 // If audio o/p preference is set to private then set the profile sound |
|
309 // to max value else if profile is in silent or meeting set the profile |
|
310 // sound to 0 |
|
311 if ( iAudioOutputPreference == KAudioEarpiece) |
|
312 { |
|
313 SetVolumeLevelL(KMMAProfileSoundIndex, KMMAVolumeMaxLevel); |
|
314 } |
|
315 else if (EProfileSilentId == iProfileId || EProfileMeetingId == iProfileId) |
|
316 { |
|
317 SetVolumeLevelL(KMMAProfileSoundIndex, 0); |
|
318 } |
217 } |
319 } |
218 |
320 |
219 TInt CMMAVolumeControl::CalculateLevel() |
321 TInt CMMAVolumeControl::CalculateLevel() |
220 { |
322 { |
221 TInt levelCount = iLevels.Count(); |
323 TInt levelCount = iLevels.Count(); |