📄 vrexplayeradapter.cpp
字号:
/*
* ============================================================================
* Name : CVideoPlayerAdapter from VRexPlayerAdapter.cpp
* Part of : Video Example
* Created : 30/08/2006 by Forum Nokia
* Implementation notes:
* Version : 2.0
* Copyright: Nokia Corporation, 2006
* ============================================================================
*/
// INCLUDE FILES
#include <eikenv.h>
#include <VideoPlayer.h>
#include <mmferrors.h>
#include <documenthandler.h>
#include <f32file.h>
#include "VRexPlayerAdapter.h"
#include "VRexFileDetails.h"
#include "MPlayerUIControllerListener.h"
/*
-----------------------------------------------------------------------------
CVideoPlayerAdapter* CVideoPlayerAdapter::NewL()
Description: Two-phased constructor.
Comments :
Return values: CVideoPlayerAdapter object pointer
-----------------------------------------------------------------------------
*/
CVideoPlayerAdapter* CVideoPlayerAdapter::NewL()
{
CVideoPlayerAdapter* self = CVideoPlayerAdapter::NewLC();
CleanupStack::Pop(self);
return self;
}
/*
-----------------------------------------------------------------------------
CVideoPlayerAdapter* CVideoPlayerAdapter::NewLC()
Description: Two-phased constructor.
Comments : Method leaves pointer to object in cleanup stack
Return values: CVideoPlayerAdapter object pointer
-----------------------------------------------------------------------------
*/
CVideoPlayerAdapter* CVideoPlayerAdapter::NewLC()
{
CVideoPlayerAdapter* self = new (ELeave) CVideoPlayerAdapter();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/*
-----------------------------------------------------------------------------
void CVideoPlayerAdapter::ConstructL()
Description: Second phase constructor.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVideoPlayerAdapter::ConstructL()
{
iMediaFile = HBufC::NewL(0);
// Create a progress updater
iFileDetails = new (ELeave) CVideoFileDetails;
iProgressUpdater = CHeartbeat::NewL(0);
}
/*
-----------------------------------------------------------------------------
CVideoPlayerAdapter::CVideoPlayerAdapter()
Description: Default constructor.
Comments : Constructor may never leave
Return values: N/A
-----------------------------------------------------------------------------
*/
CVideoPlayerAdapter::CVideoPlayerAdapter() :
iState(ENotInitialized)
{
}
/*
-----------------------------------------------------------------------------
CVideoPlayerAdapter::~CVideoPlayerAdapter()
Description: Destructor.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
CVideoPlayerAdapter::~CVideoPlayerAdapter()
{
delete iDocHandler;
iDocHandler = NULL;
delete iMediaFile;
iMediaFile = NULL;
delete iFileDetails;
iFileDetails = NULL;
delete iProgressUpdater;
iProgressUpdater = NULL;
delete iPlayer;
iPlayer = NULL;
}
/*
-----------------------------------------------------------------------------
void CVideoPlayerAdapter::InitControllerL(MPlayerUIControllerListener* aControllerListener,
RWsSession& aWs,
CWsScreenDevice& aScreenDevice,
RWindowBase& aWindow,
TRect& aScreenRect,
TRect& aClipRect)
Description: This method initializes the video player controller.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVideoPlayerAdapter::InitControllerL(
MPlayerUIControllerListener* aControllerListener,
RWsSession& aWs,
CWsScreenDevice& aScreenDevice,
RWindowBase& aWindow,
TRect& aScreenRect,
TRect& aClipRect)
{
iState = EInitializing;
iCtrlrListener = aControllerListener;
if (iPlayer)
{
delete iPlayer;
iPlayer = NULL;
};
iPlayer = CVideoPlayerUtility::NewL(*this, EMdaPriorityNormal,
EMdaPriorityPreferenceNone, aWs,
aScreenDevice,aWindow,aScreenRect,
aClipRect);
TRAPD(unsupported, iPlayer->OpenFileL(iMediaFile->Des()));
if(unsupported!=KErrNone)
{
iPlayer->Close();
delete iPlayer;
iPlayer = NULL;
// Clear the status pane
iCtrlrListener->PlayCompletedL(KErrNotSupported);
User::Leave(unsupported);
}
}
/*
-----------------------------------------------------------------------------
void CVideoPlayerAdapter::SetNewFileL(const TDesC& aFileName)
Description: This method sets new file name to play.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVideoPlayerAdapter::SetNewFileL(const TDesC& aFileName)
{
HBufC* newFile = aFileName.AllocL();
delete iMediaFile; // after the AllocL succeeds
iMediaFile = newFile;
}
/*
-----------------------------------------------------------------------------
void CVideoPlayerAdapter::PlayL()
Description: This method plays the video file.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVideoPlayerAdapter::PlayL()
{
// If the engine is not in the paused state, start the progress update.
if(!iProgressUpdater->IsActive())
{
iProgressUpdater->Start(ETwelveOClock,this);
}
iPlayer->Play();
switch(iState)
{
case EStopped:
{
iPlayPosition = 0;
iCtrlrListener->PlaybackPositionChangedL(iPlayPosition,
iFileDetails->iDurationInSeconds);
break;
}
case EPaused:
iCtrlrListener->PlaybackPositionChangedL(iPlayPosition,
iFileDetails->iDurationInSeconds);
break;
default:
break;
}
iState = EPlaying;
}
/*
-----------------------------------------------------------------------------
void CVideoPlayerAdapter::PauseL()
Description: This method pauses the playback of video file.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVideoPlayerAdapter::PauseL()
{
if(iState == EPlaying)
{
if(iProgressUpdater->IsActive())
{
iProgressUpdater->Cancel();
}
iPlayer->PauseL();
iState = EPaused;
}
}
/*
-----------------------------------------------------------------------------
void CVideoPlayerAdapter::Stop()
Description: This method stops the playback of video file.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVideoPlayerAdapter::Stop()
{
if(iState != EPlaying && iState != EPaused)
return;
iProgressUpdater->Cancel();
iPlayPosition = 0;
iPlayer->Stop();
iPlayer->Close();
iState = EStopped;
//release resources
if (iPlayer)
{
delete iPlayer;
iPlayer = NULL;
};
if ( iCtrlrListener )
{
TRAPD(ignored, iCtrlrListener->PlayCompletedL(KErrNone));
}
}
/*
-----------------------------------------------------------------------------
void CVideoPlayerAdapter::MvpuoOpenComplete(TInt aError)
Description: This method defines required client behaviour when an attempt to open
a video sample has completed, successfully or otherwise.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVideoPlayerAdapter::MvpuoOpenComplete(TInt aError)
{
if(aError==KErrNone)
{
// Prepare for the loading the file
iPlayer->Prepare();
}
else
{
// Stop the heart beat and close the player
Stop();
}
}
/*
-----------------------------------------------------------------------------
void CVideoPlayerAdapter::MvpuoPrepareComplete(TInt aError)
Description: Notification that video player is ready to begin playback.
Comments : This callback is generated in response to a call to Prepare
in CVideoPlayerUtility
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVideoPlayerAdapter::MvpuoPrepareComplete(TInt aError)
{
iFileDetails->iDurationInSeconds = 0;
if(aError == KErrNone || aError == KErrMMPartialPlayback)
{
TSize size( 0, 0 );
TRAPD(ignored,
iPlayer->VideoFrameSizeL(size);
iFileDetails->iResolutionHeight = size.iHeight;
iFileDetails->iResolutionWidth = size.iWidth;
// Check if audio
iFileDetails->iAudioTrack = iPlayer->AudioEnabledL();
// Video track
iFileDetails->iVideoTrack = iPlayer->VideoBitRateL();
// Duration of the video clip
iFileDetails->iDurationInSeconds =
iPlayer->DurationL().Int64() / KMPOneSecond;
);
}
if ( iCtrlrListener )
{
TRAPD(ignored,iCtrlrListener->InitControllerCompletedL(aError));
}
}
/*
-----------------------------------------------------------------------------
void CVideoPlayerAdapter::MvpuoPlayComplete(TInt aError)
Description: This method defines required client behaviour when an attempt to
play a video sample has completed, successfully or otherwise.
Comments : This method is not called if playback is explicitly stopped by
calling Stop in CVideoPlayerUtility.
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVideoPlayerAdapter::MvpuoPlayComplete(TInt aError)
{
if (iProgressUpdater->IsActive())
{
iProgressUpdater->Cancel();
}
iPlayPosition = 0;
iState = EStopped;
iPlayer->Close();
//release resources
if (iPlayer)
{
delete iPlayer;
iPlayer = NULL;
};
if ( iCtrlrListener )
{
// Pass the error forward
TRAPD(ignored, iCtrlrListener->PlayCompletedL(aError));
}
}
/*
-----------------------------------------------------------------------------
void CVideoPlayerAdapter::MvpuoFrameReady(CFbsBitmap& aFrame,TInt aError)
Description: Defines required client behaviour when a request to capture a
frame is made using CVideoPlayerUtility::GetFrame().
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVideoPlayerAdapter::MvpuoFrameReady(CFbsBitmap& /*aFrame*/,TInt /*aError*/)
{
}
/*
-----------------------------------------------------------------------------
void CVideoPlayerAdapter::Beat()
Description: This method handles a regular heartbeat timer event. This type of
event is one where the timer completes in synchronisation with the
system clock.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVideoPlayerAdapter::Beat()
{
// Keep backlights on if clip has video
if(iFileDetails->iVideoTrack)
{
User::ResetInactivityTime();
}
if(iState != EPlaying)
return;
TInt64 ret = iPlayPosition%2;
#ifndef __SERIES60_3X__
if(ret.GetTInt())
#else
if((TInt)ret)
#endif
{
iPlayPosition = iPlayPosition + 1;
if(iCtrlrListener)
{
TRAPD(ignored,iCtrlrListener->PlaybackPositionChangedL(iPlayPosition,
iFileDetails->iDurationInSeconds));
}
}
else
{
Synchronize();
}
}
/*
-----------------------------------------------------------------------------
void CVideoPlayerAdapter::Synchronize()
Description: This method synchronises the heartbeat timer with system clock.
Comments : This function handles a heartbeat timer event where the
timer completes out of synchronisation with the system clock,
(i.e. one or more heartbeats have been missed).
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVideoPlayerAdapter::Synchronize()
{
if ( iState != EPlaying )
return;
TRAPD(ignored,
// If live stream, fake progress
iPlayPosition = iPlayer->PositionL().Int64() / KMPOneSecond;
if(iCtrlrListener)
{
iCtrlrListener->PlaybackPositionChangedL(iPlayPosition,
iFileDetails->iDurationInSeconds);
}
);
}
/*
-----------------------------------------------------------------------------
CDocumentHandler& CVideoPlayerAdapter::DocumentHandlerL()
Description: This method returns a document handler.
Comments :
Return values: Document handler
-----------------------------------------------------------------------------
*/
CDocumentHandler& CVideoPlayerAdapter::DocumentHandlerL()
{
if( !iDocHandler )
{
#ifdef __SERIES60_3X__
iDocHandler = CDocumentHandler::NewL();
#else
iDocHandler = CDocumentHandler::NewL( CEikonEnv::Static()->Process() );
#endif
}
return *iDocHandler;
}
/*
-----------------------------------------------------------------------------
void CVideoPlayerAdapter::MvpuoEvent(const TMMFEvent& aEvent)
Description: Mvpuo Event comes in.
Comments :
Return values: N/A
-----------------------------------------------------------------------------
*/
void CVideoPlayerAdapter::MvpuoEvent(const TMMFEvent& aEvent)
{
// Higher priority application has taken over the audio device --> Do pause.
if (aEvent.iEventType == KMMFEventCategoryVideoPlayerGeneralError &&
aEvent.iErrorCode == KErrHardwareNotAvailable)
{
TRAPD(ignored,iCtrlrListener->PlayCompletedL(EErrAudioLost));
}
}
// End of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -