您可以按照ObjectAL demos中提供的示例進行操作,例如SingleSourceDemo。
對他們的評論是@ LearnCocos2D建議的ALSource。我會在這裏解釋一下。 首先,你應該有音頻引擎 - 假設它是OALSimpleAudio。此外,讓我們假設你不想使用它播放效果 - 它們將被單獨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"];
現在你可以用以下方法來播放/暫停/間距:
[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
等。希望這會有所幫助。
ALSource是你在找什麼。通過ALChannelSource,您可以停止/暫停/俯仰等所有在同一頻道播放的聲源。 – LearnCocos2D
好的。很感謝!任何樣品? –