×
Namespaces

Variants
Actions

Video Streaming Made Simple

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Code ExampleTested with
Devices(s): X6, 5235, N97, E63
Compatibility
Platform(s): Symbian
Article
Keywords: video, CVideoPlayerUtility, steaming
Created: somnathbanik (10 Apr 2014)
Last edited: hamishwillee (14 Jun 2013)

Contents

Description

This article provides a simple code example demonstrating how to stream video from a server using the Symbian C++ CVideoPlayerUtility::OpenUrlL API. The example overcomes many of the common problems developers will encounter.

This application has been tested on 2G connection, and should work even better in 3G and WiFi.

API Used To Stream Video : CVideoPlayerUtility::OpenUrlL(aFileName,KUseDefaultIap,KNullDesC8,KNullUid), where aFileName is the URL (Video Streaming Link)

Note.pngNote: There is nothing new about the technology presented here. However I had a hard time to make a video streaming work, so this article shares my experience for others who are facing the same issue.

LiveStreamingTV.png

Creating Video Application

To know the fundamentals of creating video application (both local and streamed), please read these articles. This will help you more to understand each code used in this article.

Device Settings Required

  1. Let set a default internet connection of the device
  2. Go to Real Player ( Streaming Link->Option->Settings->Streaming-> proxy -> no)
  3. Go to Real Player ( Streaming Link->Option->Settings->Streaming->Network -> Access point in Use -> "Set default access point")

LiveTV.mmp

The required library are listed below

LIBRARY		   euser.lib
LIBRARY apparc.lib
LIBRARY cone.lib
LIBRARY eikcore.lib
LIBRARY avkon.lib
LIBRARY commonengine.lib
LIBRARY efsrv.lib
LIBRARY estor.lib
LIBRARY aknnotify.lib
LIBRARY mediaclientvideo.lib eikcoctl.lib


LiveTVAppUi.h

/*
============================================================================
Name : LiveTVAppUi.h
Author  : Somnath Banik
Copyright  : Your copyright notice
Description : Declares UI class for application.
============================================================================
*/

 
#ifndef __LIVETVAPPUI_h__
#define __LIVETVAPPUI_h__
 
// INCLUDES
#include <aknappui.h>
//video
#include "SimpleVideoPlayer.h"
#include "coecntrl.h"
 
// FORWARD DECLARATIONS
class CLiveTVAppView;
class CVideoPlayingNewViewAppView;
class CSimpleVideoPlayer;
 
// CLASS DECLARATION
/**
* CLiveTVAppUi application UI class.
* Interacts with the user through the UI and request message processing
* from the handler class
*/

class CLiveTVAppUi : public CAknAppUi
{
public:
// Constructors and destructor
 
/**
* ConstructL.
* 2nd phase constructor.
*/

void ConstructL();
 
/**
* CLiveTVAppUi.
* C++ default constructor. This needs to be public due to
* the way the framework constructs the AppUi
*/

CLiveTVAppUi();
 
/**
* ~CLiveTVAppUi.
* Virtual Destructor.
*/

virtual ~CLiveTVAppUi();
 
private:
// Functions from base classes
 
/**
* From CEikAppUi, HandleCommandL.
* Takes care of command handling.
* @param aCommand Command to be handled.
*/

void HandleCommandL(TInt aCommand);
 
/**
* HandleStatusPaneSizeChange.
* Called by the framework when the application status pane
* size is changed.
*/

void HandleStatusPaneSizeChange();
 
/**
* From CCoeAppUi, HelpContextL.
* Provides help context for the application.
* size is changed.
*/

CArrayFix<TCoeHelpContext>* HelpContextL() const;
 
private:
// Data
 
/**
* The application view
* Owned by CLiveTVAppUi
*/

public:
CLiveTVAppView* iAppView;
CSimpleVideoPlayer* iVideoPlayer;
CCoeControl* iCurrentView;
CVideoPlayingNewViewAppView* iVideoPlayNewView;
void StartVideo(const TDesC& aUrl);
void StopVideo();
void PauseVideo();
void ResumeVideo();
 
};
 
#endif // __LIVETVAPPUI_h__
// End of File


LiveTVAppUi.cpp

/*
============================================================================
Name : LiveTVAppUi.cpp
Author  : Somnath Banik
Copyright  : Your copyright notice
Description : CLiveTVAppUi implementation
============================================================================
*/

 
// INCLUDE FILES
#include <avkon.hrh>
#include <aknmessagequerydialog.h>
#include <aknnotewrappers.h>
#include <stringloader.h>
#include <f32file.h>
#include <s32file.h>
#include <hlplch.h>
 
