Reputation: 63
Here is the ObjectAL/OpenAL iOS documentation:
http://kstenerud.github.io/ObjectAL-for-iPhone/documentation/index.html#use_objectal_sec
How in the world can you simply stop/pause/mute a particular sound (not all sounds) at runtime?
I've tried using OALSimpleAudio, OpenAL Objects and OALAudioTrack with no luck.
I'm using cocos2d v3.
Upvotes: 1
Views: 1363
Reputation: 379
You can follow the examples provided in: ObjectAL demos, for instance the SingleSourceDemo.
On of them is for the ALSource that @LearnCocos2D suggested in his comment. I will try to explain it here. First, you should have the audio engine - let's say it is OALSimpleAudio. Moreover, let's assume you don't want to use it for playing effects - they will be managed by separate ALSources:
ALSource* effectSource;
ALBuffer* effectBuffer; //this is for the effect buffer
//don't reserve source for OALSimpleAudio
[OALSimpleAudio sharedInstance].reservedSources = 0;
//create the source for the effect.
source = [ALSource source];
//buffer the source file.
buffer = [[OpenALManager sharedInstance] bufferFromFile:@"audiofile.caf"];
Now you can use following methods to play/pause/pitch:
[source play:buffer loop:YES]; //play sound from buffer and loop
[source stop]; //stop
[source rewind]; //rewind sound to the beggining
[source fadeTo:0.0f duration:1.0f target:self selector:@selector(onFadeComplete:)]; //fade effect from source
[source pitchTo:0.0f duration:1.0f target:self selector:@selector(onFadeComplete:)]; //pitch effect from source
etc. Hope this will be helpful.
Upvotes: 1