Hi, I developed an application, that shows a video, i would like to have the audio output routed to the earphones, I have tried in this way:
andCode:#ifndef __AUDIOENGINE_H__ #define __AUDIOENGINE_H__ #include <MdaAudioSamplePlayer.h> // for playing audio #include "AudioOutput.h" #include "MAudioOutputObserver.h" #include <QDebug> #include <mda\\client\\utility.h> class CMySound : public CBase ,public MMdaAudioPlayerCallback,public MAudioOutputObserver { public: static CMySound* NewL(); static CMySound* NewLC(); void MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration); void MapcPlayComplete(TInt aError); void PlayL(); void SetRoutingL(CAudioOutput::TAudioOutputPreference& aAudioOutput); void SetRoutingLPrivate(); void DefaultAudioOutputChanged( CAudioOutput& aAudioOutput, CAudioOutput::TAudioOutputPreference aNewDefault ); virtual ~CMySound(); private: CMySound(); void ConstructL(); void PlayFile(); private: CMdaAudioPlayerUtility* iMyAudioPlayerUtility; CAudioOutput* iAudioOutput; }; #endif
then i put this in my widget:Code:#include "AudioEngine.h" #include <eikenv.h> #include <AudioOutput.h> #include <AknNoteWrappers.h> ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// // Standard construction sequence CMySound* CMySound::NewL() { CMySound* self = CMySound::NewLC(); CleanupStack::Pop( self ); return self; } CMySound* CMySound::NewLC() { CMySound* self = new ( ELeave ) CMySound; CleanupStack::PushL( self ); self->ConstructL(); return self; } void CMySound::ConstructL() { iMyAudioPlayerUtility = CMdaAudioPlayerUtility::NewL(*this); } CMySound::CMySound() { // No implementation required } CMySound::~CMySound() { if(iMyAudioPlayerUtility) { delete iMyAudioPlayerUtility; iMyAudioPlayerUtility = NULL; } if(iAudioOutput) { delete iAudioOutput; iAudioOutput = NULL; } } ////////////////////////////////////////////////////////////////////// // MClass/Callbacks ////////////////////////////////////////////////////////////////////// void CMySound::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/) { if(aError == KErrNone) { iMyAudioPlayerUtility->SetVolume(iMyAudioPlayerUtility->MaxVolume()); PlayFile(); } } void CMySound::MapcPlayComplete(TInt aError) { if(aError == KErrDied) { qDebug()<<"Player Died"; //CEikonEnv::InfoWinL(_L("Player died"),_L("")); } else { qDebug()<<"Play Completed"; // CEikonEnv::InfoWinL(_L("Play Completed"),_L("")); } } void CMySound::DefaultAudioOutputChanged( CAudioOutput& aAudioOutput, CAudioOutput::TAudioOutputPreference aNewDefault ) { // CEikonEnv::InfoWinL(_L("In Callback"),_L("AudioOutput Routed")); qDebug()<<"OUTPUT CHANGED"; } ////////////////////////////////////////////////////////////////////// // Audio functions ////////////////////////////////////////////////////////////////////// void CMySound::PlayL() { iMyAudioPlayerUtility->Close(); iMyAudioPlayerUtility->OpenFileL(_L("C:\\Theme.mp3")); } void CMySound::PlayFile() { iMyAudioPlayerUtility->Play(); } ////////////////////////////////////////////////////////////////////// // Audio Routing ////////////////////////////////////////////////////////////////////// void CMySound::SetRoutingL(CAudioOutput::TAudioOutputPreference& aAudioOutput) { if(iAudioOutput) { delete iAudioOutput; iAudioOutput = NULL; } iAudioOutput = CAudioOutput::NewL(*iMyAudioPlayerUtility); iAudioOutput->RegisterObserverL(*this); iAudioOutput->SetAudioOutputL(aAudioOutput); } void CMySound::SetRoutingLPrivate() { if(iAudioOutput) { delete iAudioOutput; iAudioOutput = NULL; } iAudioOutput = CAudioOutput::NewL(*iMyAudioPlayerUtility); iAudioOutput->RegisterObserverL(*this); CAudioOutput::TAudioOutputPreference aAudioOutput = CAudioOutput::EPrivate; iAudioOutput->SetAudioOutputL(aAudioOutput); }
but it returns me:Code:CMySound* sound = CMySound::NewL(); sound->SetRoutingLPrivate();
What's wrong??Code:[Qt Message] CActiveScheduler::RunIfReady() returned error: -1
Tnx so much