#include <LiveTV_0xEB2B3C0E.rsg>
 
 
#include "LiveTV.hrh"
#include "LiveTV.pan"
#include "LiveTVApplication.h"
#include "LiveTVAppUi.h"
#include "LiveTVAppView.h"
 
_LIT( KFileName, "C:\\private\\EB2B3C0E\\LiveTV.txt" );
_LIT( KText, "Hello World!");
_LIT(KVideoFilePath, "C:\\Data\\Videos\\");
 
// ============================ MEMBER FUNCTIONS ===============================
 
 
// -----------------------------------------------------------------------------
// CLiveTVAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CLiveTVAppUi::ConstructL()
{
// Initialise app UI with standard value.
//BaseConstructL(CAknAppUi::EAknEnableSkin);
BaseConstructL(EAknEnableSkin | EAknTouchCompatible | EAppOrientationPortrait);
 
// Create view object
// iVideoPlayNewView = CVideoPlayingNewViewAppView::NewL(ClientRect());
iAppView = CLiveTVAppView::NewL(ClientRect());
iAppView->SetMopParent( this );
//iAppView->ConstructL( ClientRect());
AddToStackL( iAppView );
iCurrentView = iAppView;
iCurrentView->MakeVisible(ETrue);
 
}
// -----------------------------------------------------------------------------
// CLiveTVAppUi::CLiveTVAppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CLiveTVAppUi::CLiveTVAppUi()
{
// No implementation required
}
 
// -----------------------------------------------------------------------------
// CLiveTVAppUi::~CLiveTVAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CLiveTVAppUi::~CLiveTVAppUi()
{
if (iAppView)
{
delete iAppView;
iAppView = NULL;
}
if(iVideoPlayer)
{
 
delete iVideoPlayer;
iVideoPlayer =NULL;
}
}
 
void CLiveTVAppUi::StartVideo(const TDesC& aUrl)
{
if (!iVideoPlayer)
{
iVideoPlayer = CSimpleVideoPlayer::NewL(*iAppView);
//iVideoPlayer->SetCallBack(this);
}
//iVideoPlayer->PlayL(parseFileName.FullName());
iVideoPlayer->PlayL(aUrl);
CEikButtonGroupContainer* cba =
CEikButtonGroupContainer::Current();
cba->SetCommandSetL(R_CUSTOM_CBA2);
cba->DrawNow();
}
 
void CLiveTVAppUi::StopVideo()
{
if (iVideoPlayer)
{
iVideoPlayer->Stop();
}
CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
cba->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_EXIT);
cba->DrawNow();
iAppView->DrawNow();
if(iVideoPlayer)
{
delete iVideoPlayer;
iVideoPlayer =NULL;
}
}
 
void CLiveTVAppUi::Re sumeVideo()
{
iVideoPlayer->Resume();
CEikButtonGroupContainer* cba =
CEikButtonGroupContainer::Current();
cba->SetCommandSetL(R_CUSTOM_CBA2);
cba->DrawNow();
 
}
 
void CLiveTVAppUi::PauseVideo()
{
iVideoPlayer->Pause();
CEikButtonGroupContainer* cba =
CEikButtonGroupContainer::Current();
cba->SetCommandSetL(R_CUSTOM_CBA1);
cba->DrawNow();
}
 
// -----------------------------------------------------------------------------
// CLiveTVAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void CLiveTVAppUi::HandleCommandL(TInt aCommand)
{
switch (aCommand)
{
case EEikCmdExit:
case EAknSoftkeyExit:
Exit();
break;
case EMTV:
{
_LIT(KUrl,"rtsp://a1061.v84474e.c84474.g.vq.akamaistream.net/7/1061/84474/v001/europa.hungamatech.com/AkamaiDelivery/delivery/ms15_50123998.mp4");
StartVideo(KUrl);
break;
}
case EColors:
{
_LIT(KUrl,"rtsp://a1144.v84474f.c84474.g.vq.akamaistream.net/7/1144/84474/4d7d58bb/akm-delivery.hungama.com/AkamaiDelivery/delivery/ms15_50125135.mp4");
StartVideo(KUrl);
break;
}
case EUTVBindaas:
{
_LIT(KUrl,"rtsp://a627.v844749.c84474.g.vq.akamaistream.net/7/627/84474/4d7d8127/akm-delivery.hungama.com/AkamaiDelivery/delivery/ms15_50125137.mp4");
StartVideo(KUrl);
break;
}
case EUTVMovies:
{
_LIT(KUrl,"rtsp://a1919.v844740.c84474.g.vq.akamaistream.net/7/1919/84474/4d7d81e7/akm-delivery.hungama.com/AkamaiDelivery/delivery/ms15_50125141.mp4");
StartVideo(KUrl);
break;
}
case EHomeShop18:
{
_LIT(KUrl,"rtsp://a178.v844745.c84474.g.vq.akamaistream.net/7/178/84474/4d7d87bc/akm-delivery.hungama.com/AkamaiDelivery/delivery/ms15_50125140.mp4");
StartVideo(KUrl);
break;
}
case ECbaPause:
{
PauseVideo();
break;
}
case ECbaResume:
{
 
ResumeVideo();
break;
}
 
case ECbaStop:
{
 
StopVideo();
break;
}
case ECbaPauseStop:
{
StopVideo();
break;
}
 
default:
Panic( ELiveTVUi);
break;
}
}
// -----------------------------------------------------------------------------
// Called by the framework when the application status pane
// size is changed. Passes the new client rectangle to the
// AppView
// -----------------------------------------------------------------------------
//
void CLiveTVAppUi::HandleStatusPaneSizeChange()
{
iAppView->SetRect(ClientRect());
}
 
