vtengines/videoteleng/Src/Extensions/cvtengr2ftoneplayer.cpp
changeset 0 ed9695c8bcbe
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     1 /*
       
     2 * Copyright (c) 2003, 2004, 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:  Plays snap, self-timer and video start/stop sounds.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include <videotelui.rsg>
       
    21 
       
    22 #include <avkon.rsg>
       
    23 
       
    24 #include <AudioPreference.h>
       
    25 #include <StringLoader.h>
       
    26 
       
    27 #include <CVtLogger.h>
       
    28 
       
    29 #include "cvtengr2ftoneplayer.h"
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 // FORWARD DECLARATIONS
       
    34 
       
    35 // ================= MEMBER FUNCTIONS =======================
       
    36 
       
    37 // ----------------------------------------------------------
       
    38 // CVtEngR2FTonePlayer::CVtEngR2FTonePlayer
       
    39 // C++ constructor
       
    40 // ----------------------------------------------------------
       
    41 //
       
    42 CVtEngR2FTonePlayer::CVtEngR2FTonePlayer()
       
    43     {
       
    44     }
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CVtEngR2FTonePlayer::NewL
       
    49 // Symbian OS two-phased constructor
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CVtEngR2FTonePlayer* CVtEngR2FTonePlayer::NewL()
       
    53     {
       
    54     CVtEngR2FTonePlayer* self = new ( ELeave ) CVtEngR2FTonePlayer();
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop();
       
    58     return self;
       
    59     }
       
    60 
       
    61 
       
    62 // ----------------------------------------------------------
       
    63 // CVtEngR2FTonePlayer::ConstructL
       
    64 // Symbian OS 2nd phase constructor
       
    65 // ----------------------------------------------------------
       
    66 //
       
    67 void CVtEngR2FTonePlayer::ConstructL()
       
    68     {
       
    69     __VTPRINTENTER( "CVtEngR2FTonePlayer.ConstructL" )
       
    70     iAudioPlayer = CMdaAudioPlayerUtility::NewL( *this,
       
    71         KAudioPriorityVideoRecording, 
       
    72         TMdaPriorityPreference( KAudioPrefCamera ) );
       
    73 	
       
    74     iVideoStartSound = StringLoader::LoadL( R_VIDEOTELUI_VIDEO_RECORD_START_SOUND_PATH );
       
    75     iVideoStopSound = StringLoader::LoadL( R_VIDEOTELUI_VIDEO_RECORD_STOP_SOUND_PATH );
       
    76     iSoundInProgress = EFalse;
       
    77     iOpenFileInProgress = EFalse;
       
    78     __VTPRINTEXIT( "CVtEngR2FTonePlayer.ConstructL" )
       
    79     }
       
    80 
       
    81 
       
    82 // Destructor.
       
    83 CVtEngR2FTonePlayer::~CVtEngR2FTonePlayer()
       
    84     {
       
    85     if ( iAudioPlayer )
       
    86         {
       
    87         iAudioPlayer->Close();
       
    88         delete iAudioPlayer;
       
    89         }
       
    90 
       
    91     delete iVideoStartSound;
       
    92     delete iVideoStopSound;
       
    93     }
       
    94 
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CVtEngR2FTonePlayer::PlaySound
       
    98 // Play a sound with given id.
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 TInt CVtEngR2FTonePlayer::PlaySound( TInt aSound )
       
   102     {
       
   103     __VTPRINTENTER( "CVtEngR2FTonePlayer.PlaySound" )
       
   104 	TInt err = KErrNone;
       
   105     iAudioPlayer->Stop();
       
   106     iAudioPlayer->Close();
       
   107    
       
   108     switch ( aSound )
       
   109         {
       
   110         case EVtR2FVideoStartSoundId:
       
   111         case EVtR2FVideoStopSoundId:
       
   112             {
       
   113             __VTPRINT( DEBUG_GEN,"CVtEngR2FTonePlayer.PlaySound() user sound" )
       
   114             
       
   115             // Set correct sound file
       
   116             TPtrC soundFile = *iVideoStartSound;
       
   117             if ( aSound == EVtR2FVideoStopSoundId )
       
   118                 {
       
   119                 soundFile.Set( *iVideoStopSound );
       
   120                 }
       
   121                 
       
   122             // Video recording start sound using MMF
       
   123             if ( !iOpenFileInProgress && !iSoundInProgress )
       
   124                 {
       
   125                 TRAP( err, iAudioPlayer->OpenFileL( soundFile ) );
       
   126                 if ( !err )
       
   127                     {
       
   128                     __VTPRINT( DEBUG_GEN,"CVtEngR2FTonePlayer.PlaySound() open now in progress" )
       
   129                     iOpenFileInProgress = ETrue;
       
   130                     }
       
   131                 }
       
   132             else
       
   133                 {
       
   134                 __VTPRINT( DEBUG_GEN, "CVtEngR2FTonePlayer.PlaySound() err, in use" )
       
   135                 // The last OpenFileL call still hasnt completed.
       
   136                 // Cannot start playing a new file.
       
   137                 err = KErrInUse;
       
   138                 }
       
   139             break;
       
   140             }
       
   141 
       
   142         default:
       
   143             {
       
   144             // Other sounds are not supported
       
   145 			err = KErrArgument;
       
   146             break;
       
   147             }
       
   148         }
       
   149 	__VTPRINTEXIT( "CVtEngR2FTonePlayer.PlaySound" )
       
   150 	return err;
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // CVtEngR2FTonePlayer::Stop
       
   155 // Stop any ongoing sound.
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 void CVtEngR2FTonePlayer::StopSound()
       
   159     {
       
   160     __VTPRINTENTER( "CVtEngR2FTonePlayer.StopSound" )
       
   161     
       
   162     iAudioPlayer->Stop();
       
   163     iAudioPlayer->Close();
       
   164     
       
   165     __VTPRINTEXIT( "CVtEngR2FTonePlayer.StopSound" )
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // CVtEngR2FTonePlayer::MapcInitComplete
       
   170 // CMdaAudioPlayerUtility initialization complete
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 void CVtEngR2FTonePlayer::MapcInitComplete(
       
   174     TInt aError, const TTimeIntervalMicroSeconds& aDuration )
       
   175     {
       
   176     __VTPRINTENTER( "CVtEngR2FTonePlayer.MapcInitComplete" )
       
   177     __VTPRINT3( DEBUG_GEN, "CVtEngR2FTonePlayer.MapcInitComplete(%d, %d) ", 
       
   178     	aError, I64INT( aDuration.Int64()) )
       
   179     
       
   180     (void) aDuration; 
       
   181 
       
   182     iOpenFileInProgress = EFalse;
       
   183 	
       
   184 	// If tone can be played
       
   185     if ( !aError )
       
   186         {
       
   187         __VTPRINT( DEBUG_GEN, "CVtEngR2FTonePlayer.MapcInitComplete() play" )
       
   188         iSoundInProgress = ETrue;
       
   189         iAudioPlayer->Play();
       
   190         }
       
   191     // error occured during tone player init    
       
   192     else
       
   193         {
       
   194         __VTPRINT( DEBUG_GEN,"CVtEngR2FTonePlayer.MapcInitComplete() error" )
       
   195         }
       
   196     __VTPRINTEXIT( "CVtEngR2FTonePlayer.MapcInitComplete" )
       
   197     }
       
   198 
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // CVtEngR2FTonePlayer::MapcPlayComplete
       
   202 // Playback complete, notify observer
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 void CVtEngR2FTonePlayer::MapcPlayComplete( TInt aError )
       
   206     {
       
   207     __VTPRINTENTER( "CVtEngR2FTonePlayer.MapcPlayComplete" )
       
   208     __VTPRINT2( DEBUG_GEN, "CVtEngR2FTonePlayer.MapcPlayComplete(%d)", aError)
       
   209     
       
   210     (void) aError;
       
   211 
       
   212     iSoundInProgress = EFalse;
       
   213     __VTPRINTEXIT( "CVtEngR2FTonePlayer.MapcPlayComplete" )    
       
   214     }
       
   215 
       
   216 
       
   217 // End of File