svgtopt/SVG/SVGImpl/src/SVGAudioElementImpl.cpp
changeset 46 88edb906c587
equal deleted inserted replaced
-1:000000000000 46:88edb906c587
       
     1 /*
       
     2 * Copyright (c) 2005 - 2006 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:  SVG Implementation source file
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #if !defined(__E32BASE_H__)
       
    21 #include <e32base.h>
       
    22 #endif
       
    23 
       
    24 #include <AudioPreference.h> // For priority/pref values
       
    25 
       
    26 #include "SVGAudioElementImpl.h"
       
    27 #include "SVGDocumentImpl.h"
       
    28 #include "SVGEngineImpl.h"
       
    29 #include "SVGSchemaData.h"
       
    30 #include "SVGTimeContainer.h"
       
    31 
       
    32 _LIT(KAudioAMR, "audio/amr");
       
    33 _LIT(KAudioAWB, "audio/amr-wb");
       
    34 _LIT(KAudioMP3, "audio/mpeg");
       
    35 _LIT(KAudioMP4, "audio/mp4");
       
    36 _LIT(KAudio3GP, "audio/3gp");
       
    37 _LIT(KAudio3G2, "audio/3g2");
       
    38 _LIT(KAudioAAC, "audio/aac");
       
    39 _LIT(KAudioMID, "audio/midi");
       
    40 _LIT(KAudioMID2, "audio/sp-midi");
       
    41 _LIT(KAudioRMF, "audio/rmf");
       
    42 _LIT(KAudioRMF2, "audio/x-rmf");
       
    43 _LIT(KAudioRMF3, "audio/x-beatnik-rmf");
       
    44 _LIT(KAudioMXMF, "audio/mobile-xmf");
       
    45 _LIT(KAudioWMA, "audio/x-ms-wma");
       
    46 _LIT(KAttrAudioType,  "type" );
       
    47 _LIT(KXlinkHref,  "xlink:href" );
       
    48 _LIT(KDur,"dur");
       
    49 _LIT(KMedia,"media");
       
    50 _LIT(KAudioLevelStr,  "audio-level");
       
    51 _LIT(KVolumeStr,  "volume");
       
    52 
       
    53 // audio-level property by default is  100%
       
    54 const TInt KAudioLevelDefaultPercent = 100;
       
    55 const  TInt KMillisecondsPerMicrosecond = 1000;
       
    56 // ---------------------------------------------------------------------------
       
    57 // Create new element of audioelementimpl
       
    58 // ---------------------------------------------------------------------------
       
    59 CSvgAudioElementImpl* CSvgAudioElementImpl::NewL(  const TUint8 aElemID,
       
    60                                                   CSvgDocumentImpl* aDoc )
       
    61     {
       
    62     CSvgAudioElementImpl*   self    = new ( ELeave )
       
    63                                       CSvgAudioElementImpl( aDoc );
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL(  aElemID, aDoc );
       
    66     CleanupStack::Pop();
       
    67     return self;
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // Create new element of audioelementimpl
       
    72 // ---------------------------------------------------------------------------
       
    73 CSvgAudioElementImpl* CSvgAudioElementImpl::NewLC(  const TUint8 aElemID,
       
    74                                                    CSvgDocumentImpl* aDoc )
       
    75     {
       
    76     CSvgAudioElementImpl*   self    = new ( ELeave )
       
    77                                       CSvgAudioElementImpl( aDoc );
       
    78     CleanupStack::PushL( self );
       
    79     self->ConstructL(  aElemID,aDoc );
       
    80     return self;
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // Create new element of audioelementimpl
       
    85 // ---------------------------------------------------------------------------
       
    86 void CSvgAudioElementImpl::ConstructL(  const TUint8 aElemID,
       
    87                                        CSvgDocumentImpl* /* aDoc */ )
       
    88     {
       
    89     iPercentLevelVolume = KAudioLevelDefaultPercent;
       
    90 	CSvgMediaElementBase::ConstructL( aElemID );
       
    91 	iStoredPos = 0;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // Destructor for Audioelement
       
    96 // ---------------------------------------------------------------------------
       
    97 CSvgAudioElementImpl::~CSvgAudioElementImpl()
       
    98     {
       
    99 	if ( iAudioPlayer )
       
   100         {
       
   101         iAudioPlayer->Stop();
       
   102    	    delete iAudioPlayer;
       
   103    	    iAudioPlayer = NULL;
       
   104         }
       
   105     if( iUri)
       
   106         {
       
   107         delete iUri;
       
   108         iUri= NULL;
       
   109         }
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // Sets attributes of audio element
       
   114 // ---------------------------------------------------------------------------
       
   115 TInt CSvgAudioElementImpl::SetAttributeL( const TDesC& aName,
       
   116                                           const TDesC& aValue )
       
   117     {
       
   118     if (!iTargetSet)
       
   119         {
       
   120 	    iTargetElement = ( CSvgElementImpl * ) ParentNode();// default is parent element
       
   121 		if (iTargetElement)
       
   122 			{
       
   123     	    iTargetSet = ETrue;
       
   124 			}
       
   125         }
       
   126 
       
   127     if(aName == KDur && aValue != KMedia)
       
   128         {
       
   129     	iDurMedia = EFalse;
       
   130     	
       
   131         }
       
   132     
       
   133     if( aName == KXlinkHref)
       
   134         {
       
   135         this->SetXlinkAttributeL(aName,aValue);
       
   136         iUri = aValue.AllocL();        
       
   137         }
       
   138     if ( aName == KAttrAudioType )
       
   139         {
       
   140         HBufC16* tempValue = aValue.Alloc();
       
   141         TPtr16 lowercaseValue = tempValue->Des();
       
   142         lowercaseValue.LowerCase();
       
   143 
       
   144         if ( !( (lowercaseValue == KAudioAMR) ||
       
   145             (lowercaseValue == KAudioAWB)  ||
       
   146             (lowercaseValue == KAudioMP3)  ||
       
   147             (lowercaseValue == KAudioMP4)  ||
       
   148             (lowercaseValue == KAudio3GP)  ||
       
   149             (lowercaseValue == KAudio3G2)  ||
       
   150             (lowercaseValue == KAudioAAC)  ||
       
   151             (lowercaseValue == KAudioMID)  ||
       
   152             (lowercaseValue == KAudioMID2) ||
       
   153             (lowercaseValue == KAudioRMF)  ||
       
   154             (lowercaseValue == KAudioRMF2) ||
       
   155             (lowercaseValue == KAudioRMF3) ||
       
   156             (lowercaseValue == KAudioMXMF) ||
       
   157             (lowercaseValue == KAudioWMA) ))
       
   158                 {
       
   159                 iAudioStatus = EPlayerProhibit;
       
   160                 }
       
   161         delete tempValue;
       
   162         }
       
   163     else if  (( aName ==  KAudioLevelStr)  || ( aName ==  KVolumeStr ))
       
   164         {
       
   165         TLex value  ( aValue );
       
   166         TReal32 volume;
       
   167         if( value.Val( volume, '.' ) == KErrNone)
       
   168             {
       
   169             iVolume = volume < 0 ? 0 : volume;
       
   170             iVolume = volume > 1 ? 1 : volume;
       
   171             }
       
   172         return KErrNone;
       
   173         }
       
   174     return CSvgMediaElementBase::SetAttributeL( aName, aValue );
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // Sets attributes of audio element
       
   179 // ---------------------------------------------------------------------------
       
   180 
       
   181 TInt  CSvgAudioElementImpl::SetAttributeDesL( const TInt aNameId,
       
   182 											   const TDesC& aValue )
       
   183 	{
       
   184 	return CSvgElementImpl::SetAttributeDesL( aNameId, aValue );
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // Sets attributes of audio element
       
   189 // ---------------------------------------------------------------------------
       
   190 TInt CSvgAudioElementImpl::SetAttributeFloatL( const TInt aNameId,
       
   191                                                TFloatFixPt aValue )
       
   192     {
       
   193 	return CSvgMediaElementBase::SetAttributeFloatL(aNameId,aValue);
       
   194     }
       
   195 
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // Gets attributes of audio element
       
   199 // ---------------------------------------------------------------------------
       
   200 TInt CSvgAudioElementImpl::GetAttributeFloat(const TInt aNameId,
       
   201                                                 TFloatFixPt& aValue )
       
   202     {
       
   203 	return CSvgMediaElementBase::GetAttributeFloat(aNameId,aValue);
       
   204     }
       
   205 
       
   206 
       
   207 // perform a deep clone of this object
       
   208 // ---------------------------------------------------------------------------
       
   209 // Deep Copy of the parent
       
   210 // ---------------------------------------------------------------------------
       
   211 MXmlElement* CSvgAudioElementImpl::CloneL(MXmlElement* aParentElement)
       
   212     {
       
   213     CSvgAudioElementImpl* newElement = CSvgAudioElementImpl::NewL(
       
   214         this->ElemID(), ((CSvgDocumentImpl*)iOwnerDocument) );
       
   215 
       
   216     CleanupStack::PushL(newElement);
       
   217     newElement->iParentNode = aParentElement;
       
   218     // copy everything over
       
   219     this->CopyL(newElement);
       
   220     CleanupStack::Pop();
       
   221     return newElement;
       
   222     }
       
   223 
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // From MSvgEventReceiver
       
   227 // ---------------------------------------------------------------------------
       
   228 TBool CSvgAudioElementImpl::ReceiveEventL( MSvgEvent* aEvent )
       
   229     {
       
   230     return CSvgMediaElementBase::ReceiveEventProcL( aEvent, this );
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // CSvgAudioElementImpl::InitAnimationL
       
   235 // From CSvgMediaElementBase
       
   236 // ---------------------------------------------------------------------------
       
   237 void CSvgAudioElementImpl::InitAnimationL()
       
   238     {
       
   239     CSvgMediaElementBase::InitAnimationL();
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 // CSvgAudioElementImpl::ResetAnimationL
       
   244 // From CSvgMediaElementBase
       
   245 // ---------------------------------------------------------------------------
       
   246 void CSvgAudioElementImpl::ResetAnimationL()
       
   247     {
       
   248 	if (( iAnimStatus == KAnimActive ) ||
       
   249 		( iAnimStatus == KAnimFinished) ||
       
   250 		( iAnimStatus == KAnimEnd))
       
   251 		{
       
   252 			
       
   253 		if (( iAudioStatus == EPlayerStatePlaying ) ||
       
   254 		( iAudioStatus == EPlayerStateComplete ))
       
   255     		{
       
   256     		// Save the audio start offset
       
   257             iAudioStartOffset = 
       
   258                 ( ( CSvgDocumentImpl* )iOwnerDocument)->CurrentTime();
       
   259             iStoredPos = 0;    
       
   260     		// if previously audio is still playing, and asked to play again...
       
   261         	iAudioPlayer->Stop();
       
   262             //For  Negative Begin
       
   263         	if ( iNegativeBeginTime < 0)
       
   264     	        {
       
   265     	            const TInt64 aInterval = iNegativeBeginTime * -KMillisecondsPerMicrosecond;
       
   266     	            TTimeIntervalMicroSeconds aTime(aInterval);        
       
   267     	            iAudioPlayer->SetPosition(aTime);
       
   268     	            iStoredPos = aTime;
       
   269     	        }
       
   270             //For  Negative Begin
       
   271 
       
   272         	iAudioPlayer->Play();
       
   273         	iAudioStatus = EPlayerStatePlaying;
       
   274     		}
       
   275 		}
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // CSvgAudioElementImpl::Reset
       
   280 // From CSvgMediaElementBase
       
   281 // ---------------------------------------------------------------------------
       
   282 void CSvgAudioElementImpl::Reset( MSvgEvent* aEvent )
       
   283 	{
       
   284 
       
   285 	iIsUserSeek = ETrue;
       
   286     iStoredPos = 0;
       
   287 	// call the animation base function.
       
   288 	TSvgTimerEvent* timerEvent  = ( TSvgTimerEvent* ) aEvent;
       
   289 	if((TInt32)timerEvent->Time() < iAbsoluteBeginTime)
       
   290 		{
       
   291 		// let it come to initial position.
       
   292 		//((CSvgDocumentImpl*)iOwnerDocument)->iInitialDrawFlag = ETrue;
       
   293 		ReInitializeAnimation();
       
   294 		return;
       
   295 		}
       
   296 	TRAPD(error,CSvgAnimationBase::ResetL( aEvent, this));
       
   297     if (error != KErrNone)
       
   298         {
       
   299         // error processing not processed
       
   300         return;
       
   301         }
       
   302 	}  
       
   303 	
       
   304 // ---------------------------------------------------------------------------
       
   305 // Call AnimaProcL
       
   306 // ---------------------------------------------------------------------------
       
   307 TBool CSvgAudioElementImpl::DoAnimProcL(MSvgEvent* aEvent)
       
   308     {
       
   309     return this->AnimProcL((MSvgTimerEvent*)aEvent);
       
   310     }
       
   311 
       
   312 
       
   313 // ---------------------------------------------------------------------------
       
   314 // From MsvgAnimationBase
       
   315 // ---------------------------------------------------------------------------
       
   316 TBool CSvgAudioElementImpl::AnimProcL( MSvgTimerEvent* /*aEvent*/ )
       
   317     {
       
   318 #ifdef _DEBUG    
       
   319    	RDebug::Print(_L("%d %d"), iAnimStatus, IsAnimating());
       
   320 #endif   	
       
   321     if ( iAudioStatus == EPlayerProhibit )
       
   322         return EFalse;
       
   323     
       
   324     if ( /*iAnimTime->DurationTime() == KTimeIndefinite ||*/ iAnimTime->DurationTime() == 0 )
       
   325         {
       
   326          return EFalse;
       
   327         }
       
   328 	
       
   329     if ( !iAudioPlayer )
       
   330         {
       
   331     	iAudioPlayer = CMdaAudioPlayerUtility::NewL(*this);
       
   332         RDebug::Print(_L("SvgtAudioElem: Player created"));
       
   333         }
       
   334 
       
   335     if ( iAudioStatus != EPlayerStateIdle && !iAudioPlayer )
       
   336         {
       
   337         // Error case, when player is initialised but
       
   338         // iAudioPlayer pointer is NULL.
       
   339         return EFalse;
       
   340         }
       
   341 
       
   342     if( iAnimStatus != KAnimActive )
       
   343         {
       
   344         if ( iAudioStatus == EPlayerStatePlaying )
       
   345     		{
       
   346     		iStoredPos = 0;
       
   347         	iAudioPlayer->Stop();
       
   348         	iAudioStatus = EPlayerStateStop;
       
   349         	return EFalse;
       
   350     		}
       
   351         }
       
   352     else //iAnimStatus == KAnimActive
       
   353         {
       
   354         if ( !iHadBegun )
       
   355             {
       
   356             iHadBegun = ETrue;
       
   357             // Save the time the audio element starts
       
   358             iAudioStartOffset = 
       
   359                 ( ( CSvgDocumentImpl* )iOwnerDocument)->CurrentTime();
       
   360 
       
   361             // this is a restart from begin list.
       
   362             if ((iAudioStatus != EPlayerStateIdle) &&
       
   363             	(iAudioStatus != EPlayerStatePlayInit))
       
   364             	{
       
   365 		    	iStoredPos = 0;
       
   366 		    	iAudioPlayer->Stop();
       
   367 		    	iAudioPlayer->Play();
       
   368 		    	iAudioStatus = EPlayerStatePlaying;
       
   369             	}
       
   370             return ETrue;
       
   371          }
       
   372 
       
   373         if ( iAudioStatus == EPlayerStateIdle ) // stopped
       
   374         {
       
   375         // Indicate to the time container that audio element 
       
   376         // is not ready
       
   377         ( ( CSvgDocumentImpl* )
       
   378             iOwnerDocument )->TimeContainer()->TimedEntityNotReady( 
       
   379             this );
       
   380         // Save the audio start offset
       
   381         iAudioStartOffset = 
       
   382             ( ( CSvgDocumentImpl* )iOwnerDocument)->CurrentTime();
       
   383         TPtrC href = Href();
       
   384         #ifdef _DEBUG            
       
   385         RDebug::Print(_L("CSvgAudioElementImpl::NewFilePlayerL is to be called"));
       
   386         RDebug::RawPrint(href);
       
   387         #endif           	           	
       
   388 
       
   389         //Check and load file here
       
   390         RFs  session;
       
   391         CSvgErrorImpl* SvgError  =  CSvgErrorImpl::NewL();
       
   392         CSvgDocumentImpl::OpenSession( session,  *SvgError  );
       
   393 
       
   394         RFile fileHandle;
       
   395 
       
   396         CSvgDocumentImpl* document = (CSvgDocumentImpl*)OwnerDocument();
       
   397         CSvgEngineImpl* engine  = document->Engine();
       
   398         MSvgRequestObserver* lRequestObserver = NULL;
       
   399         TInt lFetchStatus = KErrNone;
       
   400         if(engine!= NULL)
       
   401             {
       
   402             lRequestObserver =  engine->iRequestObserver;
       
   403             }
       
   404         else
       
   405             {
       
   406             return EFalse;
       
   407             }
       
   408             
       
   409         if(lRequestObserver != NULL)
       
   410             {
       
   411             lFetchStatus = lRequestObserver->FetchImage( *iUri, session, fileHandle );
       
   412             }
       
   413         else
       
   414             {
       
   415             return EFalse;
       
   416             }
       
   417         
       
   418         if(lFetchStatus == KErrNone)
       
   419          {
       
   420          iAudioPlayer->OpenFileL(fileHandle);
       
   421          
       
   422          }
       
   423            else
       
   424              {
       
   425              return EFalse;
       
   426              }
       
   427         if(SvgError) 
       
   428          {
       
   429          delete SvgError;
       
   430          }
       
   431         session.Close();
       
   432         iAudioStatus = EPlayerStatePlayInit;  	
       
   433         #ifdef _DEBUG       		
       
   434         RDebug::Print(_L("SvgtAudioElem: File opened"));
       
   435         #endif           	
       
   436         return ETrue;
       
   437         }
       
   438         if( iAudioStatus == EPlayerStateStop && iTcCommandState != ESvgTEPausedState)
       
   439         {
       
   440 
       
   441         		iAudioStartOffset = 
       
   442                 ( ( CSvgDocumentImpl* )iOwnerDocument)->CurrentTime();
       
   443             // if previously audio is still playing, and asked to play again...
       
   444         	iAudioPlayer->Play();
       
   445         	iAudioStatus = EPlayerStatePlaying;
       
   446             }
       
   447         }
       
   448         return ETrue;
       
   449     }
       
   450 
       
   451 
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // Set the volume of the Audio Player to the specified level
       
   455 // ---------------------------------------------------------------------------
       
   456 void CSvgAudioElementImpl::SetVolume(TInt aPercentage)
       
   457     {
       
   458     if(
       
   459     iAudioPlayer && 
       
   460     (iAudioStatus != EPlayerStateIdle && iAudioStatus != EPlayerStatePlayInit && iAudioStatus != EPlayerProhibit)
       
   461     )
       
   462         {
       
   463         TInt lVolLevel = 0;
       
   464         // Check if within limits
       
   465         if  ( aPercentage > 0  && aPercentage <= 100 )
       
   466             {
       
   467 #ifdef __WINSCW__            
       
   468             const TReal32 KMaxAudioVolumeLevels = 65535;
       
   469 #else
       
   470             const TReal32 KMaxAudioVolumeLevels = iAudioPlayer->MaxVolume();
       
   471 #endif   
       
   472             // Calculating the volume based on system volume & element volume
       
   473             TReal32 lRealLevel = ((TReal32)aPercentage/100.0) * KMaxAudioVolumeLevels * iVolume;
       
   474             lVolLevel = lRealLevel;
       
   475             }
       
   476         iAudioPlayer->SetVolume(lVolLevel);
       
   477         }
       
   478     iPercentLevelVolume = aPercentage;
       
   479     }
       
   480 
       
   481 // ---------------------------------------------------------------------------
       
   482 // From CMdaAudioPlayerUtility
       
   483 // Callback from Audio Player indicating the audio has finished initalisation
       
   484 // ---------------------------------------------------------------------------
       
   485 void CSvgAudioElementImpl::MapcInitComplete(TInt aError,
       
   486                 const TTimeIntervalMicroSeconds& aDuration)
       
   487 	{
       
   488 	if ( aError == KErrNone )
       
   489 	    {
       
   490        	if(iDurMedia)
       
   491           	{
       
   492             TTimeIntervalMicroSeconds durInMicroS;
       
   493             durInMicroS   = aDuration;
       
   494 
       
   495 
       
   496             TInt32 durInMilliS;
       
   497             durInMilliS  =  durInMicroS.Int64()  /  KMillisecondsPerMicrosecond;
       
   498 
       
   499             iAnimTime->SetDurationTime(durInMilliS);
       
   500             //In ReInitialize function of AnimTimeController
       
   501             // the duration is reinitialized from Org Duration
       
   502             iAnimTime->SetOrgDurationTime(durInMilliS);
       
   503            	}
       
   504 #ifdef _DEBUG           	
       
   505     	RDebug::Print(_L("CSvgAudioElementImpl::MapcInitComplete :-> Open audio file OK!"));
       
   506 #endif    	
       
   507     	iMediaDuration = aDuration;
       
   508 
       
   509         TInt lVolLevel = 0;
       
   510 
       
   511         // Check if within limits
       
   512         if  ( iPercentLevelVolume > 0  && iPercentLevelVolume <= 100 )
       
   513             {
       
   514 #ifdef __WINSCW__            
       
   515             const TReal32 KMaxAudioVolumeLevels = 65535;
       
   516 #else
       
   517             const TReal32 KMaxAudioVolumeLevels = iAudioPlayer->MaxVolume();
       
   518 #endif            
       
   519             // Calculating the volume based on system volume & element volume
       
   520             TReal32 lRealLevel = ((TReal32)iPercentLevelVolume/100.0) * KMaxAudioVolumeLevels * iVolume;
       
   521             lVolLevel = lRealLevel;
       
   522             }
       
   523         iAudioPlayer->SetVolume(lVolLevel);
       
   524         // If the pause command was issued do not play, the resume should set 
       
   525         // it playing
       
   526         if(iTcCommandState == ESvgTEPlayingState)
       
   527             {
       
   528 #ifdef _DEBUG            
       
   529             RDebug::Print(_L("To play"));
       
   530 #endif            
       
   531             iAudioPlayer->Play();
       
   532             iAudioStatus = EPlayerStatePlaying;
       
   533             }
       
   534         else if(iTcCommandState == ESvgTEStoppedState)
       
   535             {
       
   536             iAudioStatus = EPlayerStateStop;
       
   537             }
       
   538         else
       
   539             {
       
   540              iAudioStatus = EPlayerStatePaused;
       
   541             }
       
   542         }
       
   543     else
       
   544         {
       
   545         #ifdef _DEBUG
       
   546     	RDebug::Print(_L("CSvgAudioElementImpl::MapcPlayComplete :-> Error code [%d]"), aError);
       
   547     	#endif
       
   548         }
       
   549     if ( iNegativeBeginTime < 0 )
       
   550         {
       
   551         const TInt64 aInterval = iNegativeBeginTime * -1000;
       
   552         TTimeIntervalMicroSeconds aTime(aInterval);        
       
   553         iAudioPlayer->SetPosition(aTime);
       
   554         iStoredPos = aTime;
       
   555         }
       
   556 	// Indicate to time container that audio element is ready
       
   557     ( ( CSvgDocumentImpl* )iOwnerDocument )->TimeContainer()->TimedEntityReady( 
       
   558                 this );	
       
   559         
       
   560 	}
       
   561 
       
   562 // ---------------------------------------------------------------------------
       
   563 // From CMdaAudioPlayerUtility
       
   564 // Callback from Audio Player indicating the audio has finished playing
       
   565 // ---------------------------------------------------------------------------
       
   566 void CSvgAudioElementImpl::MapcPlayComplete(TInt aError)
       
   567 	{
       
   568     // normal play exit
       
   569 	iAudioStatus = EPlayerStateComplete;
       
   570 
       
   571 	if ( aError != KErrNone )
       
   572 	    {
       
   573         #ifdef _DEBUG
       
   574 	    RDebug::Print(_L("CSvgAudioElementImpl::MapcPlayComplete :-> Error code [%d]"), aError);
       
   575     	#endif
       
   576 	    }
       
   577 	}
       
   578 
       
   579     
       
   580 // -----------------------------------------------------------------------------
       
   581 // CSvgAudioElementImpl::CanGenerateTick
       
   582 // From CSvgMediaElementBase
       
   583 // -----------------------------------------------------------------------------
       
   584 TBool CSvgAudioElementImpl::CanGenerateTick()
       
   585     {
       
   586     // If media is playing then audio element can generate tick
       
   587     if ( iAudioPlayer && 
       
   588         ( iAudioStatus == EPlayerStatePlaying || 
       
   589             iAudioStatus == EPlayerStatePlayInit ) )
       
   590         {
       
   591         return ETrue;
       
   592         }
       
   593     return EFalse;
       
   594     }
       
   595 
       
   596 // -----------------------------------------------------------------------------
       
   597 // CSvgAudioElementImpl::GetEntityCurrentTime
       
   598 // From CSvgMediaElementBase
       
   599 // -----------------------------------------------------------------------------
       
   600 //        
       
   601 void CSvgAudioElementImpl::GetEntityCurrentTime( TUint32& 
       
   602             aEntityCurTime ) // Current Entity Time in msecs. 
       
   603     {
       
   604     if ( iAudioPlayer && iAudioStatus != EPlayerStateIdle )
       
   605         {
       
   606         // Convert to  milliseconds and account for negative  begin  time
       
   607         // and the audio start offset  and  send back
       
   608         if(iAudioStatus == EPlayerStateComplete)
       
   609         {
       
   610             TTimeIntervalMicroSeconds lDuration = iAudioPlayer->Duration();
       
   611             aEntityCurTime = iAudioStartOffset +  lDuration.Int64() / KMillisecondsPerMicrosecond;
       
   612         }
       
   613         else
       
   614         {
       
   615             TTimeIntervalMicroSeconds lPos; 
       
   616             iAudioPlayer->GetPosition( lPos );
       
   617             
       
   618             // at EOF lPos returns zero, no point of time should 
       
   619             // iStorePos be greater than lPos
       
   620             if(iStoredPos > lPos)
       
   621                 {
       
   622                 lPos = iStoredPos;
       
   623                 }
       
   624             else
       
   625                 {
       
   626                 iStoredPos = lPos;
       
   627                 }
       
   628         #ifdef _DEBUG
       
   629     	RDebug::Printf("====================================");
       
   630     	RDebug::Printf("Audio gets current position \n");
       
   631     	RDebug::Printf("lpos %d", lPos.Int64());
       
   632     	RDebug::Printf("====================================");
       
   633     	#endif
       
   634         aEntityCurTime = iAudioStartOffset + lPos.Int64() / KMillisecondsPerMicrosecond;
       
   635         }
       
   636         if(iAudioStatus == EPlayerStatePlaying)
       
   637             {
       
   638             aEntityCurTime += iNegativeBeginTime;
       
   639             }
       
   640         }
       
   641     else
       
   642         {
       
   643         aEntityCurTime = iAudioStartOffset;
       
   644         }
       
   645     }
       
   646 
       
   647 // -----------------------------------------------------------------------------
       
   648 // CSvgAudioElementImpl::ResyncTimedEntity
       
   649 // From CSvgMediaElementBase
       
   650 // -----------------------------------------------------------------------------
       
   651 void CSvgAudioElementImpl::ResyncTimedEntity( 
       
   652             TUint32 aSyncTime ) // Time for resync in msecs.
       
   653     {
       
   654     if ( iAudioPlayer && iAudioStatus == EPlayerStatePlaying )
       
   655         {
       
   656         // Convert sync to microsecs before setting position
       
   657         TTimeIntervalMicroSeconds  lSeekPos(  aSyncTime  *  KMillisecondsPerMicrosecond );
       
   658         iAudioPlayer->SetPosition( lSeekPos );
       
   659         iStoredPos = lSeekPos;
       
   660         }
       
   661     } 
       
   662 
       
   663 // -----------------------------------------------------------------------------
       
   664 // CSvgAudioElementImpl::PauseTimedEntity
       
   665 // From CSvgMediaElementBase
       
   666 // -----------------------------------------------------------------------------
       
   667 void CSvgAudioElementImpl::PauseTimedEntity()
       
   668     {
       
   669 
       
   670     iTcCommandState = ESvgTEPausedState;
       
   671       if ( iAudioPlayer && iAudioStatus == EPlayerStatePlaying )
       
   672         {
       
   673             iAudioPlayer->Pause();
       
   674         	iAudioStatus = EPlayerStatePaused;
       
   675         }
       
   676     }
       
   677 
       
   678 // -----------------------------------------------------------------------------
       
   679 // CSvgAudioElementImpl::ResumeTimedEntity
       
   680 // From CSvgMediaElementBase
       
   681 // -----------------------------------------------------------------------------
       
   682 void CSvgAudioElementImpl::ResumeTimedEntity()
       
   683     {
       
   684     iTcCommandState = ESvgTEPlayingState; 
       
   685     // Resume of the player is done only when it is Pause State
       
   686     // When resume is done on Stopped/Completed, it might start playing it
       
   687     // even though animation is not active or it is not supposed to repeat.
       
   688 	if ( iAudioStatus == EPlayerStatePaused )
       
   689       {
       
   690     	iAudioPlayer->Play();
       
   691     	iAudioStatus = EPlayerStatePlaying;
       
   692       }
       
   693     }
       
   694 
       
   695 // -----------------------------------------------------------------------------
       
   696 // CSvgAudioElementImpl::StopTimedEntity
       
   697 // From CSvgMediaElementBase
       
   698 // -----------------------------------------------------------------------------
       
   699 void CSvgAudioElementImpl::StopTimedEntity()
       
   700     {
       
   701     iTcCommandState = ESvgTEStoppedState;
       
   702     if ( iAudioPlayer && iAudioStatus != EPlayerStateIdle )
       
   703         {
       
   704         iStoredPos = 0;
       
   705         iAudioPlayer->Stop();
       
   706         iAudioStatus = EPlayerStateStop;
       
   707         }
       
   708     }
       
   709     
       
   710  
       
   711 // ---------------------------------------------------------------------------
       
   712 //From MSvgTimedEntityInterface
       
   713 // ---------------------------------------------------------------------------
       
   714 TSvgObjectType CSvgAudioElementImpl::ObjectType()
       
   715     {
       
   716 	return ESvgAudioElement;	
       
   717     }
       
   718 
       
   719 
       
   720 
       
   721 // ---------------------------------------------------------------------------
       
   722 // returns the child time container of the element 
       
   723 // used in timecontainer
       
   724 // ---------------------------------------------------------------------------
       
   725 CSvgTimeContainer* CSvgAudioElementImpl::GetChildTimeContainer()
       
   726     {
       
   727     return NULL;
       
   728     }
       
   729     
       
   730     
       
   731 // ---------------------------------------------------------------------------
       
   732 // Constructor for CSvgAudioElementImpl
       
   733 // ---------------------------------------------------------------------------
       
   734 CSvgAudioElementImpl::CSvgAudioElementImpl( CSvgDocumentImpl* aDoc )
       
   735                             : CSvgMediaElementBase( aDoc ),
       
   736                             iAudioStatus(EPlayerStateIdle),
       
   737                             iVolume(1),
       
   738                             iTcCommandState(ESvgTEPlayingState),
       
   739                             iDurMedia(ETrue)
       
   740     {
       
   741 	iAttrId = KAtrAudioId;
       
   742 	iAudioPlayer = NULL;
       
   743     }
       
   744 
       
   745 
       
   746 // ---------------------------------------------------------------------------
       
   747 // perform a deep copy of this object
       
   748 // ---------------------------------------------------------------------------
       
   749 void CSvgAudioElementImpl::CopyL( CSvgAudioElementImpl* aDestElement )
       
   750     {
       
   751     if(aDestElement)
       
   752         {
       
   753           // copy stuff from superclass
       
   754         this->CSvgElementImpl::CopyL(aDestElement);
       
   755 
       
   756         // copy the reference to idoc (CSvgDocumentImpl)
       
   757         aDestElement->iOwnerDocument = this->iOwnerDocument;
       
   758         aDestElement->iAudioPlayer = this->iAudioPlayer;
       
   759         aDestElement->iAudioStatus = this->iAudioStatus;
       
   760         aDestElement->iVolume = this->iVolume;
       
   761         aDestElement->iPercentLevelVolume = this->iPercentLevelVolume;
       
   762         aDestElement->iMediaDuration = this->iMediaDuration;
       
   763         aDestElement->iTcCommandState = this->iTcCommandState;
       
   764         aDestElement->iAudioStartOffset = this->iAudioStartOffset;
       
   765         aDestElement->iDurMedia = this->iDurMedia;
       
   766         }
       
   767     }
       
   768 // ---------------------------------------------------------------------------
       
   769 //
       
   770 // ---------------------------------------------------------------------------
       
   771 void CSvgAudioElementImpl::DeactivateAnimation()
       
   772 	{
       
   773 	CSvgAnimationBase::DeactivateAnimation(this);
       
   774 	}
       
   775 
       
   776 // ---------------------------------------------------------------------------
       
   777 // 
       
   778 // ---------------------------------------------------------------------------
       
   779 void CSvgAudioElementImpl::Print( TBool aIsEncodeOn )
       
   780     {
       
   781 	if (!aIsEncodeOn)
       
   782     	{
       
   783     	#ifdef _DEBUG
       
   784     	RDebug::Printf("<audio>");
       
   785     	#endif
       
   786         }
       
   787     }
       
   788 
       
   789 // ---------------------------------------------------------------------------
       
   790 // End of file
       
   791 // ---------------------------------------------------------------------------