mmlibs/mmfw/tsrc/mmvalidationsuite/mmvalidationsuiteagents/src/audioplayagent.cpp
changeset 0 b8ed18f6c07b
equal deleted inserted replaced
-1:000000000000 0:b8ed18f6c07b
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Part of the MVS Agents for TechView
       
    15 //
       
    16 
       
    17 #include "audioplayagent.h"
       
    18 #include <e32def.h>
       
    19 #include <flogger.h>
       
    20 
       
    21 
       
    22 /**
       
    23 Constructs and initialises a new instance of the MVS audio player utility.
       
    24 
       
    25 The function leaves if the MVS audio player utility object cannot be created.
       
    26 
       
    27 No callback notification is made upon completion of NewL().
       
    28 
       
    29 @param  aObserver
       
    30 		Class to receive state change events from play agent.
       
    31 
       
    32 @return     A pointer to the new MVS audio player utility object.
       
    33 */
       
    34 
       
    35 EXPORT_C CMVSAudioPlayAgent* CMVSAudioPlayAgent::NewL(MMVSClientObserver& aObserver)
       
    36      {
       
    37      CMVSAudioPlayAgent* self = new(ELeave) CMVSAudioPlayAgent(aObserver);
       
    38      CleanupStack::PushL(self);
       
    39      self->ConstructL();
       
    40      CleanupStack::Pop(self);
       
    41      return self;
       
    42      }
       
    43 
       
    44 
       
    45 void CMVSAudioPlayAgent::ConstructL()
       
    46      {
       
    47      iPlayer = CMdaAudioPlayerUtility::NewL(*this);
       
    48      User::LeaveIfError(iFileLogger.Connect());
       
    49      iFileLogger.CreateLog(_L("LogMVSappUi"),_L("LogFile.txt"),EFileLoggingModeAppend);
       
    50      }
       
    51 
       
    52 
       
    53 EXPORT_C CMVSAudioPlayAgent::~CMVSAudioPlayAgent()
       
    54      {
       
    55      delete iPlayer;
       
    56      if(iFileLogger.Handle())
       
    57      	{
       
    58      	iFileLogger.CloseLog();
       
    59 	 	iFileLogger.Close();
       
    60      	}
       
    61      }
       
    62 
       
    63 
       
    64 CMVSAudioPlayAgent::CMVSAudioPlayAgent(MMVSClientObserver& aObserver):iObserver(aObserver)
       
    65      {
       
    66      iObserver.UpdateStateChange(ENotReady, KErrNone);
       
    67      }
       
    68 
       
    69 EXPORT_C void CMVSAudioPlayAgent::OpenFileL(TDesC& aFile)
       
    70      {
       
    71      iPlayer->Close();//Close any existing clip
       
    72      iState = EAudioOpening;
       
    73      iObserver.UpdateStateChange(EAudioOpening, KErrNone);
       
    74      iPlayer->OpenFileL(aFile);
       
    75      }
       
    76 
       
    77 EXPORT_C void CMVSAudioPlayAgent::OpenFileL(TMMSource& /*aSource*/)
       
    78      {
       
    79      
       
    80      }
       
    81 
       
    82 /**
       
    83 Begins playback of the initialised audio sample at the current volume
       
    84 and priority levels.
       
    85 
       
    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. 
       
    91 */
       
    92 EXPORT_C void CMVSAudioPlayAgent::Play()
       
    93      {
       
    94      //must be in open or paused states 
       
    95      if((iState == EAudioOpened)||(iState == EAudioPaused)||(iState == EAudioStopped))
       
    96      	{
       
    97      	iPlayer->Play();
       
    98      	iState = EAudioPlaying;
       
    99      	iObserver.UpdateStateChange(EAudioPlaying, KErrNone);	
       
   100      	}
       
   101      }
       
   102 
       
   103 
       
   104 /**
       
   105 Pauses the playback of the audio clip.
       
   106 and updates the current state to EAudioPaused.
       
   107 */
       
   108 EXPORT_C TInt CMVSAudioPlayAgent::Pause()
       
   109      {
       
   110      if(iState == EAudioPlaying)
       
   111      	{
       
   112      	TInt err = iPlayer->Pause();
       
   113      	if ( err != KErrNone)
       
   114      		{
       
   115      		return err;
       
   116      		}
       
   117      	iState = EAudioPaused;
       
   118      	iObserver.UpdateStateChange(EAudioPaused, KErrNone);
       
   119      	}
       
   120      return KErrNone;	
       
   121      }
       
   122 
       
   123 
       
   124 /**
       
   125 Stops playback of the audio sample as soon as possible.
       
   126 
       
   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.  
       
   131 */
       
   132 EXPORT_C void CMVSAudioPlayAgent::Stop()
       
   133 	{
       
   134     if(iState == EAudioPlaying || iState == EAudioPaused)
       
   135     	{
       
   136      	iPlayer->Stop();
       
   137      	iState = EAudioStopped;
       
   138      	iObserver.UpdateStateChange(iState, KErrNone);	
       
   139      	}
       
   140     }     
       
   141 
       
   142 /**
       
   143 Added for future implimentation. Currently not supported
       
   144 */
       
   145 EXPORT_C void CMVSAudioPlayAgent::Forward()
       
   146     {
       
   147     // future implementation	
       
   148     }  
       
   149      
       
   150 
       
   151 /**
       
   152 Added for future implimentation. Currently not supported
       
   153 */
       
   154 EXPORT_C void CMVSAudioPlayAgent::Rewind()
       
   155     {
       
   156     // future implementation
       
   157     }  
       
   158 
       
   159      
       
   160 /*
       
   161 Initialisation completion callback for the MVS play agent
       
   162 */
       
   163 void CMVSAudioPlayAgent::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
       
   164     {
       
   165     if(aError == KErrNone)
       
   166     	{
       
   167     	iState = EAudioOpened;
       
   168      	iFileLogger.Write(_L("Audio Opened ")) ;
       
   169        	}
       
   170     else
       
   171      	{
       
   172      	iState = ENotReady; //init failed so from opening to NotReady
       
   173      	iFileLogger.Write(_L("MapcInitComplete: Audio Not Ready")) ;
       
   174      	}
       
   175     iObserver.UpdateStateChange(iState, aError);
       
   176     }
       
   177 
       
   178 
       
   179 /*
       
   180 Play back completion callback for the MVS play agent
       
   181 */
       
   182 void CMVSAudioPlayAgent::MapcPlayComplete(TInt aError)
       
   183 	{
       
   184 	if(aError == KErrNone)
       
   185 		{
       
   186 		iState = EAudioOpened;
       
   187 		iFileLogger.Write(_L("MapcPlayComplete:Audio Opened Play Complete")) ;
       
   188 		}
       
   189 	
       
   190 	iObserver.UpdateStateChange(iState, aError);
       
   191 	}
       
   192 
       
   193 void CMVSAudioPlayAgent::MarncResourceAvailable(TUid /*aNotificationEventId*/, const TDesC8& /*aNotificationData*/)
       
   194 	{
       
   195 	}
       
   196 
       
   197 
       
   198 /**
       
   199 Returns the current playback volume
       
   200 
       
   201 @param aVolume
       
   202        A volume value between 0 and the value returned by MaxVolume().
       
   203 
       
   204 @return One of the global error codes.
       
   205 */
       
   206 EXPORT_C TInt CMVSAudioPlayAgent::GetVolume(TInt& aVolume) 
       
   207     {
       
   208     return iPlayer->GetVolume(aVolume);
       
   209     }
       
   210 
       
   211 
       
   212 /**
       
   213 Returns an integer representing the maximum volume.
       
   214 
       
   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.
       
   218 
       
   219 The function raises a CMdaAudioPlayerUtility 1 panic if the 
       
   220 audio player utility is not initialised.
       
   221 
       
   222 @return The maximum volume setting.
       
   223 */
       
   224 EXPORT_C TInt CMVSAudioPlayAgent::MaxVolume() 
       
   225     {
       
   226     return iPlayer->MaxVolume();
       
   227     }
       
   228     
       
   229 
       
   230 /**
       
   231 Returns the duration of the audio sample.
       
   232 
       
   233 The function raises a CMdaAudioPlayerUtility 1 panic if the audio
       
   234 player utility is not initialised.
       
   235 
       
   236 @return The duration in microseconds.
       
   237 */  
       
   238 EXPORT_C TTimeIntervalMicroSeconds CMVSAudioPlayAgent::Duration() 
       
   239     {
       
   240     return iPlayer->Duration();
       
   241     }
       
   242      
       
   243 
       
   244 /**
       
   245 Changes the current playback volume to a specified value.
       
   246 
       
   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.
       
   252 
       
   253 
       
   254 The function raises a CMdaAudioPlayerUtility 1 panic if
       
   255 the audio player utility is not initialised.
       
   256 
       
   257 @param  aVolume
       
   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.
       
   263 
       
   264 @param  aRampDuration
       
   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
       
   270         volume level.
       
   271 
       
   272 */
       
   273 EXPORT_C void CMVSAudioPlayAgent::SetVolume(TInt aVolume, TTimeIntervalMicroSeconds aRamp)
       
   274     {
       
   275     iPlayer->SetVolume(aVolume);
       
   276     iPlayer->SetVolumeRamp(aRamp);
       
   277     }
       
   278 
       
   279 
       
   280 /**
       
   281 Returns the current playback position in microseconds from the start of the clip.
       
   282 
       
   283 @param   aPosition
       
   284          The current time position in microseconds from the start of the clip to the current
       
   285          play position.
       
   286 
       
   287 @return the current playback position in microseconds.
       
   288 */    
       
   289 EXPORT_C TTimeIntervalMicroSeconds CMVSAudioPlayAgent::GetPosition(TTimeIntervalMicroSeconds& aPosition) 
       
   290     {
       
   291     return iPlayer->GetPosition(aPosition);
       
   292     }
       
   293      
       
   294      
       
   295 /**
       
   296 Sets the current playback position in microseconds from the start of the clip.
       
   297 
       
   298 @param  aPosition
       
   299         The position to move to in microseconds from the start of the clip.
       
   300 */
       
   301 EXPORT_C void CMVSAudioPlayAgent::SetPosition(TTimeIntervalMicroSeconds aPosition)
       
   302     {
       
   303     iPlayer->SetPosition(aPosition);
       
   304     }
       
   305     
       
   306 
       
   307 /**
       
   308 Returns the current playback balance.
       
   309 
       
   310 @param  aBalance
       
   311         A value between KMMFBalanceMaxLeft
       
   312         and KMMFBalanceMaxRight.
       
   313 
       
   314 @return An error code indicating if the function call was successful. KErrNone on success, otherwise
       
   315         another of the system-wide error codes.
       
   316 */
       
   317 EXPORT_C TInt CMVSAudioPlayAgent::GetBalance(TInt& aBalance) 
       
   318     {
       
   319     return iPlayer->GetBalance(aBalance);
       
   320     }
       
   321 
       
   322 
       
   323 /**
       
   324 Sets the current playback balance.
       
   325 
       
   326 @param  aBalance
       
   327         A value between KMMFBalanceMaxLeft
       
   328         and KMMFBalanceMaxRight. The default value is
       
   329         KMMFBalanceCenter.
       
   330 
       
   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.
       
   333 */
       
   334 EXPORT_C TInt CMVSAudioPlayAgent::SetBalance(TInt aBalance)
       
   335     {
       
   336     return iPlayer->SetBalance(aBalance);
       
   337     }
       
   338 
       
   339 
       
   340 /**
       
   341 Sets the number of times the audio sample is to be repeated during the
       
   342 playback operation.
       
   343 
       
   344 A period of silence can follow each playing of the sample. The audio
       
   345 sample can be repeated indefinitely.
       
   346 
       
   347 @param  aNoRepeats
       
   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
       
   354         is not repeated.
       
   355 @param  aDelay
       
   356         The time interval of the training silence.
       
   357 */
       
   358 EXPORT_C void CMVSAudioPlayAgent::SetRepeats(TInt aNoRepeats, TTimeIntervalMicroSeconds aDelay)
       
   359     {
       
   360     iPlayer->SetRepeats(aNoRepeats, aDelay);
       
   361     }
       
   362 
       
   363 
       
   364 /**
       
   365 Set the current playback window
       
   366 
       
   367 @param	aStart
       
   368 		Start time of playback window relative to start of file
       
   369 @param	aEnd
       
   370 		End time of playback window relative to start of file
       
   371 
       
   372 @return "TInt" One of the global error codes
       
   373 */
       
   374 EXPORT_C TInt CMVSAudioPlayAgent::SetPlayWindow(TTimeIntervalMicroSeconds aStart, TTimeIntervalMicroSeconds aEnd)
       
   375     {
       
   376     return iPlayer->SetPlayWindow(aStart,aEnd);
       
   377     }
       
   378 
       
   379 
       
   380 /**
       
   381 Clear the current playback window
       
   382 
       
   383 @return "TInt" One of the global error codes
       
   384 */   
       
   385 EXPORT_C TInt CMVSAudioPlayAgent::ClearPlayWindow()
       
   386     {
       
   387     return iPlayer->ClearPlayWindow();
       
   388     }     
       
   389 
       
   390 
       
   391 /**
       
   392 Sets the priority for playback. This is used to arbitrate between multiple
       
   393 objects trying to access a single sound device.
       
   394 
       
   395 @param  aPriority
       
   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 
       
   399         clients.
       
   400 @param  aPreference
       
   401         The quality/time preferences to apply.
       
   402 
       
   403 @return An error code indicating if the function call was successful. KErrNone on success, otherwise
       
   404         another of the system-wide error codes.
       
   405 */
       
   406 EXPORT_C TInt CMVSAudioPlayAgent::SetPriority(TInt aPriority, TMdaPriorityPreference aPreference)
       
   407     {
       
   408     return iPlayer->SetPriority(aPriority,aPreference);
       
   409     }
       
   410 
       
   411 
       
   412 /**
       
   413 Closes the current audio clip (allowing another clip to be opened)
       
   414 Sets the current state to ENotReady
       
   415 */  
       
   416 EXPORT_C void CMVSAudioPlayAgent::Reset()
       
   417     {
       
   418     iPlayer->Close();
       
   419     iState = ENotReady;
       
   420     iObserver.UpdateStateChange(ENotReady, KErrNone);
       
   421     }
       
   422 
       
   423      
       
   424 EXPORT_C void CMVSAudioPlayAgent::SetAutoPauseResume(TBool /*aEnable*/)
       
   425     {
       
   426     }
       
   427 
       
   428 
       
   429 /**
       
   430 Returns an array containing the MetaDataEntry for the given audio clip
       
   431 
       
   432 @param  aMetaArray
       
   433         The meta data Array
       
   434 
       
   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
       
   438 		failure.
       
   439 */
       
   440 EXPORT_C void CMVSAudioPlayAgent::GetMetaArrayL(RPointerArray<CMMFMetaDataEntry>& aMetaArray)
       
   441 	{
       
   442 	//Reset the meta array
       
   443     aMetaArray.Reset();
       
   444 	//Find how many elements there are to obtain
       
   445 	TInt noMetaEntries = 0;
       
   446     TInt err = iPlayer->GetNumberOfMetaDataEntries(noMetaEntries);
       
   447     if(err == KErrNone)
       
   448 	    {
       
   449 	    //Add the elements, one at a time.
       
   450 	    for(TInt counter = 0; counter < noMetaEntries; ++counter)
       
   451 	         {
       
   452 	         aMetaArray.Append(iPlayer->GetMetaDataEntryL(counter));
       
   453 	         }	
       
   454 	    }
       
   455 	User::LeaveIfError(err);	
       
   456 	}
       
   457      
       
   458 	
       
   459 /**
       
   460 Returns the bit rate of the audio clip.
       
   461 
       
   462 @param  aBitRate
       
   463         Bit rate of the audio clip.
       
   464 
       
   465 @return One of the global error codes.
       
   466 */
       
   467 EXPORT_C TInt CMVSAudioPlayAgent::GetBitRate(TUint& aBitRate)
       
   468 	{
       
   469 	return iPlayer->GetBitRate(aBitRate);
       
   470 	}
       
   471 
       
   472 
       
   473 /**
       
   474 Returns the controller implementation information associated with the current controller.
       
   475 
       
   476 @return The controller implementation structure
       
   477 */
       
   478 EXPORT_C const CMMFControllerImplementationInformation& CMVSAudioPlayAgent::GetControllerInfoL()
       
   479 	{
       
   480 	return iPlayer->ControllerImplementationInformationL();	
       
   481 	}
       
   482 
       
   483 
       
   484 /**
       
   485 Returns the current state of the CMVSAudioPlayAgent.
       
   486 
       
   487 @return The current state, iState.
       
   488 */
       
   489 EXPORT_C TMVSState CMVSAudioPlayAgent::GetState()
       
   490 	{
       
   491 	return iState;	
       
   492 	}