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