examples/QtQuick/videoapp/videoengine.cpp

00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation
00006 **
00007 **
00008 ** $QT_BEGIN_LICENSE:BSD$
00009 ** You may use this file under the terms of the BSD license as follows:
00010 **
00011 ** "Redistribution and use in source and binary forms, with or without
00012 ** modification, are permitted provided that the following conditions are
00013 ** met:
00014 **   * Redistributions of source code must retain the above copyright
00015 **     notice, this list of conditions and the following disclaimer.
00016 **   * Redistributions in binary form must reproduce the above copyright
00017 **     notice, this list of conditions and the following disclaimer in
00018 **     the documentation and/or other materials provided with the
00019 **     distribution.
00020 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
00021 **     the names of its contributors may be used to endorse or promote
00022 **     products derived from this software without specific prior written
00023 **     permission.
00024 **
00025 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00026 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00027 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00028 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00029 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00030 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00031 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00032 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00033 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00034 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00035 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
00036 ** $QT_END_LICENSE$
00037 ** Description:  videoengine.cpp, source file for video player engine.
00038 ****************************************************************************/
00039 
00040 
00041 // SYSTEM INCLUDE
00042 #include <coecntrl.h>
00043 #include <coemain.h>
00044 
00045 // USER INCLUDES
00046 #include "videoengine.h"
00047 #include "videoplayerwrapper.h"
00048 
00049 // Video file to be played.
00050 _LIT(KDirVideos,"C:\\data\\Videos\\example_video.3gp");
00051 
00052 
00057 CVideoPlayerEngine* CVideoPlayerEngine::NewL(VideoPlayerWrapper *aPlayerWrapper)
00058     {
00059     CVideoPlayerEngine* self = CVideoPlayerEngine::NewLC(aPlayerWrapper);
00060     CleanupStack::Pop(self);
00061     return self;
00062     }
00063 
00068 CVideoPlayerEngine* CVideoPlayerEngine::NewLC(VideoPlayerWrapper *aPlayerWrapper)
00069     {
00070     CVideoPlayerEngine* self = new (ELeave) CVideoPlayerEngine();
00071     CleanupStack::PushL(self);
00072     self->ConstructL(aPlayerWrapper);
00073     return self;
00074     }
00075 
00079 void CVideoPlayerEngine::ConstructL(VideoPlayerWrapper *aPlayerWrapper)
00080     {
00081     iPlayerWrapper = aPlayerWrapper;
00082     }
00083 
00087 CVideoPlayerEngine::CVideoPlayerEngine() :
00088     iState(ENotInitialized)
00089     {
00090     }
00091 
00095 CVideoPlayerEngine::~CVideoPlayerEngine()
00096     {
00097     if( iPlayer )
00098         {
00099         iPlayer->Close();
00100         delete iPlayer;
00101         iPlayer = NULL;
00102         }
00103     if( iVideoContainer )
00104         {
00105         delete iPlayer;
00106         iPlayer = NULL;
00107         }
00108     }
00109 
00114 void CVideoPlayerEngine::InitL()
00115                    
00116     {
00117     iState = ENotInitialized;
00118     if (iPlayer)
00119         {
00120         delete iPlayer;
00121         iPlayer = NULL;
00122         };
00123 
00124     // Obtains a window on which video will be displayed.
00125     if ( ! iVideoContainer )
00126         {
00127           iVideoContainer = CVideoContainer::NewL();
00128         }
00129 
00130     iPlayer = CVideoPlayerUtility::NewL( *this, EMdaPriorityNormal, EMdaPriorityPreferenceNone,
00131                                             iVideoContainer->ClientWsSession(), iVideoContainer->ScreenDevice(),
00132                                             iVideoContainer->ClientWindow(), iVideoContainer->VideoRect(),  iVideoContainer->VideoRect());
00133 
00134     }
00135 
00139 void CVideoPlayerEngine::OpenL()
00140     {
00141     TRAPD(unsupported, iPlayer->OpenFileL(KDirVideos));
00142     if ( unsupported != KErrNone )
00143          {
00144          _LIT(KOpenFailed, "Open failed");
00145          TBuf<24> message(KOpenFailed);
00146          iPlayerWrapper->printMessage(message);
00147          iPlayer->Close();
00148          delete iPlayer;
00149          iPlayer = NULL;
00150          User::Leave(unsupported);
00151          }
00152     }
00156 void CVideoPlayerEngine::Play()
00157     {
00158     if(( iState == EInitialized)||( iState == EPaused ))
00159         {
00160         iPlayer->Play();
00161         iState = EPlaying;
00162         _LIT(KPlaying, "Video playing");
00163         TBuf<24> message(KPlaying);
00164         iPlayerWrapper->printMessage(message);
00165         }
00166     else
00167         {
00168         return;
00169         }
00170     }
00171 
00175 void CVideoPlayerEngine::PauseL()
00176     {
00177     if( iState == EPlaying )
00178        {
00179         TRAPD(err,iPlayer->PauseL());
00180         if (err != KErrNone)
00181             {
00182             _LIT(KPausefailed,"Video Pause failed");
00183             TBuf<32> message(KPausefailed);
00184             iPlayerWrapper->printMessage(message);
00185             User::Leave(err);
00186             }
00187         else
00188             {
00189             iState = EPaused;
00190             _LIT(KPaused,"Video Paused");
00191             TBuf<32> message(KPaused);
00192             iPlayerWrapper->printMessage(message);
00193             }
00194         }
00195     else
00196         {
00197         return;
00198         }
00199     }
00200 
00204 void CVideoPlayerEngine::Stop()
00205     {
00206     if( iState != EPlaying && iState != EPaused )
00207         {
00208         return;
00209         }
00210     iPlayer->Stop();
00211     iState = EStopped;
00212     _LIT(KStopped,"Video Playback stopped !!!");
00213     TBuf<32> message(KStopped);
00214     iPlayerWrapper->printMessage(message);
00215     iPlayer->Close();
00216     }
00217 
00222 void CVideoPlayerEngine::SetVolume(TInt aValue)
00223     {
00224     if( iState )
00225     {
00226         TRAPD(err,iPlayer->SetVolumeL(aValue));
00227         if (err != KErrNone)
00228             {
00229             User::Leave(err);
00230             }
00231     }
00232     else
00233     {
00234         return;
00235     }
00236 
00237     }
00238 
00244 void CVideoPlayerEngine::MvpuoOpenComplete(TInt aError)
00245     {
00246     if( aError == KErrNone )
00247         {
00248         _LIT(KFileOpen,"File Open Completed !!!");
00249         TBuf<24> message(KFileOpen);
00250         iPlayerWrapper->printMessage(message);
00251         iPlayer->Prepare();
00252         iState = EInitialized;
00253         }
00254     else
00255         {
00256         _LIT(KOpenComFailed,"File Open Complete failed !!!");
00257         TBuf<24> message(KOpenComFailed);
00258         iPlayerWrapper->printMessage(message);
00259         iPlayer->Close();
00260         iState = EStopped;
00261         //release resources
00262         if ( iPlayer )
00263             {
00264             delete iPlayer;
00265             iPlayer = NULL;
00266             };
00267         }
00268     }
00269 
00277 void CVideoPlayerEngine::MvpuoPrepareComplete(TInt aError)
00278     {
00279     if( aError == KErrNone )
00280         {
00281         _LIT(KPrepareComplete,"Prepare Completed !!!");
00282         TBuf<24> message(KPrepareComplete);
00283         iPlayerWrapper->printMessage(message);
00284         }
00285     }
00286 
00292 void CVideoPlayerEngine::MvpuoPlayComplete(TInt aError)
00293     {
00294     if( aError == KErrNone )
00295         {
00296         _LIT(KPlayComplete,"Playback Completed !!!");
00297         TBuf<24> message(KPlayComplete);
00298         iPlayerWrapper->printMessage(message);
00299         Stop();
00300         }
00301     else
00302         {
00303         _LIT(KPlayCompletefailed,"Playback Complete failed !!!");
00304         TBuf<24> message(KPlayCompletefailed);
00305         iPlayerWrapper->printMessage(message);
00306         }
00307     }
00308 
00313 void CVideoPlayerEngine::MvpuoFrameReady(CFbsBitmap& /*aFrame*/,TInt /*aError*/)
00314     {
00315     }
00316 
00320 void CVideoPlayerEngine::MvpuoEvent(const TMMFEvent& /*aEvent*/)
00321     {
00322     }
00323 
00324  
00325 // End of file

Generated by  doxygen 1.6.2