videditor/VideoEditorUiComponents/src/VeiVideoDisplay.cpp
changeset 0 951a5db380a0
equal deleted inserted replaced
-1:000000000000 0:951a5db380a0
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // System includes
       
    21 #include <gulicon.h>
       
    22 #include <coemain.h>
       
    23 #include <eikenv.h>
       
    24 #include <akniconutils.h>
       
    25 #include <aknsdrawutils.h> 
       
    26 #include <aknsdatacontext.h> 
       
    27 #include <akniconutils.h>
       
    28 #include <aknbitmapanimation.h>
       
    29 #include <barsread.h>
       
    30 #include <VideoEditorUiComponents.mbg>
       
    31 #include <VideoEditorUiComponents.rsg>
       
    32 #include <audiopreference.h>
       
    33 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    34 #include <ConeResLoader.h>
       
    35 #include <data_caging_path_literals.hrh>
       
    36 #include <mmf/common/mmfcontrollerframeworkbase.h> 
       
    37 #include <mmf/common/mmferrors.h>
       
    38 #ifdef VERBOSE
       
    39 #include <eikappui.h>
       
    40 #endif
       
    41 
       
    42 // User includes
       
    43 #include "VeiVideoEditorSettings.h"
       
    44 #include "VeiVideoDisplay.h"
       
    45 #include "VideoEditorCommon.h"
       
    46 #include "VideoEditorUtils.h"
       
    47 #include "VideoEditorDebugUtils.h"
       
    48 
       
    49 // CONSTANTS
       
    50 _LIT(KResourceFile, "VideoEditorUiComponents.rsc");
       
    51 
       
    52 EXPORT_C CVeiVideoDisplay* CVeiVideoDisplay::NewL( const TRect& aRect, const CCoeControl* aParent,
       
    53 										  MVeiVideoDisplayObserver& aObserver )
       
    54     {
       
    55     CVeiVideoDisplay* self = CVeiVideoDisplay::NewLC( aRect, aParent, aObserver );
       
    56     CleanupStack::Pop(self);
       
    57     return self;
       
    58     }
       
    59 
       
    60 EXPORT_C CVeiVideoDisplay* CVeiVideoDisplay::NewLC( const TRect& aRect, const CCoeControl* aParent,
       
    61 										   MVeiVideoDisplayObserver& aObserver )
       
    62     {
       
    63     CVeiVideoDisplay* self = new (ELeave) CVeiVideoDisplay (aObserver);
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL( aRect, aParent );
       
    66     return self;
       
    67     }
       
    68 
       
    69 CVeiVideoDisplay::CVeiVideoDisplay( MVeiVideoDisplayObserver& aObserver ) : iObserver (aObserver)
       
    70 	{
       
    71 	}	
       
    72 
       
    73 void CVeiVideoDisplay::ConstructL( const TRect& aRect, 
       
    74                                    const CCoeControl* aParent)
       
    75     {
       
    76     LOG(KVideoEditorLogFile, "CVeiVideoDisplay::ConstructL: in");
       
    77 
       
    78 	TFileName mbmPath( VideoEditorUtils::IconFileNameAndPath(KVideoEditorUiComponentsIconFileId) );
       
    79     
       
    80     
       
    81 // Backgroud squares icon loading is disabled there is no suitable graphic in 
       
    82 // S60 build at the moment. A new graphic should be requested and added here.
       
    83     
       
    84 //	AknIconUtils::CreateIconL( iBgSquaresBitmap, iBgSquaresBitmapMask,
       
    85 //			mbmPath, EMbmVideoeditoruicomponentsQgn_graf_ve_novideo, 
       
    86 //			EMbmVideoeditoruicomponentsQgn_graf_ve_novideo_mask );    
       
    87     
       
    88     
       
    89 	TRAP_IGNORE( CVeiVideoEditorSettings::GetMediaPlayerVolumeLevelL( iInternalVolume ) );
       
    90 
       
    91 	iMuted = (iInternalVolume == 0);
       
    92 
       
    93 	iBorderWidth = 2;
       
    94 	iDuration = 0;
       
    95 	iMaxVolume = 0;
       
    96 	iBlank = ETrue;
       
    97 	iAnimationOn = EFalse;
       
    98 	iBufferingCompleted = ETrue;
       
    99 	SetContainerWindowL( *aParent );
       
   100 
       
   101 	SetRect( aRect );
       
   102     ActivateL();
       
   103 
       
   104 	ControlEnv()->AddForegroundObserverL( *this );
       
   105 
       
   106     LOG(KVideoEditorLogFile, "CVeiVideoDisplay::ConstructL: out");
       
   107     }
       
   108 
       
   109 void CVeiVideoDisplay::SizeChanged()
       
   110     {
       
   111 	LOGFMT2(KVideoEditorLogFile, "CVeiVideoDisplay::SizeChanged: in: Size(): (%d,%d)", Size().iWidth, Size().iHeight);
       
   112 
       
   113 	if ( iVideoPlayerUtility )
       
   114 		{
       
   115 		TRect screenRect = CalculateVideoPlayerArea();
       
   116 		LOGFMT4(KVideoEditorLogFile, "CVeiVideoDisplay::SizeChanged 1, ScreenRect Tl:(%d,%d) Br:(%d,%d)", screenRect.iTl.iX,screenRect.iTl.iY,screenRect.iBr.iX,screenRect.iBr.iY);
       
   117 
       
   118 		/* Get the required parameters for the video player. */
       
   119 		CCoeEnv* coeEnv = CCoeEnv::Static();
       
   120 		RWsSession& session = coeEnv->WsSession();
       
   121 		CWsScreenDevice* screenDevice = coeEnv->ScreenDevice();
       
   122 		RDrawableWindow* drawableWindow = DrawableWindow();
       
   123 
       
   124 		TRAPD(err, iVideoPlayerUtility->SetDisplayWindowL( session, *screenDevice, *drawableWindow,
       
   125 			screenRect, screenRect ) );
       
   126 		if( KErrNone != err )
       
   127 			{
       
   128 			LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::SizeChanged: iVideoPlayerUtility->SetDisplayWindowL failed: %d", err);
       
   129 			iObserver.NotifyVideoDisplayEvent( MVeiVideoDisplayObserver::EError );
       
   130 			}
       
   131 		}
       
   132 	AknIconUtils::SetSize( iBgSquaresBitmap, Size(), EAspectRatioNotPreserved );
       
   133 
       
   134 
       
   135 	if( iAnimationOn )
       
   136 		{
       
   137 		iAnimation->CancelAnimation();
       
   138 		TRect rect( Rect() );
       
   139 		rect.Move( iBorderWidth, iBorderWidth );
       
   140 		rect.Resize( -iBorderWidth*2, -iBorderWidth );
       
   141 
       
   142 		iAnimation->SetRect( rect );
       
   143 		TRAPD(err, iAnimation->StartAnimationL() );
       
   144 		if( KErrNone != err )
       
   145 			{
       
   146 			LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::SizeChanged: StartAnimationL failed: %d", err);
       
   147 			iObserver.NotifyVideoDisplayEvent( MVeiVideoDisplayObserver::EError );
       
   148 			}
       
   149 		}
       
   150 
       
   151 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::SizeChanged: out");
       
   152 	}
       
   153 
       
   154 TRect CVeiVideoDisplay::CalculateVideoPlayerArea()
       
   155 	{
       
   156 	/* Calculate regions. */ 
       
   157 	TRect screenRect;
       
   158 	TRect rect( Rect() );
       
   159 	/* In full screen mode return whole screen rect*/
       
   160 	if ( rect.iTl == TPoint( 0,0) )
       
   161 		{
       
   162 		return rect;
       
   163 		}
       
   164 	LOGFMT4(KVideoEditorLogFile, "CVeiVideoDisplay::CalculateVideoPlayerArea() 1: Rect() Tl:(%d,%d) Br:(%d,%d)", rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
       
   165 	
       
   166 	TPoint position = PositionRelativeToScreen();
       
   167 	LOGFMT2(KVideoEditorLogFile, "CVeiVideoDisplay::CalculateVideoPlayerArea() 2: PositionRelativeToScreen(%d,%d)", position.iX, position.iY);
       
   168 
       
   169 	screenRect = rect;  
       
   170 	screenRect.Move( TPoint( iBorderWidth, (position.iY-Rect().iTl.iY) + iBorderWidth ) ); 
       
   171 	screenRect.Resize( -(iBorderWidth*2), -(iBorderWidth*2 ));
       
   172 	return screenRect;
       
   173 	}
       
   174 
       
   175 TKeyResponse CVeiVideoDisplay::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   176 	{
       
   177 	LOGFMT2(KVideoEditorLogFile, "CVeiVideoDisplay::OfferKeyEventL: aKeyEvent.iCode:%d, aType:%d", aKeyEvent.iCode, aType);
       
   178 
       
   179 	if ( iMuted )
       
   180 		{
       
   181 		LOG(KVideoEditorLogFile, "CVeiVideoDisplay::OfferKeyEventL: volume is muted.");
       
   182 		return EKeyWasNotConsumed;
       
   183 		}
       
   184 	
       
   185 	if ( aType == EEventKey )
       
   186 		{
       
   187 		switch (aKeyEvent.iCode)
       
   188 			{
       
   189 			case EKeyDownArrow:
       
   190 			case EStdKeyDecVolume:
       
   191 				{
       
   192 				AdjustVolumeL( -1 );
       
   193 				return EKeyWasConsumed;
       
   194 				}
       
   195 			case EKeyUpArrow:
       
   196 			case EStdKeyIncVolume:
       
   197 				{
       
   198 				AdjustVolumeL( 1 );
       
   199 				return EKeyWasConsumed;
       
   200 				}
       
   201 			default:
       
   202 				{
       
   203 				return EKeyWasConsumed;
       
   204 				}
       
   205 			}
       
   206 		}
       
   207 	return EKeyWasConsumed;
       
   208 	}
       
   209 
       
   210 EXPORT_C CVeiVideoDisplay::~CVeiVideoDisplay()
       
   211 	{
       
   212 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::~CVeiVideoDisplay(): In");
       
   213 	// Remove foreground event observer
       
   214 	ControlEnv()->RemoveForegroundObserver( *this );
       
   215 	if ( iDisplayBitmap )
       
   216 		{
       
   217 		delete iDisplayBitmap;
       
   218 		iDisplayBitmap = NULL;
       
   219 		}
       
   220 	if ( iDisplayMask )
       
   221 		{
       
   222 		delete iDisplayMask;
       
   223 		iDisplayMask = NULL;
       
   224 		}
       
   225 	delete iBgSquaresBitmap;
       
   226 	delete iBgSquaresBitmapMask;
       
   227 
       
   228 	if ( iVideoPlayerUtility != NULL )
       
   229 		{
       
   230 		iVideoPlayerUtility->Close();
       
   231 		delete iVideoPlayerUtility;
       
   232 		iVideoPlayerUtility = NULL;
       
   233 		}
       
   234 	delete iAnimation;
       
   235 	delete iCallBack;
       
   236 	delete iFilename;
       
   237 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::~CVeiVideoDisplay(): Out");
       
   238 	}
       
   239 
       
   240 EXPORT_C void CVeiVideoDisplay::ShowPictureL( const CFbsBitmap& aBitmap, const CFbsBitmap& aMask )
       
   241 	{
       
   242 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::ShowPictureL: In");
       
   243 
       
   244 	StoreDisplayBitmapL( aBitmap, &aMask );
       
   245 
       
   246 	DrawDeferred();
       
   247 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::ShowPictureL: Out");
       
   248 	}
       
   249 
       
   250 EXPORT_C void CVeiVideoDisplay::ShowPictureL( const CFbsBitmap& aBitmap )
       
   251 	{
       
   252 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::ShowPicture2: In");
       
   253 
       
   254 	StoreDisplayBitmapL( aBitmap );
       
   255 
       
   256 	// set screen size to pause mode
       
   257 	if ( iVideoPlayerUtility )
       
   258 		{
       
   259 		TRect screenRect = TRect( TPoint(0,0), TPoint(0,0) );			
       
   260 		LOGFMT4(KVideoEditorLogFile, "CVeiVideoDisplay::SizeChanged 1, ScreenRect Tl:(%d,%d) Br:(%d,%d)", screenRect.iTl.iX,screenRect.iTl.iY,screenRect.iBr.iX,screenRect.iBr.iY);
       
   261 
       
   262 		/* Get the required parameters for the video player. */
       
   263 		CCoeEnv* coeEnv = CCoeEnv::Static();
       
   264 		RWsSession& session = coeEnv->WsSession();
       
   265 		CWsScreenDevice* screenDevice = coeEnv->ScreenDevice();
       
   266 		RDrawableWindow* drawableWindow = DrawableWindow();
       
   267 
       
   268 		iVideoPlayerUtility->SetDisplayWindowL( session, *screenDevice, *drawableWindow,
       
   269 			screenRect, screenRect );
       
   270 		}
       
   271 
       
   272 	DrawDeferred();
       
   273 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::ShowPicture2: Out");
       
   274 	}
       
   275 
       
   276 EXPORT_C void CVeiVideoDisplay::SetPictureL( const CFbsBitmap& aBitmap )
       
   277 	{
       
   278 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::SetPictureL: In");
       
   279 
       
   280 	StoreDisplayBitmapL( aBitmap );
       
   281 
       
   282 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::SetPictureL: Out");	
       
   283 	}
       
   284 
       
   285 void CVeiVideoDisplay::StoreDisplayBitmapL( const CFbsBitmap& aBitmap, const CFbsBitmap* aMask )
       
   286 	{
       
   287 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::StoreDisplayBitmapL: In");
       
   288 
       
   289 	iBlank = EFalse;
       
   290 	iBlack = EFalse;
       
   291 
       
   292 	// Delete old bitmaps
       
   293 	if ( iDisplayBitmap )
       
   294 		{
       
   295 		delete iDisplayBitmap;
       
   296 		iDisplayBitmap = NULL;
       
   297 		}
       
   298 	if ( iDisplayMask )
       
   299 		{
       
   300 		delete iDisplayMask;
       
   301 		iDisplayMask = NULL;
       
   302 		}
       
   303 
       
   304 	// Create new bitmaps
       
   305 	iDisplayBitmap = new (ELeave) CFbsBitmap;
       
   306 	iDisplayBitmap->Duplicate( aBitmap.Handle() );
       
   307 	if (aMask)
       
   308 		{
       
   309 		iDisplayMask = new (ELeave) CFbsBitmap;
       
   310 		iDisplayMask->Duplicate( aMask->Handle() );
       
   311 		}
       
   312 
       
   313 #ifdef VERBOSE
       
   314 	// Write the display bitmap to disk
       
   315 	_LIT(KFileName, "C:\\data\\images\\videoeditor\\iDisplayBitmap.mbm");
       
   316 	TFileName saveToFile( KFileName );
       
   317 	CEikonEnv* env = CEikonEnv::Static();
       
   318 	env->EikAppUi()->Application()->GenerateFileName( env->FsSession(), saveToFile );
       
   319 	User::LeaveIfError( iDisplayBitmap->Save( saveToFile ) );
       
   320 	LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::StoreDisplayBitmapL: saved %S", &saveToFile);
       
   321 #endif
       
   322 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::StoreDisplayBitmapL: Out");
       
   323 	}
       
   324 
       
   325 EXPORT_C void CVeiVideoDisplay::ShowBlackScreen()
       
   326 	{
       
   327 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::ShowBlackScreen: In");	
       
   328 	iBlack = ETrue;
       
   329 	DrawDeferred();
       
   330 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::ShowBlackScreen: Out");	
       
   331 	}
       
   332 EXPORT_C void CVeiVideoDisplay::SetBlackScreen( TBool aBlack )
       
   333     {
       
   334     LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::SetBlackScreen: In and out, aBlack:%d", aBlack);	
       
   335     iBlack = aBlack;
       
   336     }
       
   337 EXPORT_C void CVeiVideoDisplay::ShowBlankScreen()
       
   338 	{
       
   339 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::ShowBlankScreen: In and out");	
       
   340 	iBlank = ETrue;
       
   341 	DrawDeferred();
       
   342 	}
       
   343 
       
   344 EXPORT_C TTimeIntervalMicroSeconds CVeiVideoDisplay::PositionL() const
       
   345 	{
       
   346 	if ( !iVideoPlayerUtility )
       
   347 		return TTimeIntervalMicroSeconds(0);
       
   348 	else
       
   349 		return iVideoPlayerUtility->PositionL();
       
   350 	}
       
   351 
       
   352 EXPORT_C TVideoRotation CVeiVideoDisplay::RotationL() const
       
   353     {
       
   354     if ( iVideoPlayerUtility )
       
   355     	{
       
   356         return iVideoPlayerUtility->RotationL();
       
   357     	}
       
   358     else
       
   359     	{
       
   360         return EVideoRotationNone;
       
   361     	}
       
   362     }
       
   363 
       
   364 EXPORT_C void CVeiVideoDisplay::SetPositionL( const TTimeIntervalMicroSeconds& aPosition )
       
   365 	{
       
   366 	LOGFMT(KVideoEditorLogFile, "VideoDisplay SetPositionL: %Ld", aPosition.Int64());
       
   367 	iStartPoint = aPosition;
       
   368 	if ( iVideoPlayerUtility && iBufferingCompleted )
       
   369 		{	
       
   370 		iVideoPlayerUtility->SetPositionL( iStartPoint );
       
   371 		}
       
   372 	}
       
   373 
       
   374 EXPORT_C void CVeiVideoDisplay::SetRotationL(TVideoRotation aRotation)
       
   375     {
       
   376 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::SetRotationL: in");
       
   377     if ( iVideoPlayerUtility )
       
   378 		{
       
   379 		iVideoPlayerUtility->SetRotationL( aRotation );
       
   380 		}
       
   381 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::SetRotationL: out");
       
   382     }
       
   383 
       
   384 
       
   385 EXPORT_C void CVeiVideoDisplay::Stop( TBool aCloseStream )
       
   386 	{
       
   387 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::Stop: in");	
       
   388 	if ( iVideoPlayerUtility )
       
   389 		{
       
   390 		// this is poor solution, responsibility of taking care of iStartPoint be elsewhere
       
   391 		TRAP_IGNORE(iStartPoint = PositionL());
       
   392 		iVideoPlayerUtility->Stop();
       
   393 	
       
   394 		if ( aCloseStream )
       
   395 			{
       
   396 			LOG(KVideoEditorLogFile, "CVeiVideoDisplay::Stop 1, Close CVideoPlayerUtility.");
       
   397 			iVideoPlayerUtility->Close(); 
       
   398 			delete iVideoPlayerUtility;
       
   399 			iVideoPlayerUtility = NULL;
       
   400 			}
       
   401 		}
       
   402 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::Stop 2");
       
   403 	iObserver.NotifyVideoDisplayEvent( MVeiVideoDisplayObserver::EStop );
       
   404 
       
   405 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::Stop: out");
       
   406 	}
       
   407 
       
   408 EXPORT_C TInt CVeiVideoDisplay::GetBorderWidth() const
       
   409 	{
       
   410 	return iBorderWidth;
       
   411 	}
       
   412 
       
   413 EXPORT_C TSize CVeiVideoDisplay::GetScreenSize() const
       
   414 	{
       
   415 	TRect rect( Rect() );
       
   416 	rect.Shrink( iBorderWidth, iBorderWidth-1 );
       
   417 	return rect.Size();
       
   418 	}
       
   419 
       
   420 EXPORT_C void CVeiVideoDisplay::Play()
       
   421 	{
       
   422 	/*LOG(KVideoEditorLogFile, "CVeiVideoDisplay::Play :in");
       
   423 	if (iVideoPlayerUtility &&  iBufferingCompleted )
       
   424 		{	
       
   425 		LOG(KVideoEditorLogFile, "CVeiVideoDisplay::Play :2");
       
   426 		//SizeChanged();
       
   427 		iVideoPlayerUtility->Play();
       
   428 		}
       
   429 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::Play: out");
       
   430 	*/
       
   431 	PlayL(*iFilename);
       
   432 	}
       
   433 
       
   434 EXPORT_C void CVeiVideoDisplay::PlayMarkedL( const TTimeIntervalMicroSeconds& aStartPoint, const TTimeIntervalMicroSeconds& aEndPoint)
       
   435 	{
       
   436 	/*
       
   437 	LOGFMT2(KVideoEditorLogFile, "CVeiVideoDisplay::PlayMarked:In, aStartPoint:%Ld, aEndPoint:%Ld", aStartPoint.Int64(), aEndPoint.Int64());
       
   438 	iVideoPlayerUtility->SetPositionL(aStartPoint);
       
   439 	//SizeChanged();
       
   440 	iVideoPlayerUtility->Play(aStartPoint, aEndPoint);
       
   441 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::PlayMarked :Out");
       
   442 	*/
       
   443 	PlayL(*iFilename, aStartPoint, aEndPoint);
       
   444 	}
       
   445 
       
   446 EXPORT_C void CVeiVideoDisplay::PlayL( 	const TDesC& aFilename,
       
   447 								const TTimeIntervalMicroSeconds& aStartPoint, 
       
   448 								const TTimeIntervalMicroSeconds& aEndPoint )
       
   449 	{
       
   450 	LOGFMT3(KVideoEditorLogFile, "CVeiVideoDisplay::PlayL(): In, aFilename:%S, aStartPoint:%Ld, aEndPoint:%Ld", &aFilename, aStartPoint.Int64(), aEndPoint.Int64());
       
   451 		
       
   452 	if ( iVideoPlayerUtility && iBufferingCompleted)
       
   453 		{
       
   454 		LOG(KVideoEditorLogFile, "CVeiVideoDisplay::PlayL 1");
       
   455 		if ( aEndPoint.Int64() != 0 )
       
   456 			{
       
   457 			LOGFMT2(KVideoEditorLogFile, "CVeiVideoDisplay::Play 2, iStartPoint:%Ld, aStartPoint:%Ld", iStartPoint.Int64(), aStartPoint.Int64());	
       
   458 			iStartPoint = aStartPoint;
       
   459 			//iVideoPlayerUtility->SetPositionL(iStartPoint);
       
   460 			//SizeChanged();
       
   461 			iVideoPlayerUtility->Stop();
       
   462 			iVideoPlayerUtility->Play( aStartPoint, aEndPoint );
       
   463 			}
       
   464 		else
       
   465 			{
       
   466 			LOG(KVideoEditorLogFile, "CVeiVideoDisplay::PlayL 3");	
       
   467 			//SizeChanged();
       
   468 			//iVideoPlayerUtility->Play(iStartPoint, iVideoPlayerUtility->DurationL());
       
   469 			iVideoPlayerUtility->Play();
       
   470 			}
       
   471 		}
       
   472 	else if (!iVideoPlayerUtility && iBufferingCompleted) /* should this be: if (! iVideoPlayerUtility)*/
       
   473 		{		
       
   474 		LOG(KVideoEditorLogFile, "CVeiVideoDisplay::PlayL 4");
       
   475 		if ( aEndPoint.Int64() != 0 )
       
   476 			{
       
   477 			iStartPoint = aStartPoint;
       
   478 			iEndPoint = aEndPoint;	
       
   479 			}	
       
   480 		OpenFileL( aFilename );
       
   481 		}
       
   482 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::PlayL(): out");
       
   483 	}
       
   484 
       
   485 EXPORT_C void CVeiVideoDisplay::PauseL()
       
   486 	{
       
   487 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::PauseL(): in");
       
   488 	if ( iVideoPlayerUtility && iBufferingCompleted )
       
   489 		{
       
   490 		LOG(KVideoEditorLogFile, "CVeiVideoDisplay::PauseL 1, calling pause");
       
   491 		iVideoPlayerUtility->PauseL();
       
   492 		
       
   493 		/*						
       
   494 		//@: for some reason this does not work 
       
   495 		TDisplayMode dmode = EColor64K;		
       
   496 		iVideoPlayerUtility->GetFrameL(dmode, ContentAccess::EPlay);
       
   497 		*/
       
   498 		
       
   499 		/*
       
   500 		//@: do not work either:
       
   501 		LOG(KVideoEditorLogFile, "CVeiVideoDisplay::PauseL(): 2, refreshing");
       
   502 		TInt err = KErrNone;
       
   503 		TRAP(err, iVideoPlayerUtility->RefreshFrameL());
       
   504 		LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::PauseL(): 3, err:%d", err);
       
   505 		*/
       
   506 		}
       
   507 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::PauseL(): out");
       
   508 	}
       
   509 
       
   510 EXPORT_C void CVeiVideoDisplay::OpenFileL( const TDesC& aFilename )
       
   511     {
       
   512 	LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::OpenFileL: In, aFilename:%S", &aFilename);		
       
   513 
       
   514 	/* Calculate regions. */ 
       
   515     TRect screenRect = CalculateVideoPlayerArea();
       
   516 
       
   517 	/* Get the required parameters for the video player. */
       
   518 	CCoeEnv* coeEnv = CCoeEnv::Static();
       
   519 	RWsSession& session = coeEnv->WsSession();
       
   520 	CWsScreenDevice* screenDevice = coeEnv->ScreenDevice();
       
   521 	RDrawableWindow* drawableWindow = DrawableWindow();
       
   522 
       
   523 	if ( iVideoPlayerUtility != NULL )
       
   524 		{
       
   525 		delete iVideoPlayerUtility;
       
   526 		iVideoPlayerUtility = NULL;		
       
   527 		}
       
   528 		
       
   529 	if (!iFilename)
       
   530 		{	
       
   531 		iNewFile = ETrue;
       
   532 		iDuration = TTimeIntervalMicroSeconds(0);
       
   533 		iFilename = aFilename.AllocL();		
       
   534 		}	
       
   535 	else if ((*iFilename).CompareF(aFilename))
       
   536 		{
       
   537 		iNewFile = ETrue;
       
   538 		iDuration = TTimeIntervalMicroSeconds(0);
       
   539 		HBufC* temp = aFilename.AllocL();
       
   540 		delete iFilename;
       
   541 		iFilename = temp;
       
   542 		}
       
   543 
       
   544 	/* Initialize the video player. */
       
   545 	iVideoPlayerUtility = CVideoPlayerUtility::NewL( *this, 
       
   546 	static_cast<enum TMdaPriority>(KAudioPriorityRealOnePlayer),
       
   547 	static_cast<enum TMdaPriorityPreference>(KAudioPrefRealOneLocalPlayback),
       
   548 	session, *screenDevice, *drawableWindow, screenRect, screenRect );
       
   549 
       
   550 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::OpenFileL 2");
       
   551 	iObserver.NotifyVideoDisplayEvent( MVeiVideoDisplayObserver::ELoadingStarted );
       
   552 	iVideoPlayerUtility->RegisterForVideoLoadingNotification( *this );
       
   553 	/* Open the file. */	
       
   554 	iVideoPlayerUtility->OpenFileL( *iFilename );
       
   555 
       
   556 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::OpenFileL: Out");
       
   557     }
       
   558 // ---------------------------------------------------------
       
   559 // CVeiPreviewContainer::MvpuoFrameReady( CFbsBitmap& aFrame, TInt aError )
       
   560 // Notification to the client that the frame requested by a call to GetFrameL is ready.
       
   561 // ---------------------------------------------------------
       
   562 void CVeiVideoDisplay::MvpuoFrameReady( CFbsBitmap& /*aFrame*/, TInt DEBUGLOG_ARG(aError) )
       
   563 	{	
       
   564 	LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::MvpuoFrameReady: In and Out, aError:%d", aError);
       
   565 	/*
       
   566 	@: for some reason this does not work 
       
   567 	if (KErrNone == aError)
       
   568 		{
       
   569 		SetPictureL(aFrame);		
       
   570 		}
       
   571 	DrawDeferred();
       
   572 	*/			
       
   573 	}
       
   574 
       
   575 // ---------------------------------------------------------
       
   576 // CVeiVideoDisplay::MvpuoOpenComplete( TInt aError )
       
   577 // Notification to the client that the opening of the video clip has completed.
       
   578 // ---------------------------------------------------------
       
   579 void CVeiVideoDisplay::MvpuoOpenComplete( TInt aError )
       
   580 	{
       
   581 	LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::MvpuoOpenComplete: In, aError:%d", aError);
       
   582 	if( aError != KErrNone )
       
   583 		{
       
   584 		iObserver.NotifyVideoDisplayEvent( MVeiVideoDisplayObserver::EError );
       
   585 		return;
       
   586 		}
       
   587 	
       
   588 	iVideoPlayerUtility->Prepare();
       
   589 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::MvpuoOpenComplete: Out");
       
   590 	}
       
   591 
       
   592 // ---------------------------------------------------------
       
   593 // CVeiVideoDisplay::MvpuoPlayComplete( TInt aError )
       
   594 // Notification that video playback has completed.
       
   595 // ---------------------------------------------------------
       
   596 void CVeiVideoDisplay::MvpuoPlayComplete( TInt aError )
       
   597 	{
       
   598 	LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::MvpuoPlayComplete:In, aError:%d", aError);
       
   599 	iStartPoint = TTimeIntervalMicroSeconds(0);
       
   600 	/* iBufferingCompleted is set to EFalse in MvloLoadingStarted and set back ETrue in 
       
   601 	   MvloLoadingCompleted.
       
   602 	   If error occurs in the middle of the loading process the latter one is not called and 
       
   603 	   iBufferingCompleted is left to EFalse, that is why is it set to ETrue here also for safety's sake
       
   604 	*/   
       
   605 	iBufferingCompleted = ETrue;
       
   606 	iObserver.NotifyVideoDisplayEvent( MVeiVideoDisplayObserver::EPlayComplete, aError );			
       
   607 	
       
   608 	// Stop() better to be called from iObserver 
       
   609 	/*if ( KErrSessionClosed == aError ) // -45 (10/2006)
       
   610 		{		
       
   611 		Stop( ETrue );
       
   612 		}	
       
   613 		*/
       
   614 
       
   615 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::MvpuoPlayComplete: Out");
       
   616 	}
       
   617 
       
   618 // ---------------------------------------------------------
       
   619 // CVeiPreviewContainer::MvpuoEvent( const TMMFEvent& /*aEvent*/ )
       
   620 // 
       
   621 // ---------------------------------------------------------
       
   622 void CVeiVideoDisplay::MvpuoEvent( const TMMFEvent& aEvent )
       
   623 	{	
       
   624 	LOGFMT2(KVideoEditorLogFile, "CVeiVideoDisplay::MvpuoEvent In, aEvent.iEventType:%d, aEvent.iErrorCode:%d",
       
   625 		aEvent.iEventType.iUid, aEvent.iErrorCode);			
       
   626 	
       
   627 	if (KMMFEventCategoryVideoPlayerGeneralError == aEvent.iEventType  &&
       
   628 		KErrMMAudioDevice == aEvent.iErrorCode)
       
   629 		{
       
   630 		iObserver.NotifyVideoDisplayEvent( MVeiVideoDisplayObserver::EError, aEvent.iErrorCode );	
       
   631 		}
       
   632 	
       
   633 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::MvpuoEvent, Out");	
       
   634 	}
       
   635 
       
   636 // ---------------------------------------------------------
       
   637 // CVeiVideoDisplay::MvpuoPrepareComplete( TInt aError )
       
   638 // Notification to the client that the opening of the video clip has been prepared.
       
   639 // ---------------------------------------------------------
       
   640 void CVeiVideoDisplay::MvpuoPrepareComplete( TInt aError )
       
   641 	{
       
   642 	LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::MvpuoPrepareComplete:In, aError:%d",aError);
       
   643 		
       
   644 	//LocateEntryL();
       
   645 	if( KErrNone != aError )
       
   646 		{		
       
   647 		iObserver.NotifyVideoDisplayEvent( MVeiVideoDisplayObserver::EError, aError );
       
   648 		return;
       
   649 		}
       
   650 
       
   651 	SetPlaybackVolumeL();
       
   652  
       
   653 	SetPositionL(iStartPoint);
       
   654 	iObserver.NotifyVideoDisplayEvent( MVeiVideoDisplayObserver::EOpenComplete, iStartPoint.Int64() );
       
   655 /** If volume is 0(muted) give event so muted icon is drawn to navipane */
       
   656 	if ( iInternalVolume == 0 )
       
   657 		{
       
   658 		LOG(KVideoEditorLogFile, "CVeiVideoDisplay::MvpuoPrepareComplete 1");
       
   659 		iObserver.NotifyVideoDisplayEvent( MVeiVideoDisplayObserver::EVolumeLevelChanged);
       
   660 		}
       
   661 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::MvpuoPrepareComplete: Out");	
       
   662 	}
       
   663 	
       
   664 
       
   665 void CVeiVideoDisplay::LocateEntryL()
       
   666 	{
       
   667 	TInt metaDataCount = iVideoPlayerUtility->NumberOfMetaDataEntriesL();
       
   668 	CMMFMetaDataEntry* entry = NULL;
       
   669 	// Loop through metadata
       
   670 	for ( TInt i = 0; i < metaDataCount; i++ )
       
   671 		{
       
   672 		entry =	iVideoPlayerUtility->MetaDataEntryL( i );		
       
   673 		HBufC* name = entry->Name().AllocLC();
       
   674 		HBufC* value = entry->Value().AllocLC();
       
   675 		LOGFMT3(KVideoEditorLogFile, "CVeiVideoDisplay::LocateEntryL, i:%d, name,value:%S,%S", i, name, value);
       
   676 		CleanupStack::PopAndDestroy( value );
       
   677 		CleanupStack::PopAndDestroy( name );
       
   678 		}		
       
   679 	}
       
   680 
       
   681 void CVeiVideoDisplay::MvloLoadingStarted()
       
   682 	{
       
   683 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::MvloLoadingStarted, In");
       
   684 	iBufferingCompleted = EFalse;
       
   685 	iObserver.NotifyVideoDisplayEvent( MVeiVideoDisplayObserver::EBufferingStarted );
       
   686 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::MvloLoadingStarted, Out");
       
   687 	}
       
   688 
       
   689 void CVeiVideoDisplay::MvloLoadingComplete()
       
   690 	{
       
   691 	LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::MvloLoadingComplete, In, iStartPoint:%Ld", iStartPoint.Int64());
       
   692 	iBufferingCompleted = ETrue;			
       
   693 	iObserver.NotifyVideoDisplayEvent( MVeiVideoDisplayObserver::ELoadingComplete, iStartPoint.Int64() );
       
   694 	// set screen size to play mode
       
   695 	SizeChanged();	
       
   696 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::MvloLoadingComplete, Out");
       
   697 	}
       
   698 
       
   699 void CVeiVideoDisplay::Draw( const TRect& aRect ) const
       
   700 	{
       
   701 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::Draw in");
       
   702     CWindowGc& gc = SystemGc();
       
   703 
       
   704 	TRect rect( Rect() );
       
   705 
       
   706 	rect.Move(iBorderWidth,iBorderWidth);
       
   707 	rect.Resize(-iBorderWidth*2,-iBorderWidth*2);
       
   708 	TSize clipRect( rect.Size() );
       
   709 
       
   710     if ( Window().DisplayMode() == EColor16MA )
       
   711         {
       
   712         gc.SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
       
   713         gc.SetBrushColor(TRgb::Color16MA( 0 ));
       
   714         gc.Clear(aRect);
       
   715         }
       
   716 	
       
   717    	if ( iBlack )
       
   718    		{        
       
   719 /*   		
       
   720    		LOG(KVideoEditorLogFile, "CVeiVideoDisplay::Draw 1");
       
   721         gc.SetPenStyle( CWindowGc::ENullPen );
       
   722 		gc.SetBrushColor( KRgbBlack );
       
   723 		gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   724 		gc.DrawRect( rect );
       
   725 
       
   726         gc.SetPenStyle( CWindowGc::ESolidPen );
       
   727         gc.SetPenSize( TSize(iBorderWidth,iBorderWidth) );
       
   728 	
       
   729 	    gc.DrawRoundRect(aRect, TSize(4,4));
       
   730 */ 
       
   731 		return;
       
   732         }
       
   733 	
       
   734 	if ( iBlank )
       
   735 		{
       
   736 		LOG(KVideoEditorLogFile, "CVeiVideoDisplay::Draw 2");
       
   737 		gc.BitBltMasked( rect.iTl, iBgSquaresBitmap, clipRect, iBgSquaresBitmapMask, EFalse);
       
   738 		}
       
   739 	else
       
   740 		{		
       
   741 		LOG(KVideoEditorLogFile, "CVeiVideoDisplay::Draw 3");
       
   742 
       
   743 		if ( iDisplayBitmap->SizeInPixels() == GetScreenSize() )
       
   744 			{						
       
   745 
       
   746 			gc.BitBlt( rect.iTl, iDisplayBitmap, clipRect);
       
   747 			}
       
   748 		else
       
   749 			{						
       
   750 
       
   751 			TSize clipRectSize = iDisplayBitmap->SizeInPixels();                 
       
   752             TRect destRect;
       
   753             
       
   754             // check which one has bigger aspect ratio, video diplay or thumbnail.
       
   755             TReal displayAR = rect.Width() / TReal(rect.Height());
       
   756             TReal thumbnailAR = clipRectSize.iWidth / TReal(clipRectSize.iHeight);
       
   757             
       
   758             if (thumbnailAR > displayAR)
       
   759                 {
       
   760                 //Create proper destination rect                                    
       
   761                 TInt newHeight = (clipRectSize.iHeight * rect.Width() ) / clipRectSize.iWidth;
       
   762                 TInt newTLiY = rect.iTl.iY + (rect.Height() - newHeight) / 2;
       
   763                 destRect = TRect(TPoint(rect.iTl.iX,newTLiY), TSize(rect.Width(), newHeight));
       
   764                 }
       
   765             else
       
   766                 {
       
   767                 // write here destrect calculation when thumbnailAR < displayAR
       
   768                 TInt newWidth = rect.Height()*thumbnailAR;
       
   769                 TInt newTLiX = rect.iTl.iX + ((rect.Width()-newWidth)/2);
       
   770                 destRect = TRect (TPoint(newTLiX, rect.iTl.iY), TSize(newWidth, rect.Height()));
       
   771                 }
       
   772 		   gc.DrawBitmap( destRect, iDisplayBitmap );
       
   773 			}
       
   774 		}
       
   775 
       
   776 /*
       
   777 	gc.SetPenStyle( CWindowGc::ESolidPen );
       
   778 	gc.SetPenSize( TSize(iBorderWidth,iBorderWidth) );
       
   779 	
       
   780 	rect = Rect();
       
   781 	rect.Resize(-(iBorderWidth-1),-(iBorderWidth-1));
       
   782 	gc.DrawRoundRect( rect, TSize(4,4));
       
   783 */	
       
   784 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::Draw out");
       
   785 	}
       
   786 
       
   787 
       
   788 EXPORT_C TTimeIntervalMicroSeconds CVeiVideoDisplay::TotalLengthL()
       
   789 	{
       
   790 	if ( !iVideoPlayerUtility )
       
   791 		{
       
   792 		return iDuration;	
       
   793 		//return TTimeIntervalMicroSeconds(0);
       
   794 		}
       
   795 	else
       
   796 		{
       
   797 		TRAPD( err, iDuration =iVideoPlayerUtility->DurationL() );
       
   798 		if ( err == KErrNone )
       
   799 			{
       
   800 			return iDuration;
       
   801 			}
       
   802 		else
       
   803 			{
       
   804 			return TTimeIntervalMicroSeconds(0);
       
   805 			}
       
   806 		}
       
   807 	}
       
   808 
       
   809 EXPORT_C void CVeiVideoDisplay::AdjustVolumeL( TInt aIncrement )
       
   810 	{
       
   811 	LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::AdjustVolumeL( %d ): in", aIncrement);
       
   812 
       
   813 	iInternalVolume += aIncrement;
       
   814 
       
   815 	if ( iInternalVolume < 0 )
       
   816 		{
       
   817 		iInternalVolume = 0;
       
   818 		}
       
   819 	if ( iInternalVolume > KMaxVolumeLevel )
       
   820 		{
       
   821 		iInternalVolume = KMaxVolumeLevel;
       
   822 		}
       
   823 
       
   824 	SetPlaybackVolumeL();
       
   825 	iObserver.NotifyVideoDisplayEvent( MVeiVideoDisplayObserver::EVolumeLevelChanged );
       
   826 
       
   827 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::SetVolumeL(): out");
       
   828 	}
       
   829 
       
   830 void CVeiVideoDisplay::SetPlaybackVolumeL()
       
   831 	{
       
   832 	LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::SetPlaybackVolumeL(): in: iInternalVolume: %d", iInternalVolume);
       
   833 
       
   834 	if ( iVideoPlayerUtility )
       
   835 		{
       
   836 		// Convert the internal volume to CVideoPlayerUtility's scale.
       
   837 		iMaxVolume = iVideoPlayerUtility->MaxVolume();
       
   838 
       
   839 		TInt vol = iMaxVolume * iInternalVolume / KMaxVolumeLevel;
       
   840 		iVideoPlayerUtility->SetVolumeL( vol );
       
   841 		}
       
   842 
       
   843 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::SetPlaybackVolumeL(): out");
       
   844 	}
       
   845 
       
   846 EXPORT_C void CVeiVideoDisplay::ShowAnimationL( TInt aResourceId, TInt aFrameIntervalInMilliSeconds )
       
   847 	{
       
   848 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::ShowAnimationL: in");
       
   849 
       
   850 	iAnimationResourceId = aResourceId;
       
   851 
       
   852 	if ( iAnimation )
       
   853 		{
       
   854 		delete iAnimation;
       
   855 		iAnimation = 0;
       
   856 		}
       
   857 	/* In slowmotion video thumbnail is shown */
       
   858 	if ( aResourceId != R_VEI_SLOW_MOTION_ANIMATION )
       
   859 		{
       
   860 		iBlack = ETrue;
       
   861 		DrawNow();
       
   862 		iBlack = EFalse;
       
   863 		}
       
   864 	else
       
   865 		{
       
   866 		DrawNow();
       
   867 		}
       
   868 
       
   869 	// Locate and open the resource file
       
   870     TFileName fileName;
       
   871     TParse p;    
       
   872 
       
   873     Dll::FileName(fileName);
       
   874     p.Set(KResourceFile, &KDC_RESOURCE_FILES_DIR, &fileName);
       
   875     fileName = p.FullName();
       
   876 
       
   877     LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::ShowAnimationL: Loading resource file: %S", &fileName);
       
   878     RConeResourceLoader coneResLoader (*iCoeEnv);
       
   879 	coneResLoader.OpenL( fileName ); // RConeResourceLoader selects the correct language file
       
   880 	CleanupClosePushL( coneResLoader );
       
   881 
       
   882 	// Create animation from resource
       
   883 	iAnimation = CAknBitmapAnimation::NewL();
       
   884 
       
   885 	TResourceReader reader;
       
   886 	iCoeEnv->CreateResourceReaderLC( reader, aResourceId );
       
   887 	iAnimation->ConstructFromResourceL( reader );
       
   888 	TRect rect( Rect() );
       
   889 	rect.Move( iBorderWidth, iBorderWidth );
       
   890 	rect.Resize( -iBorderWidth*2, -iBorderWidth );
       
   891 	iAnimation->SetRect( rect );
       
   892 	iAnimation->SetContainerWindowL( *this );
       
   893 	iAnimationOn = ETrue;
       
   894 	iAnimation->StartAnimationL();
       
   895 	CleanupStack::PopAndDestroy(); //reader
       
   896 	CBitmapAnimClientData* animClientData = iAnimation->BitmapAnimData();
       
   897 	iAnimationFrameIntervalInMilliSeconds = animClientData->FrameIntervalInMilliSeconds();
       
   898 	
       
   899 	CleanupStack::PopAndDestroy(); // coneResLoader
       
   900 
       
   901 	if ( aFrameIntervalInMilliSeconds > 0 )
       
   902 		{
       
   903 		SetFrameIntervalL( aFrameIntervalInMilliSeconds );
       
   904 		}
       
   905 	DrawDeferred();
       
   906 
       
   907 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::ShowAnimationL: out");
       
   908 	}
       
   909 
       
   910 EXPORT_C void CVeiVideoDisplay::StopAnimation()
       
   911 	{
       
   912 	if ( iAnimationOn )
       
   913 		{
       
   914 		iAnimation->CancelAnimation();
       
   915 		}
       
   916 	iAnimationOn = EFalse;
       
   917 	DrawDeferred();
       
   918 	}
       
   919 
       
   920 EXPORT_C void CVeiVideoDisplay::SetFrameIntervalL(TInt aFrameIntervalInMilliSeconds)
       
   921 	{
       
   922 	iAnimationFrameIntervalInMilliSeconds+=aFrameIntervalInMilliSeconds;
       
   923 	iAnimation->SetFrameIntervalL( iAnimationFrameIntervalInMilliSeconds );
       
   924 	}
       
   925 
       
   926 void CVeiVideoDisplay::HandleResourceChange(TInt aType)
       
   927 	{
       
   928 	if( (aType == KEikMessageFadeAllWindows) && iAnimationOn )
       
   929 		{
       
   930 		iAnimation->CancelAnimation();
       
   931 		}
       
   932 	else if( (aType == KEikMessageUnfadeWindows) && iAnimationOn )
       
   933 		{
       
   934 		TRAPD(err, iAnimation->StartAnimationL() );
       
   935 		if( KErrNone != err )
       
   936 			{
       
   937 			LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::HandleResourceChange: StartAnimationL failed: %d", err);
       
   938 			iObserver.NotifyVideoDisplayEvent( MVeiVideoDisplayObserver::EError );
       
   939 			}
       
   940 		}
       
   941 	}
       
   942 
       
   943 EXPORT_C TInt CVeiVideoDisplay::Volume() const
       
   944 	{
       
   945 	return iInternalVolume;
       
   946 	}
       
   947 	
       
   948 EXPORT_C void CVeiVideoDisplay::SetMuteL( TBool aMuted )
       
   949 	{
       
   950 	iMuted = aMuted;	
       
   951 	}
       
   952 
       
   953 //=======================================================================================================
       
   954 void CVeiVideoDisplay::HandleLosingForeground()
       
   955 	{
       
   956 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::HandleLosingForeground(): In");
       
   957 
       
   958 	if( iAnimationOn )
       
   959 		{
       
   960 		LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::HandleLosingForeground(): stopping animation. iAnimationFrameIntervalInMilliSeconds == %d", iAnimationFrameIntervalInMilliSeconds);
       
   961 
       
   962 		// Delete the animation when going to backgroung. This should not be necessary, there are some
       
   963 		// platforms where the bitmap animation works incorrectly when swithching back (see EFLI-6VL4JS)
       
   964 		iStoredAnimationFrameIntervalInMilliSeconds = iAnimationFrameIntervalInMilliSeconds;
       
   965 		delete iAnimation;
       
   966 		iAnimation = NULL;
       
   967 		}
       
   968 
       
   969 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::HandleLosingForeground(): Out");
       
   970 	}
       
   971 
       
   972 //=======================================================================================================
       
   973 void CVeiVideoDisplay::HandleGainingForeground()
       
   974 	{
       
   975 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::HandleGainingForeground(): In");
       
   976 
       
   977 	if( iAnimationOn )
       
   978 		{
       
   979 		TRAPD(err, ShowAnimationL( iAnimationResourceId, 0 ));
       
   980 		if( KErrNone == err )
       
   981 			{
       
   982 			// restore the animation speed
       
   983 			LOGFMT2(KVideoEditorLogFile, "CVeiVideoDisplay::HandleLosingForeground(): animation started. next restoring speed to %d (now it is %d)", iStoredAnimationFrameIntervalInMilliSeconds, iAnimationFrameIntervalInMilliSeconds);
       
   984 			iAnimationFrameIntervalInMilliSeconds = iStoredAnimationFrameIntervalInMilliSeconds;
       
   985 			// set the animation's frame interval via callback. if set directly after starting the
       
   986 			// animation, the rate change does not take effect on screen.
       
   987 			SetAnimationFrameIntervalCallbackL();
       
   988 			}
       
   989 		else
       
   990 			{
       
   991 			LOGFMT(KVideoEditorLogFile, "CVeiVideoDisplay::SizeChanged: HandleGainingForeground failed: %d", err);
       
   992 			iObserver.NotifyVideoDisplayEvent( MVeiVideoDisplayObserver::EError );
       
   993 			}
       
   994 		}
       
   995 
       
   996 	LOG(KVideoEditorLogFile, "CVeiVideoDisplay::HandleGainingForeground: Out");
       
   997 	}
       
   998 
       
   999 //=======================================================================================================
       
  1000 void CVeiVideoDisplay::SetAnimationFrameIntervalCallbackL()
       
  1001 	{
       
  1002 	LOG( KVideoEditorLogFile, "CVeiVideoDisplay::DoSetAnimationFrameIntervalL: in");
       
  1003 
       
  1004 	if (! iCallBack)
       
  1005 		{		
       
  1006 		TCallBack cb (CVeiVideoDisplay::SetAnimationFrameIntervalCallbackMethod, this);
       
  1007 		iCallBack = new (ELeave) CAsyncCallBack(cb, CActive::EPriorityLow);
       
  1008 		}
       
  1009 	iCallBack->CallBack();
       
  1010 
       
  1011 	LOG( KVideoEditorLogFile, "CVeiVideoDisplay::DoSetAnimationFrameIntervalL: out");
       
  1012 	}
       
  1013 
       
  1014 //=======================================================================================================
       
  1015 TInt CVeiVideoDisplay::SetAnimationFrameIntervalCallbackMethod(TAny* aThis)
       
  1016 	{
       
  1017     LOG( KVideoEditorLogFile, "CVeiVideoDisplay::SetAnimationFrameIntervalCallbackMethod");
       
  1018 
       
  1019 	CVeiVideoDisplay* me = static_cast<CVeiVideoDisplay*>(aThis);
       
  1020 	TRAPD( err, me->SetFrameIntervalL( 0 ) );
       
  1021 	
       
  1022 	return err;
       
  1023 	}
       
  1024 
       
  1025 // End of File