www.pudn.com > nokie_soundplayer.rar > playeradapter.cpp


/* Copyright (c) 2004, Nokia. All rights reserved */ 
 
 
// INCLUDE FILES 
#include  
#include  
#include  
 
#include "sound.pan" 
#include "sound.hrh" 
#include "playeradapter.h" 
#include "soundappui.h" 
 
 
// ========================= MEMBER FUNCTIONS ================================== 
 
// ----------------------------------------------------------------------------- 
// CPlayerAdapter::CPlayerAdapter() 
// C++ default constructor can NOT contain any code, that might leave. 
// ----------------------------------------------------------------------------- 
CPlayerAdapter::CPlayerAdapter( CSoundAppUi& aAppUi ) 
: iState( ENotReady ), iAppUi( aAppUi )  
    { 
    // No implementation required 
    } 
 
 
// ----------------------------------------------------------------------------- 
// CPlayerAdapter::NewL() 
// Two-phased constructor. 
// ----------------------------------------------------------------------------- 
// 
CPlayerAdapter* CPlayerAdapter::NewL( const TDesC& aFileName,  
                                      CSoundAppUi& aAppUi ) 
    { 
    CPlayerAdapter* self = NewLC( aFileName, aAppUi ); 
    CleanupStack::Pop( self ); 
    return self; 
    } 
 
// ----------------------------------------------------------------------------- 
// CPlayerAdapter::NewLC() 
// Two-phased constructor. 
// ----------------------------------------------------------------------------- 
// 
CPlayerAdapter* CPlayerAdapter::NewLC( const TDesC& aFileName,  
                                       CSoundAppUi& aAppUi ) 
    { 
    CPlayerAdapter* self = new ( ELeave ) CPlayerAdapter( aAppUi ); 
    CleanupStack::PushL( self ); 
    self->ConstructL( aFileName ); 
    return self; 
    } 
 
// ----------------------------------------------------------------------------- 
// CPlayerAdapter::ConstructL() 
// Symbian 2nd phase constructor can leave. 
// ----------------------------------------------------------------------------- 
// 
void CPlayerAdapter::ConstructL( const TDesC& aFileName ) 
    { 
 
     // Load a string from the resource file. 
     // Identifying string for this audio utility. 
     itextResourceIdentifier = CCoeEnv::Static()->AllocReadResourceL(  
                                                            R_SOUN_MODE_PLAYER ); 
 
 
   #ifdef __WINS__ 
        // on emulator, the sound files used by application are  
        // deployed onto c: drive 
         _LIT( tFullPath,"c:\\system\\apps\\sound\\" ); 
        TParse parse; 
     
    #else 
 
        // on real phone, application can be installed to the memory  
        // card ( non-"C:" drive ), 
        // this part of code evaluates current application path: 
         
        // find the instance of EikonEnv 
        CEikonEnv& ee = *CEikonEnv::Static(); 
         
        // derive the instance of EikonAppUi 
        CEikAppUi& ea = *( ee.EikAppUi() ); 
 
        // fetch the application full filename 
        TFileName tAppFullName = ea.Application()->AppFullName(); 
        TParse parse; 
 
        // form parse object containing full app name 
        parse.Set( tAppFullName, NULL, NULL ); 
         
        // get application path with drive letter 
        TFileName tFullPath = parse.DriveAndPath();  
 
    #endif 
 
 
    // use tparse to get the full path to sound file 
    parse.Set( tFullPath, &aFileName,  NULL );   
    TFileName tFullFileName = parse.FullName(); 
 
    // Create an audio player utility instance for playing  
    // sample data from a file, 
    // causes MMdaAudioPlayerCallback::MapcInitComplete to be called 
    iMdaAudioPlayerUtility = CMdaAudioPlayerUtility::NewFilePlayerL( tFullFileName, *this ); 
    } 
 
// ----------------------------------------------------------------------------- 
// CPlayerAdapter::~CPlayerAdapter() 
// Destructor. 
// ----------------------------------------------------------------------------- 
// 
CPlayerAdapter::~CPlayerAdapter() 
    { 
    delete iMdaAudioPlayerUtility;     
 
    // Delete private HBuf member for indetify 
    delete itextResourceIdentifier; 
    } 
 
// ----------------------------------------------------------------------------- 
// CPlayerAdapter::UpdateMenuL() 
// Update Menu 
// ----------------------------------------------------------------------------- 
// 
void CPlayerAdapter::UpdateMenuL( CEikMenuPane* aMenuPane ) 
    { 
    aMenuPane->SetItemDimmed( ESoundCmdPlay,   ETrue ); 
    //aMenuPane->SetItemDimmed( ESoundCmdRecord, ETrue ); 
    aMenuPane->SetItemDimmed( ESoundCmdStop,   ETrue ); 
    //aMenuPane->SetItemDimmed( ESoundCmdChange, ETrue ); 
 
    switch ( iState ) 
        { 
        case ENotReady: 
            //aMenuPane->SetItemDimmed( ESoundCmdChange, EFalse ); 
            break; 
 
        case EReadyToPlay: 
            aMenuPane->SetItemDimmed( ESoundCmdPlay, EFalse ); 
          //  aMenuPane->SetItemDimmed( ESoundCmdChange, EFalse ); 
            break; 
 
        case EPlaying: 
            aMenuPane->SetItemDimmed( ESoundCmdStop, EFalse ); 
            break; 
 
        default: 
            User::Panic( KPlayerAdapter, KSoundPanicInvalidMdaState ); 
            break; 
        } 
    } 
 
// ----------------------------------------------------------------------------- 
// CPlayerAdapter::PlayL() 
// Play the wav 
// ----------------------------------------------------------------------------- 
// 
void CPlayerAdapter::PlayL() 
    { 
    iMdaAudioPlayerUtility->Play(); 
    iState = EPlaying; 
    } 
 
// ----------------------------------------------------------------------------- 
// CPlayerAdapter::RecordL() 
// Record the wav, not available in Player mode. 
// ----------------------------------------------------------------------------- 
// 
void CPlayerAdapter::RecordL()  
    { 
    // No implementation required 
    } 
 
// ----------------------------------------------------------------------------- 
// CPlayerAdapter::StopL() 
// Stop the play 
// ----------------------------------------------------------------------------- 
// 
void CPlayerAdapter::StopL() 
    { 
    iMdaAudioPlayerUtility->Stop(); 
    iState = EReadyToPlay; 
    } 
 
// ----------------------------------------------------------------------------- 
// CPlayerAdapter::Identify() 
// Identify mode 
// ----------------------------------------------------------------------------- 
// 
const TDesC& CPlayerAdapter::Identify() 
    { 
     return *itextResourceIdentifier; 
    } 
 
// ----------------------------------------------------------------------------- 
// CPlayerAdapter::MapcInitComplete() 
// Mapc Init Complete 
// ----------------------------------------------------------------------------- 
// 
void CPlayerAdapter::MapcInitComplete( TInt aError, 
                                 const TTimeIntervalMicroSeconds& /*aDuration*/ ) 
    { 
    iState = aError ? ENotReady : EReadyToPlay; 
    } 
 
// ----------------------------------------------------------------------------- 
// CPlayerAdapter::MapcPlayComplete() 
// Mapc Play Complete 
// ----------------------------------------------------------------------------- 
// 
void CPlayerAdapter::MapcPlayComplete( TInt aError ) 
    { 
    iState = aError ? ENotReady : EReadyToPlay; 
    } 
 
 
// End of File