Game Development Reference
In-Depth Information
Now audio playback is very simple. Declare a global audio thread:
clAudioThread g_Audio;
Start it from the main thread and wait until initialization completes:
g_Audio.Start( iThread::Priority_Normal );
g_Audio.Wait();
We can invoke other useful initialization routines between the g_
Audio.Start() and g_Audio.Wait() calls, to take advantage of
asynchronous initialization.
Create and conigure a new audio source and play it:
Music = new clAudioSource();
Music->BindWaveform(new
clModPlugProvider( LoadFileAsBlob("test.xm")) );
Music->LoopSound( true );
Music->Play();
All audio management is now done on another thread.
There's moreā€¦
Our audio thread is capable of playing different types of audio iles such as .ogg , .xm , .it,
and .s3m iles. You can hide the creation of an appropriate wavedata provider by adding
another method to AudioSource . Just switch the selection based on the ile extension to
create ModPlugProvider or OggProvider instances. We leave this as an exercise for you.
See also
F The Initializing OpenAL and playing the .wav iles, Decoding Ogg Vorbis iles ,
Decoding tracker music using ModPlug , and Streaming sounds recipes in Chapter 5 ,
Cross-platform Audio Streaming
Shutting down the application
Smartphones' batteries are very limited making mobile devices very sensitive to any
background activities they run. Our previous application samples stayed alive after the
user switched to another activity. This means that instead of respecting the Android
activity lifecycle ( http://developer.android.com/training/basics/activity-
lifecycle ) and pausing our application, we continued to waste precious system resources
in the background. It's time we learnt how to handle the onPause() Android callback in our
native code.
 
Search WWH ::




Custom Search