2014-04-01 43 views
1

這裏是ObjectAL/OpenAL的iOS版的文件:ObjectAL/OpenAL for iOS - 在運行時停止/暫停/靜音?

http://kstenerud.github.io/ObjectAL-for-iPhone/documentation/index.html#use_objectal_sec

你在這個世界怎麼可以簡單地停止/暫停/靜音運行時特定的聲音(不是所有的聲音)?

我試過使用OALSimpleAudio,OpenAL對象和OALAudioTrack沒有運氣。

我正在使用cocos2d v3。

+0

ALSource是你在找什麼。通過ALChannelSource,您可以停止/暫停/俯仰等所有在同一頻道播放的聲源。 – LearnCocos2D

+0

好的。很感謝!任何樣品? –

回答

1

您可以按照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 

等。希望這會有所幫助。