CArrayFix<TCoeHelpContext>* CLiveTVAppUi::HelpContextL() const
{
#warning "Please see comment about help and UID3..."
// Note: Help will not work if the application uid3 is not in the
// protected range. The default uid3 range for projects created
// from this template (0xE0000000 - 0xEFFFFFFF) are not in the protected range so that they
// can be self signed and installed on the device during testing.
// Once you get your official uid3 from Symbian Ltd. and find/replace
// all occurrences of uid3 in your project, the context help will
// work. Alternatively, a patch now exists for the versions of
// HTML help compiler in SDKs and can be found here along with an FAQ:
// http://www3.symbian.com/faq.nsf/AllByDate/E9DF3257FD565A658025733900805EA2?OpenDocument
CArrayFixFlat<TCoeHelpContext>* array = new (ELeave) CArrayFixFlat<
TCoeHelpContext> (1);
CleanupStack::PushL(array);
 
CleanupStack::Pop(array);
return array;
}
 
// End of File


SimpleVideoPlayer.h

#ifndef SIMPLEVIDEOPLAYER_H
#define SIMPLEVIDEOPLAYER_H
 
// INCLUDE FILES
#include <e32std.h>
#include <e32base.h>
#include <VideoPlayer.h>
#include "LiveTVAppUi.h"
#include "LiveTVAppView.h"
#include "coecntrl.h"
 
// FORWARD DECLARATION
class CCoeControl;
class CVideoAlarmUIAppUi;
 
// CLASS DECLARATION
 
class CSimpleVideoPlayer : public CBase, public MVideoPlayerUtilityObserver
{
public: // Constructors and destructor
~CSimpleVideoPlayer();
static CSimpleVideoPlayer* NewL(const CCoeControl& aControl);
static CSimpleVideoPlayer* NewLC(const CCoeControl& aControl);
 
public: // Public methods
void PlayL(const TDesC& aFileName);
void Stop();
void Pause();
void Resume();
 
void SetDisplayWindowL(const CCoeControl& aControl);
 
private: // Constructors
CSimpleVideoPlayer();
void ConstructL(const CCoeControl& aControl);
 
private: // From MVideoPlayerUtilityObserver
void MvpuoOpenComplete(TInt aError);
void MvpuoPrepareComplete(TInt aError);
void MvpuoFrameReady(CFbsBitmap& aFrame, TInt aError);
void MvpuoPlayComplete(TInt aError);
void MvpuoEvent(const TMMFEvent& aEvent);
 
private: // Private methods
void DisplayErrorMessage(TInt aError);
 
private: // Member variables
CVideoPlayerUtility* iPlayerUtility;
//added
public:
void SetCallBack(CVideoAlarmUIAppUi* aVideoAlarmUIAppUi);
CVideoAlarmUIAppUi* iSetCallBackVideoAlarmUIAppUi;
};
 
#endif // SIMPLEVIDEOPLAYER_H
 
// End of File

SimpleVideoPlayer.cpp

// INCLUDE FILES
#include <coecntrl.h>
#include <coemain.h>
#include <eikenv.h>
#include <VideoPlayer.h>
#include "SimpleVideoPlayer.h"
#include "aknnotewrappers.h"
 
// CONSTANTS
const TInt KVolumeDenominator = 2;
 
// METHODS DEFINITION
 
CSimpleVideoPlayer::CSimpleVideoPlayer()
{
}
 
CSimpleVideoPlayer::~CSimpleVideoPlayer()
{
delete iPlayerUtility;
}
 
