audiorecordview.cpp
来自「《UIQ 3 The Complete Guide》书的源代码」· C++ 代码 · 共 582 行 · 第 1/2 页
CPP
582 行
//
// AudioRecordView.cpp - Record audio
//
// Copyright (C) UIQ Technology AB, 2007
//
// This material is provided "as is" without any warranty to its performance or functionality.
// In no event shall UIQ Technology be liable for any damages whatsoever arising out of the
// use or inabilty to use this material.
//
#include "AudioRecordView.h"
#include "SignedAppUids.h"
#include "SignedApp.hrh"
#include <SignedApp_0x20000462.rsg>
#include <QikCommand.h>
#include <QikAppUi.h>
#include <QikApplication.h>
#include <eikchlst.h>
#include <QikNumberEditor.h>
#include <QikSimpleDialog.h>
//////////////////////////////////////////////////////////////////////////////////
// Dynamically creates the choice list entry content displayed to user as the list of
// possible codecs that can be chosen between
class CCodecChoiceListArray : public CBase, public MDesCArray
{
protected:
// from MDesCArray
TInt MdcaCount() const;
TPtrC MdcaPoint(TInt aIndex) const;
public:
CCodecChoiceListArray(RArray<TFourCC>& aDataTypes);
protected:
RArray<TFourCC>& iDataTypes;
TBuf<4> iData;
};
CCodecChoiceListArray::CCodecChoiceListArray(RArray<TFourCC>& aDataTypes) :
iDataTypes(aDataTypes)
{}
TInt CCodecChoiceListArray::MdcaCount() const
// report number of entries in the choice list
{
return(iDataTypes.Count());
}
TPtrC CCodecChoiceListArray::MdcaPoint(TInt aIndex) const
// Extract one of the TFourCC objects and present it as text
{
TUint8 bb[4];
TPtr8 q(&bb[0],0,4); // define descriptor pointer to the actual data held by bb[]
iDataTypes[aIndex].FourCC(&q);
MUTABLE_CAST(CCodecChoiceListArray*,this)->iData.Copy(q); // 8-bit to TText conversion
return(iData);
}
//////////////////////////////////////////////////////////////////////////////////
// Dynamically creates the choice list entry content displayed to user as the list of
// possible bitfields, sample rates, channels
class CChoiceListArray : public CBase, public MDesCArray
{
protected:
// from MDesCArray
TInt MdcaCount() const;
TPtrC MdcaPoint(TInt aIndex) const;
public:
CChoiceListArray(RArray<TUint>& aInfo);
protected:
RArray<TUint>& iInfo;
TBuf<16> iData;
};
CChoiceListArray::CChoiceListArray(RArray<TUint>& aInfo) :
iInfo(aInfo)
{}
TInt CChoiceListArray::MdcaCount() const
// report number of entries in the choice list
{
return(iInfo.Count());
}
TPtrC CChoiceListArray::MdcaPoint(TInt aIndex) const
// Extract one of the TUints from the list and present it as text
{
MUTABLE_CAST(CChoiceListArray*,this)->iData.Num(iInfo[aIndex]);
return(iData);
}
//////////////////////////////////////////////////////////////////////////////////
// Display some visual feedback to the user that recording is occuring
class CAudioRecordingProgressDialog : public CQikSimpleDialog
{
protected:
void HandleCommandL(CQikCommand& aCommand);
void PostLayoutDynInitL();
public:
CAudioRecordingProgressDialog(CMdaAudioRecorderUtility* aRecorder);
TInt ConstructAndRunLD();
protected:
CMdaAudioRecorderUtility* iRecorder;
};
CAudioRecordingProgressDialog::CAudioRecordingProgressDialog(CMdaAudioRecorderUtility* aRecorder) :
iRecorder(aRecorder)
{}
TInt CAudioRecordingProgressDialog::ConstructAndRunLD()
{
return(ExecuteLD(R_AUDIO_RECORDING_PROGRESS_DIALOG));
}
void CAudioRecordingProgressDialog::PostLayoutDynInitL()
//
// Dialog been laid out and configured. We can start recording content now.
//
{
// calling this will call back CAudioRecordView::MoscoStateChangeEvent() to change states
// this method requires the UserEnvironment Capability. Without it we wont start recording,
// the MoscoStateChangeEvent() will be called back with aErrorCode == -46
iRecorder->SetPosition(TTimeIntervalMicroSeconds(0));
TRAPD(err,iRecorder->RecordL());
// NOTE: the TRAPD() is required in CQikSimpleDialog - because if the RecordL() ever leaves,
// e.g. KErrNotSupported, the leave will cause a KernExec-3 somewhere in the CQikSimpleDialog
// code!
}
void CAudioRecordingProgressDialog::HandleCommandL(CQikCommand& aCommand)
{
switch (aCommand.Id())
{
case EAppCmdStop:
iRecorder->Stop();
CloseDialog(KErrNone);
break;
default:
CQikSimpleDialog::HandleCommandL(aCommand);
break;
}
}
//////////////////////////////////////////////////////////////////////////////////
CAudioRecordView::~CAudioRecordView()
{
TidyUpSoundRecorder();
}
CAudioRecordView::CAudioRecordView(CQikAppUi& aAppUi,CAppEngine* aEngine) :
CQikViewBase(aAppUi,KViewIdListView),iEngine(aEngine)
{}
TVwsViewId CAudioRecordView::ViewId() const
//
// All views are uniquely identified within the entire system. A TVwsViewId consists of
// the application uid (uid3) and app specific view uid
//
{
return(KViewIdAudioRecordView);
}
void CAudioRecordView::HandleCommandL(CQikCommand& aCommand)
//
// Handle the commands coming in from the controls that can deliver cmds..
//
{
switch (aCommand.Id())
{
case EAppCmdRecord:
if (iOpenedOk)
StartRecordingL();
break;
default: // e.g. the back button...
CQikViewBase::HandleCommandL(aCommand);
break;
}
}
// Currently SE devices only support a single recording file type + param set.
// #ifdef __UIQ_SUPPORTS_MULTIPLE_RECORDING_TYPES
void CAudioRecordView::StartRecordingL()
//
// Set up the recorder with the user chosen params and begin recording
//
{
// configure the recording params from the choice lists. Dont forget that we might have
// a blank choice list (e.g. for bitrate), empty choice lists will have CurrentItem()==-1
#ifdef __UIQ_SUPPORTS_MULTIPLE_RECORDING_TYPES
// codec
CEikChoiceList* cl=LocateControlByUniqueHandle<CEikChoiceList>(EAppChoiceList2);
TInt index=cl->CurrentItem();
if (index>=0)
iRecorder->SetDestinationDataTypeL(iDataTypes[index]);
// bitrate
cl=LocateControlByUniqueHandle<CEikChoiceList>(EAppChoiceList3);
index=cl->CurrentItem();
if (index>=0)
iRecorder->SetDestinationBitRateL(iBitRates[index]);
// sample rate
cl=LocateControlByUniqueHandle<CEikChoiceList>(EAppChoiceList4);
index=cl->CurrentItem();
if (index>=0)
iRecorder->SetDestinationSampleRateL(iSampleRates[index]);
// channels
cl=LocateControlByUniqueHandle<CEikChoiceList>(EAppChoiceList5);
index=cl->CurrentItem();
if (index>=0)
iRecorder->SetDestinationNumberOfChannelsL(iChannels[index]);
// gain
CQikNumberEditor* numEd=LocateControlByUniqueHandle<CQikNumberEditor>(EAppEdwin1);
iRecorder->SetGain(numEd->Value());
// balance
numEd=LocateControlByUniqueHandle<CQikNumberEditor>(EAppEdwin2);
iRecorder->SetPlaybackBalance(numEd->Value());
#else
#ifdef __WINS__
iRecorder->SetDestinationDataTypeL(KMMFFourCCCodePCMU8);
#else
// this is required on real devices to cause recording to work..
// Emul only seems to support wav..., real device only supports AMR despite the info being reported by the
// system when we ask what is supported...
iRecorder->SetDestinationDataTypeL(KMMFFourCCCodeAMR);
iRecorder->SetDestinationBitRateL(12200);
iRecorder->SetDestinationSampleRateL(8000);
iRecorder->SetDestinationNumberOfChannelsL(TMdaAudioDataSettings::EChannelsMono);
iRecorder->SetGain(iRecorder->MaxGain());
#endif // __WINS__
#endif // __UIQ_SUPPORTS_MULTIPLE_RECORDING_TYPES
// and start recording, display a progress dialog showing some activity...
(new(ELeave)CAudioRecordingProgressDialog(iRecorder))->ConstructAndRunLD();
}
void CAudioRecordView::TidyUpSoundRecorder()
//
// Tidy up all the sound recorder resources used.
//
{
// shutdown the current recorder object
if (iRecorder)
{
if (iRecorder->State()==CMdaAudioClipUtility::ERecording)
iRecorder->Stop();
delete(iRecorder);
iRecorder=NULL;
}
iOpenedOk=FALSE;
// release the previous lists
iDataTypes.Close();
iBitRates.Close();
iSampleRates.Close();
iChannels.Close();
}
void CAudioRecordView::ResetChoiceLists()
//
// Reset the choice lists given there is no data available.
//
{
// Codecs
CEikChoiceList* cl=LocateControlByUniqueHandle<CEikChoiceList>(EAppChoiceList2);
cl->SetCurrentItem(-1);
// bitRates
cl=LocateControlByUniqueHandle<CEikChoiceList>(EAppChoiceList3);
cl->SetCurrentItem(-1);
// sample rates
cl=LocateControlByUniqueHandle<CEikChoiceList>(EAppChoiceList4);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?