examples/sfexamples/GfxWorkbench/src/GfxVideoPlayer.cpp

00001 /*
00002 Copyright (c) 2002-2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 #include "GfxVideoPlayer.h"
00030 
00031 #include <EIKENV.H>
00032 
00033 _LIT(KVideoFileName,"c:\\data\\video\\videotest.3gp");
00034 
00035 CGfxVideoPlayer * CGfxVideoPlayer :: NewL(CVideoPlayerControl* aView)
00036 {
00037      CGfxVideoPlayer * self = new (ELeave) CGfxVideoPlayer ();
00038      CleanupStack::PushL( self);
00039      self->ConstructL(aView );
00040      CleanupStack::Pop();
00041      return self;
00042     }
00043 void CGfxVideoPlayer ::ConstructL(CVideoPlayerControl* aView)
00044    {
00045     iView = aView;
00046    }
00047 CGfxVideoPlayer ::CGfxVideoPlayer ():iPlayer(NULL)
00048    {
00049  
00050    }
00051 CGfxVideoPlayer ::~CGfxVideoPlayer ()
00052    {
00053         delete iPlayer, iPlayer = NULL; 
00054     }
00055  
00056 void CGfxVideoPlayer ::InitControllerL()   
00057     {
00058      iPlayer = NULL;
00059      iPlayer = CVideoPlayerUtility::NewL(*this,EMdaPriorityNormal,
00060                                         EMdaPriorityPreferenceNone,
00061                                         iView->ClientWsSession(),
00062                                         iView->ScreenDevice(),
00063                                         iView->ClientWindow(),
00064                                         iView->VideoRect(),
00065                                         iView->VideoRect() );
00066      iPlayer->OpenFileL( KVideoFileName);
00067     }
00068 void CGfxVideoPlayer ::MvpuoPrepareComplete(TInt aError)
00069     {
00070     if(aError)
00071         iView->SignalError(_L("MvpuoPrepareComplete"), aError);
00072     else
00073         iPlayer->Play();
00074     }   
00075 void CGfxVideoPlayer ::MvpuoEvent(const TMMFEvent& /*aEvent*/)
00076     {
00077      // do nothing..
00078 
00079     }
00080 void CGfxVideoPlayer ::MvpuoPlayComplete(TInt aError)
00081     {
00082     if(aError)
00083         iView->SignalError(_L("MvpuoPlayComplete"), aError);
00084     }
00085 void CGfxVideoPlayer ::MvpuoFrameReady(CFbsBitmap& /*aFrame*/,TInt aError)
00086         {
00087     if(aError)
00088         iView->SignalError(_L("MvpuoFrameReady"), aError);
00089     }
00090 void CGfxVideoPlayer ::MvpuoOpenComplete(TInt aError)
00091         {
00092     if(aError)
00093         iView->SignalError(_L("MvpuoOpenComplete"), aError);
00094     else
00095         iPlayer->Prepare();
00096     }
00097 void CGfxVideoPlayer ::PauseL()
00098     {
00099      iPlayer->PauseL();
00100     }
00101 TTimeIntervalMicroSeconds  CGfxVideoPlayer ::PositionL()
00102     {
00103      return iPlayer->PositionL();
00104     }
00105 TTimeIntervalMicroSeconds CGfxVideoPlayer ::DurationL()
00106     {
00107      return iPlayer->DurationL();
00108     }
00109 void CGfxVideoPlayer ::Stop()
00110     {
00111      iPlayer->Stop();
00112     }
00113 
00114 CVideoPlayerControl* CVideoPlayerControl::NewL(const TRect& aRect)
00115     {
00116      CVideoPlayerControl* self = CVideoPlayerControl::NewLC(aRect);
00117      CleanupStack::Pop(self);
00118      return self;
00119     }
00120 CVideoPlayerControl* CVideoPlayerControl::NewLC(const TRect& aRect)
00121     {
00122      CVideoPlayerControl* self = new (ELeave) CVideoPlayerControl;
00123      CleanupStack::PushL(self); 
00124      self->ConstructL(aRect);
00125      return self;
00126     }
00127 
00128 CVideoPlayerControl::CVideoPlayerControl()
00129     {
00130      // no implementation required
00131     }
00132 CVideoPlayerControl::~CVideoPlayerControl()
00133     {
00134     if(iPlayer)
00135         iPlayer->Stop();
00136     delete iPlayer;
00137     }
00138 void CVideoPlayerControl::ConstructL(const TRect& aRect)
00139     {
00140     iPlayer = CGfxVideoPlayer::NewL(this);
00141 
00142         CreateWindowL();
00143         SetRect(aRect);
00144         iVideoRect = Rect();
00145         TPoint point = PositionRelativeToScreen();
00146         iVideoRect.Move(point);
00147         ActivateL();
00148     }
00149 
00150 void CVideoPlayerControl::StartL()
00151         {
00152         iPlayer->InitControllerL();
00153         }
00154 
00155 void CVideoPlayerControl::StopL()
00156         {
00157         iPlayer->Stop();
00158         }
00159         
00160 void CVideoPlayerControl::SignalError(const TDesC& aCallBack, TInt aErrorCode)
00161         {
00162         TBuf<10> errorString;
00163         errorString.AppendNum(aErrorCode);
00164         
00165         iEikonEnv->AlertWin(aCallBack, errorString);
00166         }
00167 
00168 void CVideoPlayerControl::Draw(const TRect& /*aRect*/) const
00169     {
00170      CWindowGc& gc = SystemGc();
00171      //gc.SetBrushColor(KRgbBlack);
00172      gc.SetBrushColor(KRgbTransparent);
00173      gc.SetBrushStyle (CGraphicsContext::ESolidBrush);
00174      TRect rect = Rect();
00175      gc.Clear(rect);
00176     }
00177  
00178 inline RWindow& CVideoPlayerControl::ClientWindow()
00179     {
00180      return Window();
00181     }
00182 inline TRect CVideoPlayerControl::VideoRect() const
00183     {
00184      return iVideoRect;
00185     }
00186 inline RWsSession& CVideoPlayerControl::ClientWsSession()
00187     {
00188      return ControlEnv()->WsSession();
00189     }
00190 inline CWsScreenDevice& CVideoPlayerControl::ScreenDevice()
00191     {
00192      return *(ControlEnv()->ScreenDevice());
00193     }

Generated by  doxygen 1.6.2