os/mm/mmlibs/mmfw/tsrc/mmvalidationsuite/mmvalidationsuiteagents/src/audioplayagent.cpp
First public contribution.
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Part of the MVS Agents for TechView
17 #include "audioplayagent.h"
23 Constructs and initialises a new instance of the MVS audio player utility.
25 The function leaves if the MVS audio player utility object cannot be created.
27 No callback notification is made upon completion of NewL().
30 Class to receive state change events from play agent.
32 @return A pointer to the new MVS audio player utility object.
35 EXPORT_C CMVSAudioPlayAgent* CMVSAudioPlayAgent::NewL(MMVSClientObserver& aObserver)
37 CMVSAudioPlayAgent* self = new(ELeave) CMVSAudioPlayAgent(aObserver);
38 CleanupStack::PushL(self);
40 CleanupStack::Pop(self);
45 void CMVSAudioPlayAgent::ConstructL()
47 iPlayer = CMdaAudioPlayerUtility::NewL(*this);
48 User::LeaveIfError(iFileLogger.Connect());
49 iFileLogger.CreateLog(_L("LogMVSappUi"),_L("LogFile.txt"),EFileLoggingModeAppend);
53 EXPORT_C CMVSAudioPlayAgent::~CMVSAudioPlayAgent()
56 if(iFileLogger.Handle())
58 iFileLogger.CloseLog();
64 CMVSAudioPlayAgent::CMVSAudioPlayAgent(MMVSClientObserver& aObserver):iObserver(aObserver)
66 iObserver.UpdateStateChange(ENotReady, KErrNone);
69 EXPORT_C void CMVSAudioPlayAgent::OpenFileL(TDesC& aFile)
71 iPlayer->Close();//Close any existing clip
72 iState = EAudioOpening;
73 iObserver.UpdateStateChange(EAudioOpening, KErrNone);
74 iPlayer->OpenFileL(aFile);
77 EXPORT_C void CMVSAudioPlayAgent::OpenFileL(TMMSource& /*aSource*/)
83 Begins playback of the initialised audio sample at the current volume
86 Sets the current state of the system to EAudioPlaying
87 When playing of the audio sample is complete, successfully or
88 otherwise, the callback function
89 CMVSAudioPlayAgent::MapcPlayComplete() is called, which inturn
90 sets the state to EAudioOpened.
92 EXPORT_C void CMVSAudioPlayAgent::Play()
94 //must be in open or paused states
95 if((iState == EAudioOpened)||(iState == EAudioPaused)||(iState == EAudioStopped))
98 iState = EAudioPlaying;
99 iObserver.UpdateStateChange(EAudioPlaying, KErrNone);
105 Pauses the playback of the audio clip.
106 and updates the current state to EAudioPaused.
108 EXPORT_C TInt CMVSAudioPlayAgent::Pause()
110 if(iState == EAudioPlaying)
112 TInt err = iPlayer->Pause();
113 if ( err != KErrNone)
117 iState = EAudioPaused;
118 iObserver.UpdateStateChange(EAudioPaused, KErrNone);
125 Stops playback of the audio sample as soon as possible.
127 Sets the current state to EAudioStopped
128 If the audio sample is playing, playback is stopped as soon as
129 possible. If playback is already complete, nothing further happens as
130 a result of calling this function.
132 EXPORT_C void CMVSAudioPlayAgent::Stop()
134 if(iState == EAudioPlaying || iState == EAudioPaused)
137 iState = EAudioStopped;
138 iObserver.UpdateStateChange(iState, KErrNone);
143 Added for future implimentation. Currently not supported
145 EXPORT_C void CMVSAudioPlayAgent::Forward()
147 // future implementation
152 Added for future implimentation. Currently not supported
154 EXPORT_C void CMVSAudioPlayAgent::Rewind()
156 // future implementation
161 Initialisation completion callback for the MVS play agent
163 void CMVSAudioPlayAgent::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
165 if(aError == KErrNone)
167 iState = EAudioOpened;
168 iFileLogger.Write(_L("Audio Opened ")) ;
172 iState = ENotReady; //init failed so from opening to NotReady
173 iFileLogger.Write(_L("MapcInitComplete: Audio Not Ready")) ;
175 iObserver.UpdateStateChange(iState, aError);
180 Play back completion callback for the MVS play agent
182 void CMVSAudioPlayAgent::MapcPlayComplete(TInt aError)
184 if(aError == KErrNone)
186 iState = EAudioOpened;
187 iFileLogger.Write(_L("MapcPlayComplete:Audio Opened Play Complete")) ;
190 iObserver.UpdateStateChange(iState, aError);
193 void CMVSAudioPlayAgent::MarncResourceAvailable(TUid /*aNotificationEventId*/, const TDesC8& /*aNotificationData*/)
199 Returns the current playback volume
202 A volume value between 0 and the value returned by MaxVolume().
204 @return One of the global error codes.
206 EXPORT_C TInt CMVSAudioPlayAgent::GetVolume(TInt& aVolume)
208 return iPlayer->GetVolume(aVolume);
213 Returns an integer representing the maximum volume.
215 This is the maximum value which can be passed to
216 CMdaAudioPlayerUtility::SetVolume(). This value is platform
217 independent, but is always greater than or equal to one.
219 The function raises a CMdaAudioPlayerUtility 1 panic if the
220 audio player utility is not initialised.
222 @return The maximum volume setting.
224 EXPORT_C TInt CMVSAudioPlayAgent::MaxVolume()
226 return iPlayer->MaxVolume();
231 Returns the duration of the audio sample.
233 The function raises a CMdaAudioPlayerUtility 1 panic if the audio
234 player utility is not initialised.
236 @return The duration in microseconds.
238 EXPORT_C TTimeIntervalMicroSeconds CMVSAudioPlayAgent::Duration()
240 return iPlayer->Duration();
245 Changes the current playback volume to a specified value.
247 The volume can be changed before or during playback and is effective
248 immediately. The volume can be set to any value between zero (mute) and
249 the maximum permissible volume (determined using MaxVolume()).Also the
250 period over which the volume level is to rise smoothly from nothing to
251 the normal volume level,is given by the ramp up time.
254 The function raises a CMdaAudioPlayerUtility 1 panic if
255 the audio player utility is not initialised.
258 The volume setting. This can be any value from zero to
259 the value returned by a call to
260 CMVSAudioPlayAgent::MaxVolume().
261 Setting a zero value mutes the sound. Setting the
262 maximum value results in the loudest possible sound.
265 The period over which the volume is to rise. A zero
266 value causes the audio sample to be played at the
267 normal level for the full duration of the playback. A
268 value which is longer than the duration of the audio
269 sample means that the sample never reaches its normal
273 EXPORT_C void CMVSAudioPlayAgent::SetVolume(TInt aVolume, TTimeIntervalMicroSeconds aRamp)
275 iPlayer->SetVolume(aVolume);
276 iPlayer->SetVolumeRamp(aRamp);
281 Returns the current playback position in microseconds from the start of the clip.
284 The current time position in microseconds from the start of the clip to the current
287 @return the current playback position in microseconds.
289 EXPORT_C TTimeIntervalMicroSeconds CMVSAudioPlayAgent::GetPosition(TTimeIntervalMicroSeconds& aPosition)
291 return iPlayer->GetPosition(aPosition);
296 Sets the current playback position in microseconds from the start of the clip.
299 The position to move to in microseconds from the start of the clip.
301 EXPORT_C void CMVSAudioPlayAgent::SetPosition(TTimeIntervalMicroSeconds aPosition)
303 iPlayer->SetPosition(aPosition);
308 Returns the current playback balance.
311 A value between KMMFBalanceMaxLeft
312 and KMMFBalanceMaxRight.
314 @return An error code indicating if the function call was successful. KErrNone on success, otherwise
315 another of the system-wide error codes.
317 EXPORT_C TInt CMVSAudioPlayAgent::GetBalance(TInt& aBalance)
319 return iPlayer->GetBalance(aBalance);
324 Sets the current playback balance.
327 A value between KMMFBalanceMaxLeft
328 and KMMFBalanceMaxRight. The default value is
331 @return "TInt" An error code indicating if the function call was successful. KErrNone on success, otherwise
332 another of the system-wide error codes.
334 EXPORT_C TInt CMVSAudioPlayAgent::SetBalance(TInt aBalance)
336 return iPlayer->SetBalance(aBalance);
341 Sets the number of times the audio sample is to be repeated during the
344 A period of silence can follow each playing of the sample. The audio
345 sample can be repeated indefinitely.
348 The number of times the audio sample, together with
349 the trailing silence, is to be repeated. If this is
350 set to KMdaRepeatForever, then the audio
351 sample, together with the trailing silence, is
352 repeated indefinitely or until Stop() is
353 called. If this is set to zero, then the audio sample
356 The time interval of the training silence.
358 EXPORT_C void CMVSAudioPlayAgent::SetRepeats(TInt aNoRepeats, TTimeIntervalMicroSeconds aDelay)
360 iPlayer->SetRepeats(aNoRepeats, aDelay);
365 Set the current playback window
368 Start time of playback window relative to start of file
370 End time of playback window relative to start of file
372 @return "TInt" One of the global error codes
374 EXPORT_C TInt CMVSAudioPlayAgent::SetPlayWindow(TTimeIntervalMicroSeconds aStart, TTimeIntervalMicroSeconds aEnd)
376 return iPlayer->SetPlayWindow(aStart,aEnd);
381 Clear the current playback window
383 @return "TInt" One of the global error codes
385 EXPORT_C TInt CMVSAudioPlayAgent::ClearPlayWindow()
387 return iPlayer->ClearPlayWindow();
392 Sets the priority for playback. This is used to arbitrate between multiple
393 objects trying to access a single sound device.
396 The priority level to apply, EMdaPriorityMin client can be interrupted by any
397 other client, EMdaPriorityNormal client can only be interrupted by a client
398 with a higher priority or EMdaPriorityMax client cannot be interrupted by other
401 The quality/time preferences to apply.
403 @return An error code indicating if the function call was successful. KErrNone on success, otherwise
404 another of the system-wide error codes.
406 EXPORT_C TInt CMVSAudioPlayAgent::SetPriority(TInt aPriority, TMdaPriorityPreference aPreference)
408 return iPlayer->SetPriority(aPriority,aPreference);
413 Closes the current audio clip (allowing another clip to be opened)
414 Sets the current state to ENotReady
416 EXPORT_C void CMVSAudioPlayAgent::Reset()
420 iObserver.UpdateStateChange(ENotReady, KErrNone);
424 EXPORT_C void CMVSAudioPlayAgent::SetAutoPauseResume(TBool /*aEnable*/)
430 Returns an array containing the MetaDataEntry for the given audio clip
435 @leave Leaves with KErrNotFound if the meta data entry does not exist or
436 KErrNotSupported if the controller does not support meta data
437 information for this format. Other errors indicate more general system
440 EXPORT_C void CMVSAudioPlayAgent::GetMetaArrayL(RPointerArray<CMMFMetaDataEntry>& aMetaArray)
442 //Reset the meta array
444 //Find how many elements there are to obtain
445 TInt noMetaEntries = 0;
446 TInt err = iPlayer->GetNumberOfMetaDataEntries(noMetaEntries);
449 //Add the elements, one at a time.
450 for(TInt counter = 0; counter < noMetaEntries; ++counter)
452 aMetaArray.Append(iPlayer->GetMetaDataEntryL(counter));
455 User::LeaveIfError(err);
460 Returns the bit rate of the audio clip.
463 Bit rate of the audio clip.
465 @return One of the global error codes.
467 EXPORT_C TInt CMVSAudioPlayAgent::GetBitRate(TUint& aBitRate)
469 return iPlayer->GetBitRate(aBitRate);
474 Returns the controller implementation information associated with the current controller.
476 @return The controller implementation structure
478 EXPORT_C const CMMFControllerImplementationInformation& CMVSAudioPlayAgent::GetControllerInfoL()
480 return iPlayer->ControllerImplementationInformationL();
485 Returns the current state of the CMVSAudioPlayAgent.
487 @return The current state, iState.
489 EXPORT_C TMVSState CMVSAudioPlayAgent::GetState()