CSimpleVideoPlayer* CSimpleVideoPlayer::NewLC(const CCoeControl& aControl)
{
CSimpleVideoPlayer* self = new (ELeave)CSimpleVideoPlayer();
CleanupStack::PushL(self);
self->ConstructL(aControl);
return self;
}
 
CSimpleVideoPlayer* CSimpleVideoPlayer::NewL(const CCoeControl& aControl)
{
CSimpleVideoPlayer* self=CSimpleVideoPlayer::NewLC(aControl);
CleanupStack::Pop(self);
return self;
}
 
void CSimpleVideoPlayer::ConstructL(const CCoeControl& aControl)
{
TRect rect(
aControl.PositionRelativeToScreen(),
TSize(aControl.Rect().Width(), aControl.Rect().Height()));
iPlayerUtility = CVideoPlayerUtility::NewL(
*this,
EMdaPriorityNormal,
EMdaPriorityPreferenceNone,
aControl.ControlEnv()->WsSession(),
*aControl.ControlEnv()->ScreenDevice(),
*aControl.DrawableWindow(),
rect,
rect
);
 
 
// display rect on the video screen
 
}
 
void CSimpleVideoPlayer::PlayL(const TDesC& aFileName)
{
iPlayerUtility->Close();
//iPlayerUtility->OpenFileL(aFileName);
iPlayerUtility->OpenUrlL(aFileName,KUseDefaultIap,KNullDesC8,KNullUid);
 
}
 
void CSimpleVideoPlayer::Stop()
{
iPlayerUtility->Stop();
}
void CSimpleVideoPlayer::Pause()
{
iPlayerUtility->PauseL();
}
void CSimpleVideoPlayer::Resume()
{
 
iPlayerUtility->Play();//OpenUrlL(aFileName,KUseDefaultIap,KNullDesC8,KNullUid);
}
 
void CSimpleVideoPlayer::SetDisplayWindowL(const CCoeControl& aControl)
{
TRect rect(
aControl.PositionRelativeToScreen(),
TSize(aControl.Rect().Width(), aControl.Rect().Height()));
iPlayerUtility->SetDisplayWindowL(aControl.ControlEnv()->WsSession(),
*aControl.ControlEnv()->ScreenDevice(),
*aControl.DrawableWindow(),
rect,
rect);
}
 
void CSimpleVideoPlayer::MvpuoOpenComplete(TInt aError)
{
if (KErrNone == aError)
{
iPlayerUtility->Prepare();
}
else
{
// Do something when error happens.
TRAP_IGNORE(DisplayErrorMessage(aError));
}
}
 
void CSimpleVideoPlayer::MvpuoPrepareComplete(TInt aError)
{
if (KErrNone == aError)
{
TRAP_IGNORE(iPlayerUtility->SetVolumeL(iPlayerUtility->MaxVolume()
/*/ KVolumeDenominator*/));
iPlayerUtility->Play();
}
else
{
iPlayerUtility->Close();
 
 
// Do something when error happens.
TRAP_IGNORE(DisplayErrorMessage(aError));
}
}
 
void CSimpleVideoPlayer::MvpuoFrameReady(CFbsBitmap& /*aFrame*/,
TInt /*aError*/)
{
}
 
void CSimpleVideoPlayer::MvpuoPlayComplete(TInt aError)
{
if (KErrNone == aError)
{
// do something after the video completes
//iSetCallBackVideoAlarmUIAppUi->BackToFirstScreen();
 
 
}
else
{
TRAP_IGNORE(DisplayErrorMessage(aError));
}
}
 
void CSimpleVideoPlayer::MvpuoEvent(const TMMFEvent& /*aEvent*/)
{
}
 
void CSimpleVideoPlayer::DisplayErrorMessage(TInt aError)
{
const TInt KMaxBuffer = 15;
_LIT(KErrorMessage, "Error: %d");
TBuf<KMaxBuffer> buffer;
buffer.AppendFormat(KErrorMessage, aError);
TRAP_IGNORE(CEikonEnv::Static()->InfoWinL(KNullDesC, buffer));
}
 
// End of File
 
void CSimpleVideoPlayer::SetCallBack(CVideoAlarmUIAppUi* aVideoAlarmUIAppUi)
{
iSetCallBackVideoAlarmUIAppUi = aVideoAlarmUIAppUi;
}

Source Code

The full source code presented in this article is available here File:LiveStreamingTV.zip


Please Note : The Streaming Link that I have used in the this article are recorded video in my server. If you have the rights to use any TV Channel's streaming link, you can use it in this example and get live TV video.

--somnathbanik

This page was last modified on 14 June 2013, at 08:32.
129 page views in the last 30 days.