Playing sound on the N8 device
-
I have been trying to get sound to work on the n8, and so far without success. I have tried QSound, Phonon, and SoundMixerController from the instructions from the link http://tamss60.tamoggemon.com/2010/04/22/proper-sound-and-background-music-with-qt-for-symbian/. I am doing this for a game so I would like to play multiple sounds at once so I would prefer the SoundMixerController.
Here is some of the code.
SoundTest.pro file
@
###########################
QT += core gui
phonon
phononfixTARGET = SoundTest
TEMPLATE = appSOURCES += main.cpp
SoundTestWidget.cpp
s60sound/SoundMixerContainer.cpp
s60sound/MyActive.cpp
s60sound/CWavLoader.cpp
s60sound/CSndMixer.cpp
s60sound/CMixerThread.cppHEADERS += SoundTestWidget.h
s60sound/TSample.h
s60sound/TAudioShared.h
s60sound/SoundMixerContainer.h
s60sound/MyActive.h
s60sound/CWavLoader.h
s60sound/CSndMixer.h
s60sound/CMixerThread.hsymbian {
TARGET.UID3 = 0xe3fd4b63
include($$PWD/../../symbianpkgrules.pri)
LIBS += -lcone
-leikcore
-lefsrv
-lavkon
-lmediaclientaudio
-lmediaclientaudiostream
-lcentralrepository
-lhal
-lws32
myFiles.sources = rsc*.wav
DEPLOYMENT += myFilessymbian-abld|symbian-sbsv2 { # ro-section in gui can exceed default allocated space, so move rw-section a little further QMAKE_LFLAGS.ARMCC += --rw-base 0x800000 QMAKE_LFLAGS.GCCE += -Tdata 0xC00000 } # TARGET.CAPABILITY += TARGET.EPOCSTACKSIZE = 0x14000 TARGET.EPOCHEAPSIZE = 0x020000 0x800000
}
###########################
@CSoundMixerContainer.cpp
@
###########################
/*- Copyright © 2008 Nokia Corporation.
*/
#include "SoundMixerContainer.h"
#include <eikenv.h>
#include "CSndMixer.h"
#include "CWavLoader.h"// Profile settings
#include <centralrepository.h>
#include <ProfileEngineSDKCRKeys.h>_LIT(KEffectFile, "cow.wav");
CSoundMixerContainer::CSoundMixerContainer()
{}
CSoundMixerContainer* CSoundMixerContainer::NewL()
{
CSoundMixerContainer* self = NewLC();
CleanupStack::Pop( self );
return self;
}CSoundMixerContainer* CSoundMixerContainer::NewLC()
{
CSoundMixerContainer* self = new( ELeave )CSoundMixerContainer();
CleanupStack::PushL( self );
self->ConstructL();
return self;
}void CSoundMixerContainer::ConstructL()
{
// load sound samples
CWavLoader* wavLoader = CWavLoader::NewLC();iEffectCow = wavLoader->LoadL(KEffectFile()); CleanupStack::PopAndDestroy( wavLoader ); // create sound mixer iSndMixer = CSndMixer::NewL(); }
CSoundMixerContainer::~CSoundMixerContainer()
{
delete iSndMixer;
delete iEffectCow.iData;
}void CSoundMixerContainer::HandleGainingForeground()
{
// application gets focused
// this function is called first time when application starts
// that's why there's no need to start timer and sound in constructor
// if the mixer is manually stopped, it should not be started when focus is gained
StartMixer();
}void CSoundMixerContainer::HandleLosingForeground()
{
// application loses focus
// so stop moving blocks and playing sound
StopMixer();
}void CSoundMixerContainer::StartMixer()
{
if (!IsProfileSilent())
{
iSndMixer->Resume();
}
}void CSoundMixerContainer::StopMixer()
{
iSndMixer->Pause();
}void CSoundMixerContainer::PlayCow()
{
iSndMixer->Play( iEffectCow, 2, 16000, 256 );
}void CSoundMixerContainer::VolumeUp()
{
TInt volume = iSndMixer->Volume();
volume += 10;
if( volume > 100 ) volume = 100;iSndMixer->SetVolume( volume );
}void CSoundMixerContainer::VolumeDown()
{
TInt volume = iSndMixer->Volume();
volume -= 10;
if( volume < 0 ) volume = 0;iSndMixer->SetVolume( volume );
}// ---------------------------------------------------------
// CSoundMixerContainer::IsProfileSilent()
// Used for determining whether current profile is silent.
// This means that sounds should not be played.
// ---------------------------------------------------------TBool CSoundMixerContainer::IsProfileSilent()
{
return false;
CRepository* centralRepository = CRepository::NewLC(KCRUidProfileEngine);
TInt value;
// Get the ringing type of the active profile
User::LeaveIfError(centralRepository->Get(KProEngActiveRingingType, value));
CleanupStack::PopAndDestroy(centralRepository);
return (value == 4); // 4 = Silent
}// End of File
###########################
@@
//Code to play sounds
###########################
CSoundMixerContainer *m_sounds;m_sounds = new CSoundMixerContainer();
m_sounds->ConstructL();m_sounds->PlayCow();
###########################
@[EDIT: code formatting, Volker]
- Copyright © 2008 Nokia Corporation.