mmsharing/mmshindicator/src/mussoundplayer.cpp
changeset 0 f0cf47e981f9
equal deleted inserted replaced
-1:000000000000 0:f0cf47e981f9
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Provides means to play custom indication sound.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "mussoundplayer.h"
       
    21 #include "muslogger.h"
       
    22 #include <NokiaAudioPreference.h>
       
    23 
       
    24 
       
    25 // Name of availability sound. Path used is private path of process.
       
    26 _LIT( KMusAvailabilitySound, "tone.amr" );
       
    27 
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // 
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CMusSoundPlayer* CMusSoundPlayer::NewL( MMusSoundPlayerObserver& aObserver )
       
    34     {
       
    35     MUS_LOG( "mus: [MUSIND]  -> CMusSoundPlayer::NewL" )
       
    36     CMusSoundPlayer* self = NewLC( aObserver );
       
    37     CleanupStack::Pop( self );
       
    38     MUS_LOG( "mus: [MUSIND]  <- CMusSoundPlayer::NewL" )
       
    39     return self;
       
    40     }
       
    41 
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // 
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CMusSoundPlayer* CMusSoundPlayer::NewLC( MMusSoundPlayerObserver& aObserver )
       
    48     {
       
    49     MUS_LOG( "mus: [MUSIND]  -> CMusSoundPlayer::NewLC" )
       
    50     CMusSoundPlayer* self = new (ELeave) CMusSoundPlayer( aObserver );
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     MUS_LOG( "mus: [MUSIND]  <- CMusSoundPlayer::NewLC" )
       
    54     return self;
       
    55     }
       
    56 
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // 
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CMusSoundPlayer::~CMusSoundPlayer()
       
    63     {
       
    64     MUS_LOG( "mus: [MUSIND]  -> CMusSoundPlayer::CMusSoundPlayer" )
       
    65     if ( iMdaPlayer )
       
    66         {
       
    67         if ( ESoundPlayerPlaying == iState )
       
    68             {
       
    69             iMdaPlayer->Stop();
       
    70             }
       
    71         delete iMdaPlayer;
       
    72         iMdaPlayer = NULL;
       
    73         }
       
    74     MUS_LOG( "mus: [MUSIND]  <- CMusSoundPlayer::CMusSoundPlayer" )
       
    75     }
       
    76 
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // 
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CMusSoundPlayer::CMusSoundPlayer( MMusSoundPlayerObserver& aObserver ):
       
    83     iObserver( aObserver ),
       
    84     iState( ESoundPlayerReady )
       
    85     {
       
    86     }
       
    87 
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // 
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CMusSoundPlayer::ConstructL()
       
    94     {
       
    95     }
       
    96 
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // Plays specified indication sound.
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CMusSoundPlayer::PlayL( TVsSoundIndication aIndication )
       
   103     {
       
   104     MUS_LOG( "mus: [MUSIND]  -> CMusSoundPlayer::PlayL" )
       
   105     if ( ESoundPlayerPlaying == iState )
       
   106         {
       
   107         User::Leave( KErrNotReady );
       
   108         }
       
   109 
       
   110     HBufC* soundFileName = SoundFileNameLC( aIndication );
       
   111 
       
   112     // Used KAudioPrefVoiceAid from audiopreference.h as preference since it
       
   113     // should always be played.
       
   114     iMdaPlayer = CMdaAudioPlayerUtility::NewFilePlayerL(
       
   115         *soundFileName,
       
   116         *this,
       
   117         EMdaPriorityMax,
       
   118         (TMdaPriorityPreference) KAudioPrefNotification );
       
   119 
       
   120     iMdaPlayer->SetPriority( EMdaPriorityMax,
       
   121                              (TMdaPriorityPreference) KAudioPrefNotification );
       
   122 
       
   123     CleanupStack::PopAndDestroy( soundFileName );
       
   124 
       
   125     iState = ESoundPlayerPlaying;
       
   126     MUS_LOG( "mus: [MUSIND]  <- CMusSoundPlayer::PlayL" )
       
   127     }
       
   128 
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // Stops playing current sound.
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 void CMusSoundPlayer::Stop()
       
   135     {
       
   136     MUS_LOG( "mus: [MUSIND]  -> CMusSoundPlayer::Stop" )
       
   137     if ( ESoundPlayerPlaying == iState )
       
   138         {
       
   139         iMdaPlayer->Stop();
       
   140         }
       
   141 
       
   142     delete iMdaPlayer;
       
   143     iMdaPlayer = NULL;
       
   144 
       
   145     iState = ESoundPlayerReady;
       
   146     MUS_LOG( "mus: [MUSIND]  <- CMusSoundPlayer::Stop" )
       
   147     }
       
   148 
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // From MMdaAudioPlayerCallback.
       
   152 // Defines required client behaviour when an attempt to open and initialise an
       
   153 // audio sample has completed, successfully or otherwise.
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CMusSoundPlayer::MapcInitComplete(
       
   157     TInt aError,
       
   158     const TTimeIntervalMicroSeconds& /*aDuration*/ )
       
   159     {
       
   160     MUS_LOG1( "mus: [MUSIND]  -> CMusSoundPlayer::MapcInitComplete(%d)", aError )
       
   161     if ( aError )
       
   162         {
       
   163         delete iMdaPlayer;
       
   164         iMdaPlayer = NULL;
       
   165         iState = ESoundPlayerReady;
       
   166         iObserver.PlaySoundComplete( aError );
       
   167         }
       
   168     else
       
   169         {
       
   170         iMdaPlayer->Play();
       
   171         }
       
   172     MUS_LOG( "mus: [MUSIND]  <- CMusSoundPlayer::MapcInitComplete" )
       
   173     }
       
   174 
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // From MMdaAudioPlayerCallback.
       
   178 // Informs of playback completion.
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void CMusSoundPlayer::MapcPlayComplete( TInt aError )
       
   182     {
       
   183     MUS_LOG1( "mus: [MUSIND]  -> CMusSoundPlayer::MapcPlayComplete(%d)", aError )
       
   184     delete iMdaPlayer;
       
   185     iMdaPlayer = NULL;
       
   186     iState = ESoundPlayerReady;
       
   187     iObserver.PlaySoundComplete( aError );
       
   188     MUS_LOG( "mus: [MUSIND]  <- CMusSoundPlayer::MapcPlayComplete" )
       
   189     }
       
   190 
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // Returns name of sound file associated with event.
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 HBufC* CMusSoundPlayer::SoundFileNameLC( TVsSoundIndication aIndication )
       
   197     {
       
   198     MUS_LOG1( "mus: [MUSIND]  -> CMusSoundPlayer::SoundFileNameLC(%d)",
       
   199               aIndication )
       
   200     RFs fs;
       
   201     User::LeaveIfError( fs.Connect() );
       
   202     TFileName filename;    
       
   203     fs.PrivatePath( filename );
       
   204     fs.Close();    
       
   205     switch ( aIndication )
       
   206         {
       
   207         case EVsAvailableSound:
       
   208             {
       
   209             filename.Append( KMusAvailabilitySound() );
       
   210             }
       
   211             break;
       
   212 
       
   213         default:
       
   214             {
       
   215             User::Leave( KErrNotFound );
       
   216             }
       
   217         }
       
   218 
       
   219     /* In product all ways tone file will present in ROM , 
       
   220        Note: this prevents auditory tone hearing in sis installation.             
       
   221     */
       
   222     filename.Insert(0,_L("z:"));
       
   223 
       
   224     MUS_LOG( "mus: [MUSIND]  <- CMusSoundPlayer::SoundFileNameLC" )
       
   225     return filename.AllocLC();
       
   226     }