Implementing Drm player in Symbian
Article Metadata
Contents |
Header File
#ifndef __SampleDrmplayerUtility_H__
#define __SampleDrmplayerUtility_H__
// INCLUDE FILES
#include <e32base.h>
#include <e32std.h>
#include <etel.h>
#include <etel3rdparty.h>
#include <drmaudiosampleplayer.h>
//FORWARD DECLARATION
class MDrmAudioPlayerCallback;
// Following two lines are added to Uplink audio on the voice call channel
#define KAudioPriority 80
#define KAudioPreference 0x00060001
class CSampleDrmplayerUtility : public CActive, public MDrmAudioPlayerCallback
{
public: // Constructors and destructors
//=================================================================
// NewL
// Two-phased constructor.
// Creates a CSampleDrmplayerUtility object using two phase construction,
// and returns a pointer to the created object.
// @return A pointer to the created instance of CSampleDrmplayerUtility.
//=================================================================
//
static CSampleDrmplayerUtility* NewL();
void RunL();
void DoCancel();
//=================================================================
// NewLC
// Two-phased constructor.
// Creates a CSampleDrmplayerUtility object using two phase construction,
// and returns a pointer to the created object.
// @return A pointer to the created instance of CSampleDrmplayerUtility.
//=================================================================
//
static CSampleDrmplayerUtility* NewLC();
//=================================================================
// CSampleDrmplayerUtility
// C++ default Destructor.
// Destroys the object and release all memory objects.
// @Return
//=================================================================
virtual ~CSampleDrmplayerUtility();
private: // Constructors and destructors
//=================================================================
// CSampleDrmplayerUtility
// C++ default constructor can NOT contain any code, that might leave.
// @Return
//=================================================================
CSampleDrmplayerUtility();
//=================================================================
// ConstructL
// Symbian 2nd phase constructor can leave.
//=================================================================
//
void ConstructL();
// FOR DRMPLAYER CALLBACKS
void MdapcInitComplete (TInt aError, const TTimeIntervalMicroSeconds &
aDuration );
void MdapcPlayComplete (TInt aError);
public: // APIs exposed to other parties
void Playmusic();
void Answercall();
void Stop();
private:
CDrmPlayerUtility* iMdaAudioPlayerUtility;
CTelephony *iTelephony;
CTelephony::TCallId iCallid;
};
#endif // __SampleDrmplayerUtility_H__
Source File
#include <e32std.h> // For system wide contents
#include <eikmenup.h>
#include <eikapp.h>
#include <aknutils.h>
#include <aknnotewrappers.h>
#include "SampleDrmplayerUtility.h"
// CONSTANTS
const TTimeIntervalMicroSeconds MaxRecordLength(10000000);
#define KAudioPrefVoiceRec 0x00060001
const TInt KAudioPriorityAudioPlaybackStreaming = 80;
_LIT( KSampleDrmTestFile, "C:\\Data\\Sounds\\Digital\\Baba.amr" );
// ========================= MEMBER FUNCTIONS ==================================
//=================================================================
// CSampleDrmplayerUtility
// C++ default constructor can NOT contain any code, that might leave.
// @Return
//=================================================================
CSampleDrmplayerUtility::CSampleDrmplayerUtility()
:CActive(EPriorityStandard) {
// No implementation required
}
//=================================================================
// NewL
// Two-phased constructor.
// Creates a SampleDrmplayerUtility object using two phase construction,
// and returns a pointer to the created object.
// @return A pointer to the created instance of SampleDrmplayerUtility.
//=================================================================
//
CSampleDrmplayerUtility* CSampleDrmplayerUtility::NewL()
{
CSampleDrmplayerUtility* self = NewLC();
CleanupStack::Pop( self );
return self;
}
//=================================================================
// NewLC
// Two-phased constructor.
// Creates a SampleDrmplayerUtility object using two phase construction,
// and returns a pointer to the created object.
// @return A pointer to the created instance of SampleDrmplayerUtility.
//=================================================================
//
CSampleDrmplayerUtility* CSampleDrmplayerUtility::NewLC()
{
CSampleDrmplayerUtility* self = new ( ELeave ) CSampleDrmplayerUtility();
CleanupStack::PushL( self );
self->ConstructL();
return self;
}
//=================================================================
// ~SampleDrmplayerUtility
// C++ default Destructor.
// @Return
//=================================================================
CSampleDrmplayerUtility::~CSampleDrmplayerUtility()
{
Stop();
Cancel();
delete iTelephony;
delete iMdaAudioPlayerUtility;
}
//=================================================================
// ConstructL
// Symbian 2nd phase constructor can leave.
//=================================================================
//
void CSampleDrmplayerUtility::ConstructL()
{
CActiveScheduler::Add(this);
TBuf<128> iFileName;
iFileName.Append(KSampleDrmTestFile);
iMdaAudioPlayerUtility=CDrmPlayerUtility::NewFilePlayerL
(iFileName,*this,80,(TMdaPriorityPreference)0x00060001);
iTelephony=CTelephony::NewL();
}
void CSampleDrmplayerUtility::Playmusic()
{
if(!iMdaAudioPlayerUtility)
{
iMdaAudioPlayerUtility = CDrmPlayerUtility::NewFilePlayerL
( KSampleDrmTestFile, *this, 80, (TMdaPriorityPreference)0x00060001 );
}
User::LeaveIfNull( iMdaAudioPlayerUtility );
iMdaAudioPlayerUtility->Play();
}
void CSampleDrmplayerUtility::Answercall()
{
iTelephony->AnswerIncomingCall(iStatus,iCallid);
SetActive();
}
void CSampleDrmplayerUtility::Stop()
{
iMdaAudioPlayerUtility->Stop();
}
//end of file
void CSampleDrmplayerUtility::RunL()
{
CEikonEnv::InfoWinL(_L("Call Answered"),_L(""));
}
void CSampleDrmplayerUtility::DoCancel()
{
CTelephony::CancelAsync( CTelephony::EAnswerIncomingCallCancel );
}
void CSampleDrmplayerUtility::MdapcInitComplete(TInt aError, const
TTimeIntervalMicroSeconds & aDuration )
{
TBuf<10> err1;
err1.AppendNum(aError);
CEikonEnv::InfoWinL(_L("initialisation completed"),err1);
}
void CSampleDrmplayerUtility::MdapcPlayComplete(TInt aError)
{
TBuf<10> err2;
err2.AppendNum(aError);
CEikonEnv::InfoWinL(_L("play completed"),err2);
}
Usage and Call of Functions
CSampleDrmplayerUtility* iDrmplayer;
iDrmplayer = CSampleDrmplayerUtility::NewL();
iDrmplayer->Answercall();
iDrmplayer->Playmusic();
iDrmplayer->Stop();
if(iDrmplayer)
{
delete iDrmplayer;
iDrmplayer=NULL;
}


tote_b5 21:40, 30 July 2007 (UTC) What I don't understand from this code snippet is what telephony and playing a DRM content have in common? I mean, what the hell is CTelephony is used for in this example at all?
tote_b5 21:47, 30 July 2007 (UTC) Yep, one more thing: you forgot to mention on which platform (SDK) this example works.
cayzacj 12:05, 30 January 2008 (GMT+1) On no platform at all, since CancelAsync() is:
- Asynchronous, so the code will produce a KERN-EXEC 3 somewhere after calling delete iTelephony (tested)
- Non-static, so CTelephony::CancelAsync() won't even compile...