×
Namespaces

Variants
Actions

How to play a video file using CVideoPlayerUtility

From Nokia Developer Wiki
Jump to: navigation, search

This code example shows how to play a video on Symbian using the CVideoPlayerUtility API.

Article Metadata
Code ExampleArticle
Created: samiudd (30 May 2007)
Last edited: hamishwillee (14 Jun 2013)

Contents

Introduction

In the code given below, MediaEngine is the file containing the implementation of NewL() of CVideoPlayerUtility which constructs, initialises and returns pointers to instances of concrete classes. MediaEngine is derived from MVideoPlayerUtilityObserver which is an interface to a set of video player callback functions.

The MediaContainer is derived from CCoeControl and contains inline functions which gives screen devices, client window etc, for playing the video file. For further understanding of CVideoPlayerUtility, check the SDK documentation.

To use the volume keys in some devices (for example to increase/decrease the volume) see this article: TSS000432 - Utilising media keys

MediaEngine.cpp

_LIT(KDirVideos,"c:\\filename.rm");
CMediaEngine * CMediaEngine :: NewL(CMediaContainer* aView)
{
CMediaEngine * self = new (ELeave) CMediaEngine ();
CleanupStack::PushL( self);
self->ConstructL(aView );
CleanupStack::Pop();
return self;
}
void CMediaEngine ::ConstructL(CMediaContainer* aView)
{
iView = aView;
}
CMediaEngine ::CMediaEngine ():iPlayer(NULL)
{
 
}
CMediaEngine ::~CMediaEngine ()
{
if (iPlayer != NULL)
{
delete iPlayer;
iPlayer = NULL;
}
}
 
void CMediaEngine ::InitControllerL()
{
iPlayer = NULL;
iPlayer = CVideoPlayerUtility::NewL(*this,EMdaPriorityNormal,
EMdaPriorityPreferenceNone,
iView->ClientWsSession(),
iView->ScreenDevice(),
iView->ClientWindow(),
iView->VideoRect(),
iView->VideoRect() );
iPlayer->OpenFileL( KDirVideos);
}
void CMediaEngine ::MvpuoPrepareComplete(TInt aError )
{
iPlayer->Play();
}
void CMediaEngine ::MvpuoEvent(const TMMFEvent& aEvent)
{
// do nothing..
}
void CMediaEngine ::MvpuoPlayComplete(TInt aError)
{
// do nothing...
}
void CMediaEngine ::MvpuoFrameReady(CFbsBitmap& /*aFrame*/,TInt /*aError*/)
{
// do nothing...
}
void CMediaEngine ::MvpuoOpenComplete(TInt aError)
{
iPlayer->Prepare();
}
void CMediaEngine ::PauseL()
{
iPlayer->PauseL();
}
void CMediaEngine::IncreaseVolume()
{
TInt maxVol = iPlayer->MaxVolume();
TInt vol = iPlayer->Volume();
 
if(vol < maxVol)
iPlayer->SetVolumeL(vol + 10); //Only multiples of 10!! Other values are not good on N95
}
void CMediaEngine::DecreaseVolume()
{
TInt vol = iPlayer->Volume();
if(vol > 0)
iPlayer->SetVolumeL(vol - 10); //Again, please use multiple of 10 to avoid problems
}
TTimeIntervalMicroSeconds CMediaEngine ::PositionL()
{
return iPlayer->PositionL();
}
TTimeIntervalMicroSeconds CMediaEngine ::DurationL()
{
return iPlayer->DurationL();
}
void CMediaEngine ::Stop()
{
iPlayer->Stop();
}

MediaEngine.h

      #include <videoplayer.h>
class CMediaEngine : public CBase ,public MVideoPlayerUtilityObserver
{
public:
CMediaEngine ();
void ConstructL(CMediaContainer* aView);
static CMediaEngine * NewL(CMediaContainer* aView );
void InitControllerL();
void MvpuoOpenComplete(TInt aError);
void MvpuoPrepareComplete(TInt aError);
void MvpuoFrameReady(CFbsBitmap& aFrame,TInt aError);
void MvpuoPlayComplete(TInt aError);
void MvpuoEvent(const TMMFEvent& aEvent);
void PauseL();
void IncreaseVolume();
void DecreaseVolume();
TTimeIntervalMicroSeconds PositionL() ;
TTimeIntervalMicroSeconds DurationL() ;
void Stop();
~CMediaEngine ();
private:
CVideoPlayerUtility* iPlayer;
CMediaContainer* iView;
};

MediaContainer.cpp

CMediaContainer* CMediaContainer::NewL(const TRect& aRect)
{
CMediaContainer* self = CMediaContainer::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
CMediaContainer* CMediaContainer::NewLC(const TRect& aRect)
{
CMediaContainer* self = new (ELeave) CMediaContainer;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
CMediaContainer::CMediaContainer()
{
// no implementation required
}
CMediaContainer::~CMediaContainer()
{
// no implementation required
}
void CMediaContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
SetRect(aRect);
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;
ActivateL();
}
void CMediaContainer::Draw(const TRect& /*aRect*/) const
{
CWindowGc& gc = SystemGc();
gc.SetBrushColor(KRgbBlack);
gc.SetBrushStyle (CGraphicsContext::ESolidBrush);
TRect rect = Rect();
gc.Clear(rect);
}

MediaContainer.h

class CMediaContainer : public CCoeControl
{
public:
static CMediaContainer* NewL(const TRect& aRect);
static CMediaContainer* NewLC(const TRect& aRect);
void ConstructL(const TRect& aRect);
CMediaContainer();
~CMediaContainer();
public:
void Draw(const TRect& aRect) const;
inline RWindow& ClientWindow();
inline TRect VideoRect() const;
inline RWsSession& ClientWsSession();
inline CWsScreenDevice& ScreenDevice();
private:
TRect iVideoRect;
};
 
inline RWindow& CMediaContainer::ClientWindow()
{
return Window();
}
inline TRect CMediaContainer::VideoRect() const
{
return iVideoRect;
}
inline RWsSession& CMediaContainer::ClientWsSession()
{
return ControlEnv()->WsSession();
}
inline CWsScreenDevice& CMediaContainer::ScreenDevice()
{
return *(ControlEnv()->ScreenDevice());
}

MMP file

To link symbols add the following entry to the MMP file.

   LIBRARY        mediaclientvideo.lib

Example source code

This page was last modified on 14 June 2013, at 07:53.
85 page views in the last 30 days.