phoneapp/phoneuiview/inc/cphoneaudioplayer.h
changeset 0 5f000ab63145
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  Audio player for playing audio sample or tone file.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CPHONEAUDIOPLAYER_H
       
    20 #define CPHONEAUDIOPLAYER_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <mdaaudiosampleplayer.h>
       
    25 #include <mdaaudiotoneplayer.h>
       
    26 
       
    27 // CLASS DECLARATION
       
    28 class MPhoneAudioPlayerObserver;
       
    29 class C3DRingingToneInterface;
       
    30 class CPhoneRingingTone;
       
    31 class  CAudioOutput;
       
    32  
       
    33 /**
       
    34 *  Audio player for playing audio sample or tone file. 
       
    35 *
       
    36 *  @since 1.0
       
    37 */
       
    38 class CPhoneAudioPlayer :
       
    39     public CBase,
       
    40     private MMdaAudioPlayerCallback,
       
    41     private MMdaAudioToneObserver
       
    42     {
       
    43     public:
       
    44 
       
    45         enum TAudioPlayerStatus
       
    46             {
       
    47             EToneLoading,
       
    48             EToneReady,
       
    49             ETonePlaying
       
    50             };
       
    51 
       
    52         enum TRingingType
       
    53             {
       
    54             ETypeRinging,
       
    55             ETypeRingingOnce,
       
    56             ETypeAscending
       
    57             };
       
    58 
       
    59     public:  // Constructors and destructor
       
    60         
       
    61         /**
       
    62         * Two-phased constructor.
       
    63         * @param aRingingTone The ringing tone
       
    64         * @param aPriority The priority for the playing
       
    65         * @param aPreference The preference value
       
    66         * @param aObserver Audio player observer
       
    67         * @param aId The id of this audio player
       
    68         * @param aMdaServer The reference to media server
       
    69         * @param aExtSecNeeded ETrue if DRM extend security is needed
       
    70         * @return The instance of the audio player.
       
    71         */
       
    72         static CPhoneAudioPlayer* NewL( 
       
    73             const CPhoneRingingTone& aRingingTone, 
       
    74             TInt aPriority, 
       
    75             TUint aPreference,
       
    76             MPhoneAudioPlayerObserver& aObserver, 
       
    77             TInt aId = 0,
       
    78             CMdaServer* aMdaServer = NULL,
       
    79             TBool aExtSecNeeded = EFalse );
       
    80 
       
    81         /**
       
    82         * Two-phased constructor.
       
    83         * @param aRingingTone The ringing tone
       
    84         * @param aPriority The priority for the playing
       
    85         * @param aPreference The preference value
       
    86         * @param aObserver Audio player observer
       
    87         * @param aId The id of this audio player
       
    88         * @param aMdaServer The reference to media server
       
    89         * @param aExtSecNeeded ETrue if DRM extend security is needed
       
    90         * @return The instance of the audio player. NULL if the function fails.
       
    91         */
       
    92         static CPhoneAudioPlayer* New( 
       
    93             const CPhoneRingingTone& aRingingTone, 
       
    94             TInt aPriority, 
       
    95             TUint aPreference,
       
    96             MPhoneAudioPlayerObserver& aObserver, 
       
    97             TInt aId = 0,
       
    98             CMdaServer* aMdaServer = NULL,
       
    99             TBool aExtSecNeeded = EFalse );
       
   100             
       
   101         /**
       
   102         * Two-phased constructor.
       
   103         * @param aFileName The ringing tone file name.
       
   104         * @param aPriority The priority for the playing
       
   105         * @param aPreference The preference value
       
   106         * @param aObserver Audio player observer
       
   107         * @param aId The id of this audio player
       
   108         * @param aMdaServer The reference to media server
       
   109         * @param aExtSecNeeded ETrue if DRM extend security is needed
       
   110         * @return The instance of the audio player.
       
   111         */
       
   112         static CPhoneAudioPlayer* NewL( 
       
   113             const TDesC& aFileName, 
       
   114             TInt aPriority, 
       
   115             TUint aPreference,
       
   116             MPhoneAudioPlayerObserver& aObserver, 
       
   117             TInt aId = 0,
       
   118             CMdaServer* aMdaServer = NULL,
       
   119             TBool aExtSecNeeded = EFalse );            
       
   120 
       
   121         /**
       
   122         * Two-phased constructor, take audio from descriptor.
       
   123         *
       
   124         * @param aSequence sequence to be played.
       
   125         * @param aPriority priority of tone.
       
   126         * @param aPreference preference of tone.
       
   127         * @param aObserver observer.
       
   128         * @param aId identifier, used in observer interface 
       
   129         *            calls.
       
   130         * @param aMdaServer The reference to media server
       
   131         */
       
   132         static CPhoneAudioPlayer* NewSeqL(
       
   133             const TDesC8& aSequence,
       
   134             TInt aPriority,
       
   135             TUint aPreference,
       
   136             MPhoneAudioPlayerObserver& aObserver, 
       
   137             TInt aId = 0,
       
   138             CMdaServer* aMdaServer = NULL );
       
   139          
       
   140         /**
       
   141         * Two-phased constructor, takes Text-To-Speech text to be played.
       
   142         * @since Series 60 3.0
       
   143         * @param aText Text to be pronounced.
       
   144         * @param aPriority priority of tone.
       
   145         * @param aPreference preference of tone.
       
   146         * @param aObserver observer.
       
   147         * @param aId identifier, used in observer interface 
       
   148         *            calls.
       
   149         */        
       
   150         static CPhoneAudioPlayer* NewTtsL(
       
   151             const TDesC& aText,
       
   152             TInt aPriority,
       
   153             TUint aPreference,
       
   154             MPhoneAudioPlayerObserver& aObserver, 
       
   155             TInt aId = 0);
       
   156         
       
   157         /**
       
   158         * Destructor.
       
   159         */
       
   160         ~CPhoneAudioPlayer();
       
   161        
       
   162     public: // new function
       
   163 
       
   164         /**
       
   165         * Play the audio file or tone
       
   166         * @param aRingingType 
       
   167         * @param aVolume take value from 1 to 10
       
   168         * @param aTTsToBePlayed
       
   169         */
       
   170         void Play(
       
   171             TRingingType aRingType,
       
   172             TInt aVolume,
       
   173             TBool aTTsToBePlayed );
       
   174 
       
   175         /**
       
   176         * Stop current file playing
       
   177         */
       
   178         void StopPlaying();
       
   179         
       
   180           
       
   181         /**
       
   182         * Sets new volumes and ramptimes.
       
   183         * @param aVolume -volume to be set
       
   184         * @param aRamptime -ramptime to be set.
       
   185         */           
       
   186         void SetNewVolumeAndRamptime( TInt aVolume, TInt aRamptime );
       
   187         
       
   188         /**
       
   189         * Re starts playing.
       
   190         */
       
   191         void ReStartPlaying();
       
   192         /**
       
   193         * Enable or disable TTs playing.
       
   194         * @param aTTsToBePlayed
       
   195         */
       
   196         void SetTTsToBePlayed( TBool aTTsToBePlayed );
       
   197         
       
   198         /**
       
   199         * Sets volume level to zero.
       
   200         * @since Series 60 3.1
       
   201         */  
       
   202         void MutePlaying();
       
   203       
       
   204 
       
   205     private: //from base class
       
   206 
       
   207         /**
       
   208         * from MMdaAudioPlayerCallback
       
   209         */
       
   210         virtual void MapcInitComplete(
       
   211             TInt aError, 
       
   212             const TTimeIntervalMicroSeconds& aDuration );
       
   213 
       
   214         /**
       
   215         * from MMdaAudioPlayerCallback
       
   216         */
       
   217         virtual void MapcPlayComplete( TInt aError );
       
   218 
       
   219         /**
       
   220         * from MMdaAudioToneObserver
       
   221         */
       
   222         virtual void MatoPrepareComplete(TInt aError);
       
   223 
       
   224         /**
       
   225         * from MMdaAudioToneObserver
       
   226         */
       
   227         virtual void MatoPlayComplete(TInt aError);
       
   228         
       
   229     private:
       
   230 
       
   231         enum TAudioDataFormat
       
   232             {
       
   233             EFormatTone,
       
   234             EFormatSample,
       
   235             EFormatTts // Text-To-Speech
       
   236             };
       
   237 
       
   238         /**
       
   239         * C++ constructor.
       
   240         */
       
   241         CPhoneAudioPlayer( 
       
   242             TAudioDataFormat aDataFormat,
       
   243             MPhoneAudioPlayerObserver& aObserver, 
       
   244             TInt aPriority, 
       
   245             TUint aPreference,
       
   246             TInt aId );
       
   247 
       
   248         /**
       
   249         * Symbian OS constructor.
       
   250         */
       
   251         void ConstructL( 
       
   252             const TDesC& aFileName, CMdaServer* aMdaServer );
       
   253 
       
   254         /**
       
   255         * Symbian OS constructor.
       
   256         */
       
   257         void ConstructSeqL( 
       
   258             const TDesC8& aSequence,
       
   259             CMdaServer* aMdaServer ); 
       
   260 
       
   261         /**
       
   262         * Symbian OS constructor for the Text-To-Speech option
       
   263         * @since Series 60 3.0
       
   264         */
       
   265         void ConstructTtsL( 
       
   266             const TDesC& aTtsText, 
       
   267             TInt aPriority,
       
   268             TUint aPreference );
       
   269 
       
   270         /**
       
   271         * Do the playing stuff
       
   272         */
       
   273         void DoPlay();
       
   274 
       
   275         /**
       
   276         * Ser tinging type properties
       
   277         */
       
   278         void SetRingingTypeProperties();
       
   279 
       
   280         /**
       
   281         * Call back function for timer
       
   282         */
       
   283         static TInt TimerCallBack( TAny* aAny );
       
   284 
       
   285         /**
       
   286         * Handle timer events
       
   287         */
       
   288         void HandleTimerEvent();
       
   289         
       
   290         /*
       
   291         * Convert volume to the scale used by hardware
       
   292         * @param aVolume volume to be altered
       
   293         * @return TInt   new volume
       
   294         */
       
   295         TInt ConvertVolume( TInt aVolume );
       
   296 
       
   297     private:    // Data  
       
   298 
       
   299         // The format of audio data, audio sample file or tone file
       
   300         TAudioDataFormat iFormat;
       
   301 
       
   302         // Observer for error handling
       
   303         MPhoneAudioPlayerObserver& iObserver;
       
   304 
       
   305         // Priority. It's only used in playing tone file
       
   306         const TInt iPriority; 
       
   307         // Preference. Only used for tone file
       
   308         const TUint iPreference; 
       
   309 
       
   310         // Identifier number
       
   311         TInt iId;
       
   312 
       
   313         // Player for tone file.
       
   314         CMdaAudioToneUtility* iTonePlayer;
       
   315 
       
   316         // Player for audio file.
       
   317         CMdaAudioPlayerUtility* iSamplePlayer;
       
   318 
       
   319         // Player for the Text-To-Speech texts
       
   320         CMdaAudioPlayerUtility* iTtsPlayer;
       
   321 
       
   322         // The status of the player
       
   323         TAudioPlayerStatus iPlayerStatus;
       
   324 
       
   325         // How does the file played. It's only used if the player
       
   326         // is playing the file
       
   327         TRingingType iRingType;
       
   328 
       
   329         // Volume
       
   330         TInt iVolume;
       
   331 
       
   332         // For ascending and descending used for set current volume
       
   333         TInt iCurrentVolume;
       
   334 
       
   335         // Used by sample player
       
   336         TBool iToBePlaying;
       
   337 
       
   338         // Store for sequence.
       
   339         HBufC8* iSequence;
       
   340         
       
   341         // Store for the TTS source string
       
   342         HBufC8* iTtsText;
       
   343 
       
   344         // 3D Audio ringing tone plugin
       
   345         C3DRingingToneInterface* i3DPlugin;
       
   346         
       
   347         // Flag to  indicate whether we need to play TTs or not
       
   348         TBool iTTsToBePlayed;
       
   349         
       
   350         // Ringingtone output
       
   351         CAudioOutput* iAudioOutput; 
       
   352     };
       
   353 
       
   354 #endif      // CPHONEAUDIOPLAYER_H   
       
   355             
       
   356 // End of File