sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Part of the MVS Agents for TechView sl@0: // sl@0: sl@0: #include "audioplayagent.h" sl@0: #include sl@0: #include sl@0: sl@0: sl@0: /** sl@0: Constructs and initialises a new instance of the MVS audio player utility. sl@0: sl@0: The function leaves if the MVS audio player utility object cannot be created. sl@0: sl@0: No callback notification is made upon completion of NewL(). sl@0: sl@0: @param aObserver sl@0: Class to receive state change events from play agent. sl@0: sl@0: @return A pointer to the new MVS audio player utility object. sl@0: */ sl@0: sl@0: EXPORT_C CMVSAudioPlayAgent* CMVSAudioPlayAgent::NewL(MMVSClientObserver& aObserver) sl@0: { sl@0: CMVSAudioPlayAgent* self = new(ELeave) CMVSAudioPlayAgent(aObserver); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: void CMVSAudioPlayAgent::ConstructL() sl@0: { sl@0: iPlayer = CMdaAudioPlayerUtility::NewL(*this); sl@0: User::LeaveIfError(iFileLogger.Connect()); sl@0: iFileLogger.CreateLog(_L("LogMVSappUi"),_L("LogFile.txt"),EFileLoggingModeAppend); sl@0: } sl@0: sl@0: sl@0: EXPORT_C CMVSAudioPlayAgent::~CMVSAudioPlayAgent() sl@0: { sl@0: delete iPlayer; sl@0: if(iFileLogger.Handle()) sl@0: { sl@0: iFileLogger.CloseLog(); sl@0: iFileLogger.Close(); sl@0: } sl@0: } sl@0: sl@0: sl@0: CMVSAudioPlayAgent::CMVSAudioPlayAgent(MMVSClientObserver& aObserver):iObserver(aObserver) sl@0: { sl@0: iObserver.UpdateStateChange(ENotReady, KErrNone); sl@0: } sl@0: sl@0: EXPORT_C void CMVSAudioPlayAgent::OpenFileL(TDesC& aFile) sl@0: { sl@0: iPlayer->Close();//Close any existing clip sl@0: iState = EAudioOpening; sl@0: iObserver.UpdateStateChange(EAudioOpening, KErrNone); sl@0: iPlayer->OpenFileL(aFile); sl@0: } sl@0: sl@0: EXPORT_C void CMVSAudioPlayAgent::OpenFileL(TMMSource& /*aSource*/) sl@0: { sl@0: sl@0: } sl@0: sl@0: /** sl@0: Begins playback of the initialised audio sample at the current volume sl@0: and priority levels. sl@0: sl@0: Sets the current state of the system to EAudioPlaying sl@0: When playing of the audio sample is complete, successfully or sl@0: otherwise, the callback function sl@0: CMVSAudioPlayAgent::MapcPlayComplete() is called, which inturn sl@0: sets the state to EAudioOpened. sl@0: */ sl@0: EXPORT_C void CMVSAudioPlayAgent::Play() sl@0: { sl@0: //must be in open or paused states sl@0: if((iState == EAudioOpened)||(iState == EAudioPaused)||(iState == EAudioStopped)) sl@0: { sl@0: iPlayer->Play(); sl@0: iState = EAudioPlaying; sl@0: iObserver.UpdateStateChange(EAudioPlaying, KErrNone); sl@0: } sl@0: } sl@0: sl@0: sl@0: /** sl@0: Pauses the playback of the audio clip. sl@0: and updates the current state to EAudioPaused. sl@0: */ sl@0: EXPORT_C TInt CMVSAudioPlayAgent::Pause() sl@0: { sl@0: if(iState == EAudioPlaying) sl@0: { sl@0: TInt err = iPlayer->Pause(); sl@0: if ( err != KErrNone) sl@0: { sl@0: return err; sl@0: } sl@0: iState = EAudioPaused; sl@0: iObserver.UpdateStateChange(EAudioPaused, KErrNone); sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: /** sl@0: Stops playback of the audio sample as soon as possible. sl@0: sl@0: Sets the current state to EAudioStopped sl@0: If the audio sample is playing, playback is stopped as soon as sl@0: possible. If playback is already complete, nothing further happens as sl@0: a result of calling this function. sl@0: */ sl@0: EXPORT_C void CMVSAudioPlayAgent::Stop() sl@0: { sl@0: if(iState == EAudioPlaying || iState == EAudioPaused) sl@0: { sl@0: iPlayer->Stop(); sl@0: iState = EAudioStopped; sl@0: iObserver.UpdateStateChange(iState, KErrNone); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Added for future implimentation. Currently not supported sl@0: */ sl@0: EXPORT_C void CMVSAudioPlayAgent::Forward() sl@0: { sl@0: // future implementation sl@0: } sl@0: sl@0: sl@0: /** sl@0: Added for future implimentation. Currently not supported sl@0: */ sl@0: EXPORT_C void CMVSAudioPlayAgent::Rewind() sl@0: { sl@0: // future implementation sl@0: } sl@0: sl@0: sl@0: /* sl@0: Initialisation completion callback for the MVS play agent sl@0: */ sl@0: void CMVSAudioPlayAgent::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/) sl@0: { sl@0: if(aError == KErrNone) sl@0: { sl@0: iState = EAudioOpened; sl@0: iFileLogger.Write(_L("Audio Opened ")) ; sl@0: } sl@0: else sl@0: { sl@0: iState = ENotReady; //init failed so from opening to NotReady sl@0: iFileLogger.Write(_L("MapcInitComplete: Audio Not Ready")) ; sl@0: } sl@0: iObserver.UpdateStateChange(iState, aError); sl@0: } sl@0: sl@0: sl@0: /* sl@0: Play back completion callback for the MVS play agent sl@0: */ sl@0: void CMVSAudioPlayAgent::MapcPlayComplete(TInt aError) sl@0: { sl@0: if(aError == KErrNone) sl@0: { sl@0: iState = EAudioOpened; sl@0: iFileLogger.Write(_L("MapcPlayComplete:Audio Opened Play Complete")) ; sl@0: } sl@0: sl@0: iObserver.UpdateStateChange(iState, aError); sl@0: } sl@0: sl@0: void CMVSAudioPlayAgent::MarncResourceAvailable(TUid /*aNotificationEventId*/, const TDesC8& /*aNotificationData*/) sl@0: { sl@0: } sl@0: sl@0: sl@0: /** sl@0: Returns the current playback volume sl@0: sl@0: @param aVolume sl@0: A volume value between 0 and the value returned by MaxVolume(). sl@0: sl@0: @return One of the global error codes. sl@0: */ sl@0: EXPORT_C TInt CMVSAudioPlayAgent::GetVolume(TInt& aVolume) sl@0: { sl@0: return iPlayer->GetVolume(aVolume); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Returns an integer representing the maximum volume. sl@0: sl@0: This is the maximum value which can be passed to sl@0: CMdaAudioPlayerUtility::SetVolume(). This value is platform sl@0: independent, but is always greater than or equal to one. sl@0: sl@0: The function raises a CMdaAudioPlayerUtility 1 panic if the sl@0: audio player utility is not initialised. sl@0: sl@0: @return The maximum volume setting. sl@0: */ sl@0: EXPORT_C TInt CMVSAudioPlayAgent::MaxVolume() sl@0: { sl@0: return iPlayer->MaxVolume(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Returns the duration of the audio sample. sl@0: sl@0: The function raises a CMdaAudioPlayerUtility 1 panic if the audio sl@0: player utility is not initialised. sl@0: sl@0: @return The duration in microseconds. sl@0: */ sl@0: EXPORT_C TTimeIntervalMicroSeconds CMVSAudioPlayAgent::Duration() sl@0: { sl@0: return iPlayer->Duration(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Changes the current playback volume to a specified value. sl@0: sl@0: The volume can be changed before or during playback and is effective sl@0: immediately. The volume can be set to any value between zero (mute) and sl@0: the maximum permissible volume (determined using MaxVolume()).Also the sl@0: period over which the volume level is to rise smoothly from nothing to sl@0: the normal volume level,is given by the ramp up time. sl@0: sl@0: sl@0: The function raises a CMdaAudioPlayerUtility 1 panic if sl@0: the audio player utility is not initialised. sl@0: sl@0: @param aVolume sl@0: The volume setting. This can be any value from zero to sl@0: the value returned by a call to sl@0: CMVSAudioPlayAgent::MaxVolume(). sl@0: Setting a zero value mutes the sound. Setting the sl@0: maximum value results in the loudest possible sound. sl@0: sl@0: @param aRampDuration sl@0: The period over which the volume is to rise. A zero sl@0: value causes the audio sample to be played at the sl@0: normal level for the full duration of the playback. A sl@0: value which is longer than the duration of the audio sl@0: sample means that the sample never reaches its normal sl@0: volume level. sl@0: sl@0: */ sl@0: EXPORT_C void CMVSAudioPlayAgent::SetVolume(TInt aVolume, TTimeIntervalMicroSeconds aRamp) sl@0: { sl@0: iPlayer->SetVolume(aVolume); sl@0: iPlayer->SetVolumeRamp(aRamp); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Returns the current playback position in microseconds from the start of the clip. sl@0: sl@0: @param aPosition sl@0: The current time position in microseconds from the start of the clip to the current sl@0: play position. sl@0: sl@0: @return the current playback position in microseconds. sl@0: */ sl@0: EXPORT_C TTimeIntervalMicroSeconds CMVSAudioPlayAgent::GetPosition(TTimeIntervalMicroSeconds& aPosition) sl@0: { sl@0: return iPlayer->GetPosition(aPosition); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Sets the current playback position in microseconds from the start of the clip. sl@0: sl@0: @param aPosition sl@0: The position to move to in microseconds from the start of the clip. sl@0: */ sl@0: EXPORT_C void CMVSAudioPlayAgent::SetPosition(TTimeIntervalMicroSeconds aPosition) sl@0: { sl@0: iPlayer->SetPosition(aPosition); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Returns the current playback balance. sl@0: sl@0: @param aBalance sl@0: A value between KMMFBalanceMaxLeft sl@0: and KMMFBalanceMaxRight. sl@0: sl@0: @return An error code indicating if the function call was successful. KErrNone on success, otherwise sl@0: another of the system-wide error codes. sl@0: */ sl@0: EXPORT_C TInt CMVSAudioPlayAgent::GetBalance(TInt& aBalance) sl@0: { sl@0: return iPlayer->GetBalance(aBalance); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Sets the current playback balance. sl@0: sl@0: @param aBalance sl@0: A value between KMMFBalanceMaxLeft sl@0: and KMMFBalanceMaxRight. The default value is sl@0: KMMFBalanceCenter. sl@0: sl@0: @return "TInt" An error code indicating if the function call was successful. KErrNone on success, otherwise sl@0: another of the system-wide error codes. sl@0: */ sl@0: EXPORT_C TInt CMVSAudioPlayAgent::SetBalance(TInt aBalance) sl@0: { sl@0: return iPlayer->SetBalance(aBalance); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Sets the number of times the audio sample is to be repeated during the sl@0: playback operation. sl@0: sl@0: A period of silence can follow each playing of the sample. The audio sl@0: sample can be repeated indefinitely. sl@0: sl@0: @param aNoRepeats sl@0: The number of times the audio sample, together with sl@0: the trailing silence, is to be repeated. If this is sl@0: set to KMdaRepeatForever, then the audio sl@0: sample, together with the trailing silence, is sl@0: repeated indefinitely or until Stop() is sl@0: called. If this is set to zero, then the audio sample sl@0: is not repeated. sl@0: @param aDelay sl@0: The time interval of the training silence. sl@0: */ sl@0: EXPORT_C void CMVSAudioPlayAgent::SetRepeats(TInt aNoRepeats, TTimeIntervalMicroSeconds aDelay) sl@0: { sl@0: iPlayer->SetRepeats(aNoRepeats, aDelay); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Set the current playback window sl@0: sl@0: @param aStart sl@0: Start time of playback window relative to start of file sl@0: @param aEnd sl@0: End time of playback window relative to start of file sl@0: sl@0: @return "TInt" One of the global error codes sl@0: */ sl@0: EXPORT_C TInt CMVSAudioPlayAgent::SetPlayWindow(TTimeIntervalMicroSeconds aStart, TTimeIntervalMicroSeconds aEnd) sl@0: { sl@0: return iPlayer->SetPlayWindow(aStart,aEnd); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Clear the current playback window sl@0: sl@0: @return "TInt" One of the global error codes sl@0: */ sl@0: EXPORT_C TInt CMVSAudioPlayAgent::ClearPlayWindow() sl@0: { sl@0: return iPlayer->ClearPlayWindow(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Sets the priority for playback. This is used to arbitrate between multiple sl@0: objects trying to access a single sound device. sl@0: sl@0: @param aPriority sl@0: The priority level to apply, EMdaPriorityMin client can be interrupted by any sl@0: other client, EMdaPriorityNormal client can only be interrupted by a client sl@0: with a higher priority or EMdaPriorityMax client cannot be interrupted by other sl@0: clients. sl@0: @param aPreference sl@0: The quality/time preferences to apply. sl@0: sl@0: @return An error code indicating if the function call was successful. KErrNone on success, otherwise sl@0: another of the system-wide error codes. sl@0: */ sl@0: EXPORT_C TInt CMVSAudioPlayAgent::SetPriority(TInt aPriority, TMdaPriorityPreference aPreference) sl@0: { sl@0: return iPlayer->SetPriority(aPriority,aPreference); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Closes the current audio clip (allowing another clip to be opened) sl@0: Sets the current state to ENotReady sl@0: */ sl@0: EXPORT_C void CMVSAudioPlayAgent::Reset() sl@0: { sl@0: iPlayer->Close(); sl@0: iState = ENotReady; sl@0: iObserver.UpdateStateChange(ENotReady, KErrNone); sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CMVSAudioPlayAgent::SetAutoPauseResume(TBool /*aEnable*/) sl@0: { sl@0: } sl@0: sl@0: sl@0: /** sl@0: Returns an array containing the MetaDataEntry for the given audio clip sl@0: sl@0: @param aMetaArray sl@0: The meta data Array sl@0: sl@0: @leave Leaves with KErrNotFound if the meta data entry does not exist or sl@0: KErrNotSupported if the controller does not support meta data sl@0: information for this format. Other errors indicate more general system sl@0: failure. sl@0: */ sl@0: EXPORT_C void CMVSAudioPlayAgent::GetMetaArrayL(RPointerArray& aMetaArray) sl@0: { sl@0: //Reset the meta array sl@0: aMetaArray.Reset(); sl@0: //Find how many elements there are to obtain sl@0: TInt noMetaEntries = 0; sl@0: TInt err = iPlayer->GetNumberOfMetaDataEntries(noMetaEntries); sl@0: if(err == KErrNone) sl@0: { sl@0: //Add the elements, one at a time. sl@0: for(TInt counter = 0; counter < noMetaEntries; ++counter) sl@0: { sl@0: aMetaArray.Append(iPlayer->GetMetaDataEntryL(counter)); sl@0: } sl@0: } sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Returns the bit rate of the audio clip. sl@0: sl@0: @param aBitRate sl@0: Bit rate of the audio clip. sl@0: sl@0: @return One of the global error codes. sl@0: */ sl@0: EXPORT_C TInt CMVSAudioPlayAgent::GetBitRate(TUint& aBitRate) sl@0: { sl@0: return iPlayer->GetBitRate(aBitRate); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Returns the controller implementation information associated with the current controller. sl@0: sl@0: @return The controller implementation structure sl@0: */ sl@0: EXPORT_C const CMMFControllerImplementationInformation& CMVSAudioPlayAgent::GetControllerInfoL() sl@0: { sl@0: return iPlayer->ControllerImplementationInformationL(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Returns the current state of the CMVSAudioPlayAgent. sl@0: sl@0: @return The current state, iState. sl@0: */ sl@0: EXPORT_C TMVSState CMVSAudioPlayAgent::GetState() sl@0: { sl@0: return iState; sl@0: }