voicerecorder/RecViewSrc/CVRTonePlayer.cpp
branchRCL_3
changeset 20 072a5fa0c63b
parent 19 2f5c9ee7098c
child 21 c6bafb5162d8
equal deleted inserted replaced
19:2f5c9ee7098c 20:072a5fa0c63b
     1 /*
       
     2 * Copyright (c) 2005 - 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Class that handles playback of tones in VoiceRec application
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <avkon.hrh>
       
    22 #include <aknappui.h>
       
    23 #include <AudioPreference.h>
       
    24 #include <aknsoundsystem.h>
       
    25 #include <aknSoundinfo.h>
       
    26 
       
    27 #include "CVRTonePlayer.h"
       
    28 
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS =============================
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // CVRTonePlayer::CVRTonePlayer
       
    34 // 
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CVRTonePlayer::CVRTonePlayer()
       
    38 	: iState( EVRToneIdle )
       
    39     {
       
    40     }
       
    41 
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CVRTonePlayer::ConstructL
       
    45 // 
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 void CVRTonePlayer::ConstructL()
       
    49     {
       
    50     iPlayer = CMdaAudioToneUtility::NewL( *this );
       
    51     
       
    52     iSoundSystem = ( static_cast< CAknAppUi* >(
       
    53 						CEikonEnv::Static()->EikAppUi() )->KeySounds() );
       
    54     }
       
    55 
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CVRTonePlayer::NewL
       
    59 // 
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CVRTonePlayer* CVRTonePlayer::NewL()
       
    63     {
       
    64     CVRTonePlayer* self = new ( ELeave ) CVRTonePlayer;
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CVRTonePlayer::~CVRTonePlayer
       
    74 // 
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CVRTonePlayer::~CVRTonePlayer()
       
    78     {
       
    79     if ( iPlayer )
       
    80         {
       
    81         switch ( iPlayer->State() )
       
    82             {
       
    83             case EMdaAudioToneUtilityNotReady:
       
    84                 {
       
    85                 iPlayer->CancelPrepare();
       
    86                 break;
       
    87                 }
       
    88             case EMdaAudioToneUtilityPlaying:
       
    89                 {
       
    90                 iPlayer->CancelPlay();
       
    91                 break;
       
    92                 }           
       
    93             }
       
    94         }
       
    95     delete iPlayer;
       
    96     
       
    97     // if tone play is not finished before, finish waitloop
       
    98     if ( iShedulerWait.IsStarted() )
       
    99 		{
       
   100 		iShedulerWait.AsyncStop();
       
   101 		}		
       
   102     }
       
   103 
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CVRTonePlayer::PrepareToneL
       
   107 // Starts preparing the specified tone, preparing completes with call-back to
       
   108 // MatoPrepareComplete
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 void CVRTonePlayer::PrepareToneL( TInt aToneId )
       
   112     {
       
   113 	if ( iState != EVRToneIdle )
       
   114 		{
       
   115 		iQueuedTone = aToneId;
       
   116 		return;
       
   117 		}
       
   118 
       
   119 	// Retrieve the tone
       
   120 	CAknSoundInfo* info = CAknSoundInfo::NewL();
       
   121 	CleanupStack::PushL( info );
       
   122 	User::LeaveIfError( iSoundSystem->RequestSoundInfoL(
       
   123 					                  aToneId, *info ) );
       
   124     
       
   125     iPreparedTone = aToneId;
       
   126     iState = EVRTonePreparing;
       
   127     
       
   128     iPlayer->PrepareToPlayDesSequence( *info->iSequence );
       
   129     CleanupStack::PopAndDestroy( info );
       
   130     }
       
   131 
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CVRTonePlayer::PrepareTone
       
   135 // Non-leaving version of PrepareToneL
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CVRTonePlayer::PrepareTone( TInt aToneId )
       
   139     {
       
   140     TRAP_IGNORE( PrepareToneL( aToneId ) );
       
   141     }
       
   142 
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // CVRTonePlayer::PlayTone
       
   146 // Starts playback of specified tone. Completes with call-back to
       
   147 // MatoPlayComplete
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void CVRTonePlayer::PlayTone( TInt aToneId )
       
   151     {
       
   152     if ( iState != EVRToneIdle || iPreparedTone != aToneId || 
       
   153         iPlayer->State() == EMdaAudioToneUtilityPlaying )
       
   154     	{
       
   155     	// Preparing an unprepared tone synchronously is not supported,
       
   156     	// tone playback is skipped
       
   157     	return;
       
   158     	}
       
   159     
       
   160     // Preferences need to be set according to tone
       
   161     switch( aToneId )
       
   162     	{
       
   163     	case EAvkonSIDVoiceRecordingStartTone:
       
   164     		{
       
   165     		iPlayer->SetPriority( KAudioPriorityRecording,
       
   166     			TMdaPriorityPreference( KAudioPrefVoiceRecStart ) );
       
   167 			break;	    		
       
   168     		}    
       
   169     	case EAvkonSIDVoiceRecordingStopTone:
       
   170     		{
       
   171     		iPlayer->SetPriority( KAudioPriorityRecording,
       
   172     			TMdaPriorityPreference( KAudioPrefVoiceRecStop ) );    		
       
   173 			break;    	    		    			
       
   174     		}
       
   175     	default:
       
   176     		{
       
   177     		break;
       
   178     		}
       
   179 		}
       
   180  
       
   181     iState = EVRTonePlaying;
       
   182     
       
   183     iPlayer->Play();
       
   184     
       
   185     // Do not continue until start tone play is finished
       
   186     if( aToneId == EAvkonSIDVoiceRecordingStartTone )
       
   187 	    {
       
   188 #ifdef _DEBUG
       
   189 	    RDebug::Print( _L("VoiceRecorder: Waiting for Start tone play complete") );
       
   190 #endif	
       
   191 	    iShedulerWait.Start();
       
   192 	    }
       
   193     }
       
   194 
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // CVRTonePlayer::MatoPrepareComplete
       
   198 // 
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 void CVRTonePlayer::MatoPrepareComplete(TInt aError)
       
   202 	{
       
   203 	if ( aError )
       
   204 		{
       
   205 		iPreparedTone = 0;
       
   206 		}
       
   207 
       
   208 	iState = EVRToneIdle;
       
   209 
       
   210 	// Prepare the next tone in queue
       
   211 	if ( iQueuedTone )
       
   212 		{
       
   213 		TRAP_IGNORE( PrepareToneL( iQueuedTone ) );
       
   214 		iQueuedTone = 0;
       
   215 		}
       
   216 	}
       
   217 	
       
   218 
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 // CVRTonePlayer::MatoPlayComplete
       
   222 // 
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 #ifdef _DEBUG
       
   226 void CVRTonePlayer::MatoPlayComplete(TInt aError )
       
   227     {
       
   228 	RDebug::Print( _L("VoiceRecorder: Tone %d played, error %d"), 
       
   229 			iPreparedTone, aError );
       
   230 #else
       
   231 void CVRTonePlayer::MatoPlayComplete(TInt /*aError*/ )
       
   232     {
       
   233 #endif    	
       
   234 
       
   235 	iState = EVRToneIdle;
       
   236 
       
   237 	// Prepare the next tone in queue
       
   238 	if ( iQueuedTone )
       
   239 		{
       
   240 		TRAP_IGNORE( PrepareToneL( iQueuedTone ) );
       
   241 		iQueuedTone = 0;
       
   242 		}
       
   243 	
       
   244 	// Started only for start-tone	
       
   245 	if ( iShedulerWait.IsStarted() )
       
   246 		{
       
   247 #ifdef _DEBUG
       
   248 	    RDebug::Print( _L("VoiceRecorder: Start tone play completed -> Recording started") );
       
   249 #endif		
       
   250 		// Start tone played -> Recording can be started
       
   251 		iShedulerWait.AsyncStop();
       
   252 		}	
       
   253 			
       
   254 	}