📄 vrexvideocontainer.cpp
字号:
/*
* ============================================================================
* Name : CVRexVideoContainer from VRexVideoContainer.cpp
* Part of : Video Example
* Created : 30/08/2006 by Forum Nokia
* Implementation notes:
* Version : 2.0
* Copyright: Nokia Corporation, 2006
* ============================================================================
*/
// INCLUDE FILES
#include <eikmenup.h>
#include <documenthandler.h>
#include <apmstd.h>
#include <aknnavi.h>
#include <aknnavide.h>
#include <stringloader.h>
#include "VRexVideoContainer.h"
#include "VRexNaviDecoratorTime.h"
#include "VRexViewFinder.h"
#include <avkon.hrh>
#include <avkon.rsg>
#include <VRex.rsg>
#include "VRex.hrh"
const TInt KBufSize = 16;
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CVRexVideoContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CVRexVideoContainer::ConstructL(const TRect& aRect,
CVRexVideoView* aView, CVRexEngine* aEngine)
{
iEngine = aEngine;
iView = aView;
CreateWindowL();
// Show tabs for main views from resources
CEikStatusPane* sp = iEikonEnv->AppUiFactory()->StatusPane();
iNaviPane = (CAknNavigationControlContainer *)sp->
ControlL(TUid::Uid(EEikStatusPaneUidNavi));
iTimeNavi = CreateTimeNaviL();
iNaviPane->PushL(*iTimeNavi);
// Read time format strings from AVKON resource
iMinSecFormatString =
iEikonEnv->AllocReadResourceL(R_QTN_TIME_DURAT_MIN_SEC);
iHourMinSecFormatString =
iEikonEnv->AllocReadResourceL(R_QTN_TIME_DURAT_LONG);
// Create video view finder
iFinder = new (ELeave) CVideoViewFinder();
iFinder->SetContainerWindowL(*this);
iFinder->ConstructL(0); // Use the first camera
// Set window size
SetRect(aRect);
// Set up the video player rectangle
iVideoRect = Rect();
TPoint point = PositionRelativeToScreen();
iVideoRect.iTl.iX += point.iX;
iVideoRect.iTl.iY += point.iY;
iVideoRect.iBr.iX += point.iX;
iVideoRect.iBr.iY += point.iY;
iVideoRect.Shrink(1, 1);
ActivateL();
}
// Destructor
CVRexVideoContainer::~CVRexVideoContainer()
{
delete iTimeNavi;
iTimeNavi = NULL;
delete iMinSecFormatString;
iMinSecFormatString = NULL;
delete iHourMinSecFormatString;
iHourMinSecFormatString = NULL;
if(iFinder)
{
delete iFinder;
iFinder = NULL;
}
}
// ---------------------------------------------------------
// CVRexVideoContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CVRexVideoContainer::SizeChanged()
{
if(iFinder)
{
iFinder->SetRect(Rect());
}
}
// ---------------------------------------------------------
// CVRexVideoContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CVRexVideoContainer::CountComponentControls() const
{
return 1; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CVRexVideoContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CVRexVideoContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iFinder;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CVRexVideoContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CVRexVideoContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbGray );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( aRect );
}
// ---------------------------------------------------------
// CVRexVideoContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CVRexVideoContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
// Add your control event handler code here
}
/*
-----------------------------------------------------------------------------
CAknNavigationDecorator* CVRexVideoContainer::CreateTimeNaviL()
Description: This method creates time display navigation decorator.
Comments :
Return values: CAknNavigationDecorator object pointer
-----------------------------------------------------------------------------
*/
CAknNavigationDecorator* CVRexVideoContainer::CreateTimeNaviL()
{
CVideoNaviDecoratorTime* timeNavi = CVideoNaviDecoratorTime::NewL();
CleanupStack::PushL(timeNavi);
CAknNavigationDecorator* decoratedFolder =
CAknNavigationDecorator::NewL(iNaviPane, timeNavi,
CAknNavigationDecorator::ENotSpecified);
CleanupStack::Pop(timeNavi); // timeNavi, decoratedFolder owns it now.
CleanupStack::PushL(decoratedFolder);
decoratedFolder->SetContainerWindowL(*iNaviPane);
timeNavi->SetContainerWindowL(*decoratedFolder);
CleanupStack::Pop(decoratedFolder); // decoratedFolder
decoratedFolder->MakeScrollButtonVisible(EFalse);
return decoratedFolder;
}
/*
-----------------------------------------------------------------------------
void CVRexVideoContainer::SetNaviLabelL(const TDesC &aLabel)
Description: This method sets navigation decorator label.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVRexVideoContainer::SetNaviLabelL(const TDesC &aLabel)
{
CVideoNaviDecoratorTime* timeNavi =
static_cast<CVideoNaviDecoratorTime*>(iTimeNavi->DecoratedControl());
timeNavi->SetLabelL(aLabel);
}
/*
-----------------------------------------------------------------------------
TKeyResponse CVRexVideoContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aType)
Description: This method handles key events.
Comments :
Return values: TKeyResponse
-----------------------------------------------------------------------------
*/
TKeyResponse CVRexVideoContainer::OfferKeyEventL(
const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
{
// See if we have a selection
TInt code = aKeyEvent.iCode;
switch(code)
{
// is navigator button pressed
case EKeyOK:
{
if(iEngine->EngineState()==CVRexEngine::EPreview)
{
iView->DoRecordL();
return (EKeyWasConsumed);
}
else if(iEngine->EngineState()==CVRexEngine::EPlay)
{
if(iEngine->iVPlayer->State() == CVideoPlayerAdapter::EPlaying)
iView->DoPauseL();
else
iView->DoResumeL();
return (EKeyWasConsumed);
}
else if (iEngine->EngineState()==CVRexEngine::ERecord)
{
iView->DoStopL();
return (EKeyWasConsumed);
}
else
return (EKeyWasConsumed);
}
default:
break;
}
return EKeyWasNotConsumed;
}
/*
-----------------------------------------------------------------------------
void CVRexVideoContainer::InitControllerCompletedL(TInt aError)
Description: Controller initialization completed.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVRexVideoContainer::InitControllerCompletedL(TInt /*aError*/)
{
// Play the video
iEngine->iVPlayer->PlayL();
}
/*
-----------------------------------------------------------------------------
void CVRexVideoContainer::PlayCompletedL(TInt aError)
Description: Video clip playback completed.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVRexVideoContainer::PlayCompletedL(TInt /*aError*/)
{
// The play has been completed, we need to refresh the display now.
DrawNow();
SetNaviLabelL(KNullDesC);
// Refresh the directory listing
iView->HandleCommandL(EVRexCmdAppReturn);
}
/*
-----------------------------------------------------------------------------
void CVRexVideoContainer::RecordCompletedL(TInt aError)
Description: Video clip record completed.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVRexVideoContainer::RecordCompletedL(TInt /*aError*/)
{
iFinder->Stop();
// The recording has been completed, we need to refresh the display now.
DrawNow();
SetNaviLabelL(KNullDesC);
// Refresh the directory listing
iView->HandleCommandL(EVRexCmdAppReturn);
}
/*
-----------------------------------------------------------------------------
void CVRexVideoContainer::PlaybackPositionChangedL(TInt64 aPlaybackPosInSeconds,
TInt64 aTotalLengthInSeconds)
Description: Video clip position changed.
Comments : If aTotalLenght is 0, only position is displayed (used in
reporting position in recording or if total length is not
known)
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVRexVideoContainer::PlaybackPositionChangedL(TInt64 aPlaybackPosInSeconds,
TInt64 aTotalLengthInSeconds)
{
TTime posTime = TTime(aPlaybackPosInSeconds*KMPOneSecond);
TTime durTime = TTime(aTotalLengthInSeconds*KMPOneSecond);
TBuf<KBufSize> pos;
TBuf<KBufSize> dur;
if(aTotalLengthInSeconds > 0 && aTotalLengthInSeconds < KOneHourInSeconds)
{
// Format time to user readable format. (min:sec)
posTime.FormatL(pos, *iMinSecFormatString);
durTime.FormatL(dur, *iMinSecFormatString);
}
else
{
// Format time to user readable format. (hour:min:sec)
posTime.FormatL(pos, *iHourMinSecFormatString);
aTotalLengthInSeconds = 0;
}
// If duration greater than 0, show postion in 00:00/00:00 format
if (aTotalLengthInSeconds > 0)
{
CDesCArrayFlat* strings = new (ELeave) CDesCArrayFlat(2);
CleanupStack::PushL(strings);
strings->AppendL(pos); //First string (position)
strings->AppendL(dur); //Second string (duration)
HBufC* stringholder = StringLoader::LoadLC(R_VREX_NAVI_TIME,*strings,iEikonEnv);
static_cast<CVideoNaviDecoratorTime*>
(iTimeNavi->DecoratedControl())->SetLabelL(*stringholder);
CleanupStack::PopAndDestroy(stringholder);
CleanupStack::PopAndDestroy(strings);
}
else // Show position in 00:00:00 format
{
static_cast<CVideoNaviDecoratorTime*>
(iTimeNavi->DecoratedControl())->SetLabelL(pos);
}
}
// End of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -