Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 00:10, 22 April 2008.

How to play a video file using CVideoPlayerUtility

From Forum Nokia Wiki

This code can be used to play a video file using "CVideoPlayerUtility" API. In the example code 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.

Contents

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();
    }
TTimeIntervalMicroSeconds  CMediaEngine ::PositionL()
    {
     return iPlayer->PositionL();
    }
TTimeIntervalMicroSeconds CMediaEngine ::DurationL()
    {
     return iPlayer->DurationL();
    }
void CMediaEngine ::Stop()
    {
     iPlayer->Stop();
    }


MediaEngine.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();
          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);
    }

MediaContaincer.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());
    }
Related Discussions
Thread Thread Starter Forum Replies Last Post
Playing video on incoming call (Symbian 9) rdx83 General Symbian C++ 0 2006-08-16 09:10
Audio/Video encapsulation in a .3gp file eranga General Messaging 2 2002-12-05 11:42
Help!!!How to use OpenDesL() to play video data in buffer? LIONYCQ Symbian Media (Graphics & Sounds) 0 2007-10-07 12:15
video play clip moving coxcom General Symbian C++ 4 2006-05-19 17:27
Video snapshot muntain Symbian Media (Graphics & Sounds) 0 2007-02-05 07:53
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZseriesE5f60Q
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX