camerauis/cameraxui/cxengine/src/cxesoundplayersymbian.cpp
changeset 19 d9aefe59d544
child 37 64817133cd1d
equal deleted inserted replaced
3:8b2d6d0384b0 19:d9aefe59d544
       
     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 #include <cxesoundplayersymbian.h>
       
    18 #include <AudioPreference.h>
       
    19 #include "cxutils.h"
       
    20 #include "cxecameradevicecontrolsymbian.h"
       
    21 #include "cxestate.h"
       
    22 
       
    23 const TUint KCxeAudioPriority = KAudioPriorityCameraTone;
       
    24 //const TUint KCxeAudioPriority = KAudioPriorityVideoRecording;
       
    25 
       
    26 _LIT(KCxeCaptureSound,    "z:\\system\\sounds\\digital\\capture.wav");
       
    27 _LIT(KCxeVideoStartSound, "z:\\system\\sounds\\digital\\videoStart.wav");
       
    28 _LIT(KCxeVideoStopSound,  "z:\\system\\sounds\\digital\\videoStop.wav");
       
    29 _LIT(KCxeAutoFocusSound,  "z:\\system\\sounds\\digital\\autoFocus.wav");
       
    30 
       
    31 
       
    32 CxeSoundPlayerSymbian::CxeSoundPlayerSymbian(CaptureSound soundId) :
       
    33     CxeStateMachine("CxeSoundPlayerSymbian"),
       
    34     mAudioPlayer(NULL),
       
    35     mSoundId(soundId)
       
    36 {
       
    37     CX_DEBUG_ENTER_FUNCTION();
       
    38 
       
    39     qRegisterMetaType<CxeSoundPlayerSymbian::State>();
       
    40     initializeStates();
       
    41 
       
    42     doOpen();
       
    43     CX_DEBUG_EXIT_FUNCTION();
       
    44 }
       
    45 
       
    46 CxeSoundPlayerSymbian::~CxeSoundPlayerSymbian()
       
    47 {
       
    48     CX_DEBUG_ENTER_FUNCTION();
       
    49 
       
    50     delete mAudioPlayer;
       
    51 
       
    52     CX_DEBUG_EXIT_FUNCTION();
       
    53 }
       
    54 
       
    55 void CxeSoundPlayerSymbian::play()
       
    56 {
       
    57     CX_DEBUG_ENTER_FUNCTION();
       
    58     CX_DEBUG(("CxeSoundPlayerSymbian::play mSoundId: %d, state: %d", mSoundId, state()));
       
    59 
       
    60     // Only play the capture sound if CMdaAudioPlayerUtility is initialised
       
    61     if (state() == Ready) {
       
    62         //! @todo: Define & implement what to do, when sound is already playing.
       
    63         // Important for sequence mode.
       
    64         setState(Playing);
       
    65         mAudioPlayer->Play();
       
    66     } else if( state() == NotReady ) {
       
    67         // Here sound loading has failed.
       
    68         // Emit signal with error code.
       
    69         emit playComplete(KErrNotReady);
       
    70     } 
       
    71 
       
    72     CX_DEBUG_EXIT_FUNCTION();
       
    73 }
       
    74 
       
    75 
       
    76 void CxeSoundPlayerSymbian::MapcInitComplete(TInt aStatus, const TTimeIntervalMicroSeconds &/*aDuration*/)
       
    77 {
       
    78     CX_DEBUG_IN_FUNCTION();
       
    79     CX_DEBUG(("MapcInitComplete aStatus: %d", aStatus));
       
    80 
       
    81     if (aStatus) {
       
    82         setState(NotReady);
       
    83     } else {
       
    84         setState(Ready);
       
    85     }
       
    86 }
       
    87 
       
    88 void CxeSoundPlayerSymbian::MapcPlayComplete(TInt aStatus)
       
    89 {
       
    90     CX_DEBUG_IN_FUNCTION();
       
    91     CX_DEBUG(("MapcPlayComplete aStatus: %d", aStatus));
       
    92 
       
    93     if (aStatus != KErrNone && aStatus != KErrInUse) {
       
    94         // An error occurred. Close and reopen sound player to be sure.
       
    95         mAudioPlayer->Close();
       
    96         setState(NotReady);
       
    97         doOpen();
       
    98     } else {
       
    99         setState(Ready);
       
   100     }
       
   101 
       
   102     emit playComplete(aStatus);
       
   103 }
       
   104 
       
   105 void CxeSoundPlayerSymbian::doOpen()
       
   106 {
       
   107     CX_DEBUG(("Calling OpenFileL for sound %d", mSoundId));
       
   108     TInt error = KErrNone;
       
   109     const TDesC* filename = 0;
       
   110     switch (mSoundId) {
       
   111     case StillCapture:
       
   112         filename = &KCxeCaptureSound;
       
   113         break;
       
   114     case VideoCaptureStart:
       
   115         filename = &KCxeVideoStartSound;
       
   116         break;
       
   117     case VideoCaptureStop:
       
   118         filename = &KCxeVideoStopSound;
       
   119         break;
       
   120     case  AutoFocus:
       
   121         filename = &KCxeAutoFocusSound;
       
   122         break;
       
   123     default:
       
   124         // sound is not known
       
   125         mSoundId = Unknown;
       
   126         break;
       
   127     }
       
   128 
       
   129     if (filename) {
       
   130         if (mAudioPlayer) {
       
   131             delete mAudioPlayer;
       
   132             mAudioPlayer = 0;
       
   133         }
       
   134         TRAP( error, mAudioPlayer =
       
   135                       CMdaAudioPlayerUtility::NewFilePlayerL(*filename, *this, KCxeAudioPriority,
       
   136                                                         TMdaPriorityPreference(KAudioPrefCamera)) );
       
   137         if (!error) {
       
   138             setState(Opening);
       
   139         } else {
       
   140             setState(NotReady);
       
   141         }
       
   142     } else {
       
   143         setState(NotReady);
       
   144     }
       
   145 }
       
   146 
       
   147 
       
   148 void CxeSoundPlayerSymbian::handleStateChanged(int /*newStateId*/, CxeError::Id /*error*/)
       
   149 {
       
   150     // No implementation needed, because state is not visible outside of this class
       
   151 }
       
   152 
       
   153 CxeSoundPlayerSymbian::State CxeSoundPlayerSymbian::state() const
       
   154 {
       
   155     return static_cast<State>(stateId());
       
   156 }
       
   157 
       
   158 void CxeSoundPlayerSymbian::initializeStates()
       
   159 {
       
   160     // addState(id, name, allowed next states)
       
   161     addState(new CxeState(NotReady, "NotReady", Opening));
       
   162     addState(new CxeState(Opening, "Opening", NotReady | Ready));
       
   163     addState(new CxeState(Ready, "Ready", Playing | Opening | NotReady));
       
   164     addState(new CxeState(Playing, "Playing", Ready | Opening | NotReady));
       
   165 
       
   166     setInitialState(NotReady);
       
   167 }