60
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 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: The music control for the slideshow
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
// CLASS HEADER
|
|
22 |
#include "shwmusiccontrol.h"
|
|
23 |
|
|
24 |
// EXTERNAL INCLUDES
|
|
25 |
#include <f32file.h> // RFs
|
|
26 |
#include <mpxplaybackutility.h> // MMPXPlaybackUtility
|
|
27 |
#include <mpxplaybackframeworkdefs.h> // TMPXPlaybackProperty, EPbRepeatOne
|
|
28 |
#include <mpxplaybackmessage.h> // TMPXPlaybackMessage
|
|
29 |
#include <mpxmessagegeneraldefs.h>
|
|
30 |
|
|
31 |
// INTERNAL INCLUDES
|
|
32 |
#include "shwevent.h"
|
|
33 |
#include "shwslideshowenginepanic.h"
|
|
34 |
|
|
35 |
#include <glxlog.h>
|
|
36 |
#include <glxtracer.h>
|
|
37 |
|
|
38 |
// -----------------------------------------------------------------------------
|
|
39 |
// C++ Constructor. save a few bits of ROM by inlining it.
|
|
40 |
// -----------------------------------------------------------------------------
|
|
41 |
inline CShwMusicControl::CShwMusicControl(
|
|
42 |
MShwMusicObserver& aMusicObsvr,
|
|
43 |
const TDesC& aFilePath )
|
|
44 |
: iFilePath( aFilePath ),
|
|
45 |
iMusicObsvr( aMusicObsvr ),
|
|
46 |
iMaxVolume( KErrNotFound ),
|
|
47 |
iCurrentVolume( KErrNotFound ),
|
|
48 |
iState( EMusicOff )
|
|
49 |
{
|
|
50 |
// No implementation required
|
|
51 |
}
|
|
52 |
|
|
53 |
// -----------------------------------------------------------------------------
|
|
54 |
// NewL. Static construction
|
|
55 |
// -----------------------------------------------------------------------------
|
|
56 |
CShwMusicControl* CShwMusicControl::NewL(
|
|
57 |
MShwMusicObserver& aMusicObsvr, const TDesC& aFilePath )
|
|
58 |
{
|
|
59 |
TRACER(" CShwMusicControl::NewL");
|
|
60 |
CShwMusicControl* self =
|
|
61 |
new( ELeave ) CShwMusicControl( aMusicObsvr, aFilePath );
|
|
62 |
CleanupStack::PushL( self );
|
|
63 |
self->ConstructL();
|
|
64 |
CleanupStack::Pop( self );
|
|
65 |
return self;
|
|
66 |
}
|
|
67 |
|
|
68 |
// -----------------------------------------------------------------------------
|
|
69 |
// Destructor.
|
|
70 |
// -----------------------------------------------------------------------------
|
|
71 |
CShwMusicControl::~CShwMusicControl()
|
|
72 |
{
|
|
73 |
TRACER(" CShwMusicControl::~CShwMusicControl");
|
|
74 |
if( iPlaybackUtility )
|
|
75 |
{
|
|
76 |
//The Code Scanner Error is not corrected here in the case of
|
|
77 |
//calling a leaving function in the Non Leaving Function
|
|
78 |
//We need to write a seperate Function for this.
|
|
79 |
//but will reduce not reduce any error.
|
|
80 |
iPlaybackUtility->RemoveObserverL(*this);
|
|
81 |
// Tell player to close the music playback
|
|
82 |
TRAP_IGNORE( iPlaybackUtility->CommandL( EPbCmdClose ) );
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
// Don't destroy, close releases resources.
|
|
87 |
iPlaybackUtility->Close();
|
|
88 |
}
|
|
89 |
}
|
|
90 |
|
|
91 |
// -----------------------------------------------------------------------------
|
|
92 |
// ConstructL.
|
|
93 |
// -----------------------------------------------------------------------------
|
|
94 |
void CShwMusicControl::ConstructL()
|
|
95 |
{
|
|
96 |
TRACER("CShwMusicControl::ConstructL");
|
|
97 |
// need to specify the mode and observer, without these we get a crash
|
|
98 |
iPlaybackUtility = MMPXPlaybackUtility::NewL( KPbModeNewPlayer, this );
|
|
99 |
// music playback is sacrificed if MPX fails
|
|
100 |
TRAPD( err, InitPlayerL() );
|
|
101 |
if( err == KErrNone )
|
|
102 |
{
|
|
103 |
iState = EMusicOn;
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
// ---------------------------------------------------------------------------
|
|
108 |
// Initialize the player with File Path
|
|
109 |
// ---------------------------------------------------------------------------
|
|
110 |
void CShwMusicControl::InitPlayerL()
|
|
111 |
{
|
|
112 |
TRACER("CShwMusicControl::InitPlayerL");
|
|
113 |
RFs fs;
|
|
114 |
User::LeaveIfError( fs.Connect() );
|
|
115 |
CleanupClosePushL( fs );
|
|
116 |
User::LeaveIfError( fs.ShareProtected() );
|
|
117 |
RFile file;
|
|
118 |
// try to open the file
|
|
119 |
TInt error = file.Open(
|
|
120 |
fs,
|
|
121 |
iFilePath,
|
|
122 |
EFileRead | EFileShareReadersOrWriters );
|
|
123 |
// was there an error
|
|
124 |
if( KErrNone != error )
|
|
125 |
{
|
|
126 |
GLX_LOG_INFO1(
|
|
127 |
"CShwMusicControl error in track %d", error );
|
|
128 |
// let the observer know there was an error
|
|
129 |
iMusicObsvr.ErrorWithTrackL( error );
|
|
130 |
User::Leave( error );
|
|
131 |
}
|
|
132 |
|
|
133 |
CleanupClosePushL( file );
|
|
134 |
iPlaybackUtility->InitL( file );
|
|
135 |
CleanupStack::PopAndDestroy( &file );
|
|
136 |
CleanupStack::PopAndDestroy( &fs );
|
|
137 |
|
|
138 |
// The track should loop
|
|
139 |
iPlaybackUtility->SetL( EPbPropertyRepeatMode, EPbRepeatOne );
|
|
140 |
}
|
|
141 |
|
|
142 |
// -----------------------------------------------------------------------------
|
|
143 |
// VolumeL
|
|
144 |
// Retrieve the volume values
|
|
145 |
// -----------------------------------------------------------------------------
|
|
146 |
void CShwMusicControl::VolumeL()
|
|
147 |
{
|
|
148 |
TRACER("CShwMusicControl::VolumeL");
|
|
149 |
// Retrieve the volume - Volume indicator is shown upon slideshow start and
|
|
150 |
// when the volume is changed
|
|
151 |
if (iMaxVolume == KErrNotFound)
|
|
152 |
{
|
|
153 |
iPlaybackUtility->ValueL( *this, EPbPropertyMaxVolume );
|
|
154 |
}
|
|
155 |
iPlaybackUtility->ValueL( *this, EPbPropertyVolume );
|
|
156 |
iPlaybackUtility->ValueL( *this, EPbPropertyMute );
|
|
157 |
}
|
|
158 |
|
|
159 |
// -----------------------------------------------------------------------------
|
|
160 |
// NotifyL.
|
|
161 |
// -----------------------------------------------------------------------------
|
|
162 |
void CShwMusicControl::NotifyL( MShwEvent* aEvent )
|
|
163 |
{
|
|
164 |
TRACER("CShwMusicControl::NotifyL");
|
|
165 |
// only handle events if music initialisation succeeded
|
|
166 |
if( iState == EMusicOn )
|
|
167 |
{
|
|
168 |
// reset state flag
|
|
169 |
iSwitchingMusicOn = EFalse;
|
|
170 |
// music playback is sacrificed if MPX fails
|
|
171 |
TRAPD( errr, HandleEventL( aEvent ) );
|
|
172 |
// if we had an error while switching music back on, tell observer
|
|
173 |
// that music is off
|
|
174 |
if( ( errr != KErrNone )&&
|
|
175 |
( iSwitchingMusicOn ) )
|
|
176 |
{
|
|
177 |
iMusicObsvr.MusicOff();
|
|
178 |
}
|
|
179 |
}
|
|
180 |
}
|
|
181 |
|
|
182 |
// ---------------------------------------------------------------------------
|
|
183 |
// From class MMPXPlaybackCallback.
|
|
184 |
// Handle the change of status of playback engine
|
|
185 |
// ---------------------------------------------------------------------------
|
|
186 |
void CShwMusicControl::HandlePropertyL( TMPXPlaybackProperty aProperty,
|
|
187 |
TInt aValue,
|
|
188 |
TInt aError )
|
|
189 |
{
|
|
190 |
TRACER("CShwMusicControl::HandlePropertyL");
|
|
191 |
|
|
192 |
// leave if there was an error
|
|
193 |
User::LeaveIfError( aError );
|
|
194 |
|
|
195 |
// handle max volume and volume, ignore other properties
|
|
196 |
if( EPbPropertyMaxVolume == aProperty )
|
|
197 |
{
|
|
198 |
GLX_LOG_INFO("EPbPropertyMaxVolume = aProperty");
|
|
199 |
iMaxVolume = aValue;
|
|
200 |
}
|
|
201 |
else if( EPbPropertyVolume == aProperty )
|
|
202 |
{
|
|
203 |
GLX_LOG_INFO1("EPbPropertyVolume = aProperty - aValue: %d",aValue);
|
|
204 |
// set the current volume
|
|
205 |
iCurrentVolume = aValue;
|
|
206 |
// call observer only when max volume is also known
|
|
207 |
// iMaxVolume and iCurrentVolume are initialized to KErrNotFound
|
|
208 |
if( iMaxVolume != KErrNotFound )
|
|
209 |
{
|
|
210 |
iMusicObsvr.MusicVolumeL( iCurrentVolume, iMaxVolume );
|
|
211 |
}
|
|
212 |
}
|
|
213 |
else if( EPbPropertyMute == aProperty)
|
|
214 |
{
|
|
215 |
GLX_LOG_INFO1("EPbPropertyMute = aProperty - aValue: %d",aValue);
|
|
216 |
//Ref: TMPXPlaybackProperty - EPbPropertyMute - aValue 0(normal), 1(muted)
|
|
217 |
if(aValue == 1)
|
|
218 |
{
|
|
219 |
iCurrentVolume = 0;
|
|
220 |
if( iMaxVolume != KErrNotFound )
|
|
221 |
{
|
|
222 |
iMusicObsvr.MusicVolumeL( iCurrentVolume, iMaxVolume );
|
|
223 |
}
|
|
224 |
}
|
|
225 |
}
|
|
226 |
}
|
|
227 |
|
|
228 |
// -----------------------------------------------------------------------------
|
|
229 |
// From MMPXPlaybackCallback
|
|
230 |
// Method is called continously until aComplete=ETrue, signifying that
|
|
231 |
// it is done and there will be no more callbacks
|
|
232 |
// Only new items are passed each time
|
|
233 |
// -----------------------------------------------------------------------------
|
|
234 |
void CShwMusicControl::HandleSubPlayerNamesL(
|
|
235 |
TUid /*aPlayer*/, const MDesCArray* /*aSubPlayers*/,
|
|
236 |
TBool /*aComplete*/, TInt /*aError*/ )
|
|
237 |
{
|
|
238 |
}
|
|
239 |
|
|
240 |
// ---------------------------------------------------------------------------
|
|
241 |
// From class MMPXPlaybackCallback.
|
|
242 |
// Call back of media request
|
|
243 |
// ---------------------------------------------------------------------------
|
|
244 |
void CShwMusicControl::HandleMediaL(
|
|
245 |
const CMPXMedia& /*aProperties*/, TInt /*aError*/ )
|
|
246 |
{
|
|
247 |
}
|
|
248 |
|
|
249 |
// ---------------------------------------------------------------------------
|
|
250 |
// GetMusicVolumeL
|
|
251 |
// ---------------------------------------------------------------------------
|
|
252 |
void CShwMusicControl::GetMusicVolumeL()
|
|
253 |
{
|
|
254 |
TRACER("CShwMusicControl::GetMusicVolumeL");
|
|
255 |
if ( iCanPlay )
|
|
256 |
{
|
|
257 |
VolumeL();
|
|
258 |
}
|
|
259 |
}
|
|
260 |
|
|
261 |
// ---------------------------------------------------------------------------
|
|
262 |
// From class MMPXPlaybackObserver
|
|
263 |
// Handle playback message - required for debugging state of MPX
|
|
264 |
// Player component
|
|
265 |
// ---------------------------------------------------------------------------
|
|
266 |
void CShwMusicControl::HandlePlaybackMessageL(
|
|
267 |
const TMPXPlaybackMessage& /*aMessage*/ )
|
|
268 |
{
|
|
269 |
}
|
|
270 |
|
|
271 |
// ---------------------------------------------------------------------------
|
|
272 |
// From MMPXPlaybackObserver
|
|
273 |
// ---------------------------------------------------------------------------
|
|
274 |
void CShwMusicControl::HandlePlaybackMessage(const CMPXMessage& aMsg)
|
|
275 |
{
|
|
276 |
TRACER("CShwMusicControl::HandlePlaybackMessage");
|
|
277 |
|
|
278 |
switch(*aMsg.Value<TMPXPlaybackMessage::TEvent>( KMPXMessageGeneralEvent ))
|
|
279 |
{
|
|
280 |
case TMPXPlaybackMessage::EInitializeComplete:
|
|
281 |
{
|
|
282 |
GLX_LOG_INFO( "TMPXPlaybackMessage::EInitializeComplete" );
|
|
283 |
// at here, can play the track
|
|
284 |
iCanPlay = ETrue;
|
|
285 |
|
|
286 |
//execute the cached "play" command
|
|
287 |
if ( iPlayCached )
|
|
288 |
{
|
|
289 |
GLX_LOG_INFO( "iPlayCached" );
|
|
290 |
// Play the track
|
|
291 |
//The Code Scanner Error is not corrected here in the case of
|
|
292 |
//calling a leaving function in the Non Leaving Function
|
|
293 |
//We need to write a seperate Function for this.
|
|
294 |
//but will reduce only one error.
|
|
295 |
TRAP_IGNORE(iPlaybackUtility->CommandL( EPbCmdPlay ) );
|
|
296 |
iMusicObsvr.MusicOnL();
|
|
297 |
// need to call volume ourself to show the
|
|
298 |
// volume indicator in start
|
|
299 |
VolumeL();
|
|
300 |
iPlayCached = EFalse;
|
|
301 |
}
|
|
302 |
break;
|
|
303 |
}
|
|
304 |
default:
|
|
305 |
{
|
|
306 |
GLX_LOG_INFO( "CShwMusicControl::HandlePlaybackMessage: Default" );
|
|
307 |
break;
|
|
308 |
}
|
|
309 |
}
|
|
310 |
}
|
|
311 |
|
|
312 |
// -----------------------------------------------------------------------------
|
|
313 |
// HandleEventL.
|
|
314 |
// -----------------------------------------------------------------------------
|
|
315 |
void CShwMusicControl::HandleEventL( MShwEvent* aEvent )
|
|
316 |
{
|
|
317 |
TRACER("CShwMusicControl::HandleEventL( MShwEvent* aEvent )");
|
|
318 |
// we got an event, was it start
|
|
319 |
if( dynamic_cast< TShwEventStart* >( aEvent ) )
|
|
320 |
{
|
|
321 |
GLX_LOG_INFO( "CShwMusicControl::NotifyL - TShwEventStart" );
|
|
322 |
// set state flag
|
|
323 |
iSwitchingMusicOn = ETrue;
|
|
324 |
// iCanPlay is True when Player is Initialized.
|
|
325 |
if ( iCanPlay )
|
|
326 |
{
|
|
327 |
GLX_LOG_INFO( "inside ICanPlay" );
|
|
328 |
// Play the track
|
|
329 |
TRAP_IGNORE(iPlaybackUtility->CommandL( EPbCmdPlay ) );
|
|
330 |
iMusicObsvr.MusicOnL();
|
|
331 |
// need to call volume ourself to show the
|
|
332 |
// volume indicator in start
|
|
333 |
VolumeL();
|
|
334 |
}
|
|
335 |
else
|
|
336 |
{
|
|
337 |
GLX_LOG_INFO( "inside Else: ICanPlay" );
|
|
338 |
// initialization is not finished ,and cache the "play" command
|
|
339 |
iPlayCached = ETrue;
|
|
340 |
}
|
|
341 |
}
|
|
342 |
else if( dynamic_cast< TShwEventPause* >( aEvent ) )
|
|
343 |
{
|
|
344 |
GLX_LOG_INFO( "CShwMusicControl::NotifyL - TShwEventPause" );
|
|
345 |
// pause playback
|
|
346 |
iPlaybackUtility->CommandL( EPbCmdPause );
|
|
347 |
// let the observer know
|
|
348 |
iMusicObsvr.MusicOff();
|
|
349 |
}
|
|
350 |
else if( dynamic_cast< TShwEventResume* >( aEvent ) )
|
|
351 |
{
|
|
352 |
GLX_LOG_INFO( "CShwMusicControl::NotifyL - TShwEventResume" );
|
|
353 |
// set state flag
|
|
354 |
iSwitchingMusicOn = ETrue;
|
|
355 |
// resume
|
|
356 |
iPlaybackUtility->CommandL( EPbCmdPlay );
|
|
357 |
// let the observer know
|
|
358 |
iMusicObsvr.MusicOnL();
|
|
359 |
}
|
|
360 |
else if( dynamic_cast< TShwEventVolumeDown* >( aEvent ) )
|
|
361 |
{
|
|
362 |
GLX_LOG_INFO( "CShwMusicControl::NotifyL - TShwEventVolumeDown" );
|
|
363 |
|
|
364 |
iPlaybackUtility->CommandL( EPbCmdDecreaseVolume );
|
|
365 |
VolumeL();
|
|
366 |
}
|
|
367 |
else if( dynamic_cast< TShwEventVolumeUp* >( aEvent ) )
|
|
368 |
{
|
|
369 |
GLX_LOG_INFO( "CShwMusicControl::NotifyL - TShwEventVolumeUp" );
|
|
370 |
|
|
371 |
iPlaybackUtility->CommandL( EPbCmdIncreaseVolume );
|
|
372 |
VolumeL();
|
|
373 |
}
|
|
374 |
else if( dynamic_cast< TShwEventToggleControlUi* >( aEvent ) )
|
|
375 |
{
|
|
376 |
GLX_LOG_INFO( "CShwMusicControl::NotifyL - TShwEventToggleControlUi" );
|
|
377 |
// Have to impliment if need comes
|
|
378 |
}
|
|
379 |
}
|
|
380 |
|