mmsharing/mmshindicator/inc/mussoundplayer.h
changeset 15 ccd8e69b5392
parent 2 b31261fd4e04
child 20 e8be2c2e049d
child 22 496ad160a278
equal deleted inserted replaced
2:b31261fd4e04 15:ccd8e69b5392
     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 #ifndef C_MUSSOUNDPLAYER_H
       
    21 #define C_MUSSOUNDPLAYER_H
       
    22 
       
    23 
       
    24 #include "musunittesting.h"
       
    25 #include "mussoundplayerobserver.h"
       
    26 #include <mdaaudiosampleplayer.h>
       
    27 #include <e32base.h>
       
    28 
       
    29 
       
    30 /**
       
    31  *  CMusSoundPlayer provides means to play custom indication sounds.
       
    32  *
       
    33  *  @code
       
    34  *  void CMyClass::PlaySoundL()
       
    35  *      {
       
    36  *      if ( iPlayer )
       
    37  *          {
       
    38  *          User::Leave( KErrInUse );
       
    39  *          }
       
    40  *      iPlayer = CMusSoundPlayer::NewL( *this );
       
    41  *      TRAPD( error, iPlayer->PlayL( CMusSoundPlayer::EVsAvailableSound ) );
       
    42  *      if ( error )
       
    43  *          {
       
    44  *          delete iPlayer;
       
    45  *          iPlayer = NULL;
       
    46  *          User::Leave( error );
       
    47  *          }
       
    48  *      }
       
    49  *
       
    50  *  // from MMusSoundPlayerObserver
       
    51  *  void CMyClass::PlaySoundComplete( TInt aError )
       
    52  *      {
       
    53  *      delete iPlayer;
       
    54  *      iPlayer = NULL;
       
    55  *      }
       
    56  *
       
    57  *  void CMyClass::~CMyClass()
       
    58  *      {
       
    59  *      delete iPlayer;
       
    60  *      iPlayer = NULL;
       
    61  *      }
       
    62  *  @endcode
       
    63  *
       
    64  *  @lib musindicator.lib
       
    65  */
       
    66 class CMusSoundPlayer : public CBase, protected MMdaAudioPlayerCallback
       
    67     {
       
    68 public:
       
    69 
       
    70     MUS_UNITTEST( UT_CMusSoundPlayer )
       
    71 
       
    72     /**  VS sound indications */
       
    73     enum TVsSoundIndication
       
    74         {
       
    75         EVsAvailableSound   // Plays sound associated to VS becoming available.
       
    76         };
       
    77 
       
    78     /**
       
    79      * Two-phased constructor.
       
    80      *
       
    81      * @param aObserver Reference to observer interface.
       
    82      * @return Pointer to newly instantiated CMusSoundPlayer.
       
    83      */
       
    84     static CMusSoundPlayer* NewL( MMusSoundPlayerObserver& aObserver );
       
    85 
       
    86     /**
       
    87      * Two-phased constructor.
       
    88      *
       
    89      * @param aObserver Reference to observer interface.
       
    90      * @return Pointer to newly instantiated CMusSoundPlayer.
       
    91      */
       
    92     static CMusSoundPlayer* NewLC( MMusSoundPlayerObserver& aObserver );
       
    93 
       
    94     /**
       
    95      * Destructor.
       
    96      */
       
    97     ~CMusSoundPlayer();
       
    98 
       
    99     /**
       
   100      * Plays selected sound.
       
   101      *
       
   102      * @param aIndication Identifies the played sound.
       
   103      */
       
   104     void PlayL( TVsSoundIndication aIndication );
       
   105 
       
   106     /**
       
   107      * Stops playing sound.
       
   108      */
       
   109     void Stop();
       
   110 
       
   111 protected:
       
   112 
       
   113 // from base class MMdaAudioPlayerCallback.
       
   114 
       
   115     /**
       
   116      * From MMdaAudioPlayerCallback.
       
   117      * Informs that initializing an audio sample has completed.
       
   118      *
       
   119      * @param aError Systemwide errorcode.
       
   120      * @param aDuration Duration of the sample.
       
   121      */
       
   122     virtual void MapcInitComplete( TInt aError, const TTimeIntervalMicroSeconds& aDuration );
       
   123 
       
   124     /**
       
   125      * From MMdaAudioPlayerCallback.
       
   126      * Informs that playing an audio sample has completed.
       
   127      *
       
   128      * @param aError Systemwide errorcode.
       
   129      */
       
   130     virtual void MapcPlayComplete( TInt aError );
       
   131 
       
   132 private:
       
   133 
       
   134     CMusSoundPlayer( MMusSoundPlayerObserver& aObserver );
       
   135 
       
   136     void ConstructL();
       
   137 
       
   138     /**
       
   139      * Returns sound file name associated with event.
       
   140      *
       
   141      * @param aIndication Identifies sound to return filename for.
       
   142      * @return Buffer containing filename of sound. Ownership is transferred.
       
   143      */
       
   144     HBufC* SoundFileNameLC( TVsSoundIndication aIndication );
       
   145 
       
   146     /**  Internal state. */
       
   147     enum TMusSoundPlayerState
       
   148         {
       
   149         ESoundPlayerReady,
       
   150         ESoundPlayerPlaying
       
   151         };
       
   152 
       
   153 private: // data
       
   154 
       
   155     /**
       
   156      * Reference to observer interface.
       
   157      */
       
   158     MMusSoundPlayerObserver& iObserver;
       
   159 
       
   160     /**
       
   161      * Internal state.
       
   162      */
       
   163     TMusSoundPlayerState iState;
       
   164 
       
   165     /**
       
   166      * Instance of MDA audio player.
       
   167      * Own.
       
   168      */
       
   169     CMdaAudioPlayerUtility* iMdaPlayer;
       
   170     };
       
   171 
       
   172 #endif // C_MUSSOUNDPLAYER_H