|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : CCESoundPlayer.cpp 00004 * Part of : Content Listing Framework Sample Application 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 00017 // INCLUDE FILES 00018 #include "CCESoundPlayer.h" 00019 00020 #include <CLFExample.rsg> 00021 00022 // ============================ MEMBER FUNCTIONS =============================== 00023 00024 // ----------------------------------------------------------------------------- 00025 // CCESoundPlayer::CCESoundPlayer 00026 // C++ default constructor can NOT contain any code, that 00027 // might leave. 00028 // ----------------------------------------------------------------------------- 00029 // 00030 CCESoundPlayer::CCESoundPlayer() 00031 { 00032 } 00033 00034 // ----------------------------------------------------------------------------- 00035 // CCESoundPlayer::ConstructL 00036 // Symbian 2nd phase constructor can leave. 00037 // ----------------------------------------------------------------------------- 00038 // 00039 void CCESoundPlayer::ConstructL() 00040 { 00041 // Create a player utility 00042 iMdaAudioPlayerUtility = CMdaAudioPlayerUtility::NewL( *this ); 00043 } 00044 00045 // ----------------------------------------------------------------------------- 00046 // CCESoundPlayer::NewL 00047 // Two-phased constructor. 00048 // ----------------------------------------------------------------------------- 00049 // 00050 CCESoundPlayer* CCESoundPlayer::NewL() 00051 { 00052 CCESoundPlayer* self = CCESoundPlayer::NewLC(); 00053 CleanupStack::Pop( self ); 00054 return self; 00055 } 00056 00057 // ----------------------------------------------------------------------------- 00058 // CCESoundPlayer::NewLC 00059 // Two-phased constructor, pointer is left to the CleanupStack. 00060 // ----------------------------------------------------------------------------- 00061 // 00062 CCESoundPlayer* CCESoundPlayer::NewLC() 00063 { 00064 CCESoundPlayer* self = new (ELeave) CCESoundPlayer; 00065 CleanupStack::PushL( self ); 00066 self->ConstructL(); 00067 return self; 00068 } 00069 00070 // Destructor 00071 CCESoundPlayer::~CCESoundPlayer() 00072 { 00073 if( iPlayerState == ECEPlaying ) 00074 { 00075 StopPlayback(); 00076 } 00077 00078 delete iMdaAudioPlayerUtility; 00079 } 00080 00081 // ----------------------------------------------------------------------------- 00082 // CCESoundPlayer::MapcInitComplete 00083 // Defines client behaviour when opening and initialization of an audio sample 00084 // has completed. 00085 // ----------------------------------------------------------------------------- 00086 // 00087 void CCESoundPlayer::MapcInitComplete( 00088 TInt aError, 00089 const TTimeIntervalMicroSeconds& /*aDuration*/ ) 00090 { 00091 iPlayerState = aError ? ECENotReady : ECEReadyToPlay; 00092 00093 // Start the playback, if audio file initialization was successful 00094 if ( iPlayerState == ECEReadyToPlay ) 00095 { 00096 iMdaAudioPlayerUtility->Play(); 00097 iPlayerState = ECEPlaying; 00098 } 00099 } 00100 00101 // ----------------------------------------------------------------------------- 00102 // CCESoundPlayer::MapcPlayComplete 00103 // Defines client behaviour when playback of an audio sample has completed. 00104 // ----------------------------------------------------------------------------- 00105 // 00106 void CCESoundPlayer::MapcPlayComplete( TInt aError ) 00107 { 00108 iPlayerState = aError ? ECENotReady : ECEReadyToPlay; 00109 } 00110 00111 // ----------------------------------------------------------------------------- 00112 // CCESoundPlayer::StartPlayback 00113 // Open music file and start music playback. 00114 // ----------------------------------------------------------------------------- 00115 // 00116 void CCESoundPlayer::StartPlaybackL( const TDesC& aFileName ) 00117 { 00118 // Open the sound file 00119 iMdaAudioPlayerUtility->OpenFileL( aFileName ); 00120 } 00121 00122 // ----------------------------------------------------------------------------- 00123 // CCESoundPlayer::StopPlayback 00124 // Stop music playback. 00125 // ----------------------------------------------------------------------------- 00126 // 00127 void CCESoundPlayer::StopPlayback() 00128 { 00129 // Stop audio playback and close the audio file 00130 if( iMdaAudioPlayerUtility && iPlayerState == ECEPlaying ) 00131 { 00132 iMdaAudioPlayerUtility->Stop(); 00133 iMdaAudioPlayerUtility->Close(); 00134 iPlayerState = ECENotReady; 00135 } 00136 } 00137 00138 // ----------------------------------------------------------------------------- 00139 // CCESoundPlayer::PlayerState 00140 // Get the state of the audio player. 00141 // ----------------------------------------------------------------------------- 00142 // 00143 TCEPlayerState CCESoundPlayer::PlayerState() 00144 { 00145 return iPlayerState; 00146 } 00147 00148 // End of File
|
© Nokia 2009 |