Cocos2d iphone iOS的ObjectAL/OpenAL-运行时停止/暂停/静音?

Cocos2d iphone iOS的ObjectAL/OpenAL-运行时停止/暂停/静音?,cocos2d-iphone,audio,Cocos2d Iphone,Audio,以下是ObjectAL/OpenAL iOS文档: 你怎么能在运行时简单地停止/暂停/静音一个特定的声音(不是所有的声音) 我尝试过使用OALSimpleAudio、OpenAL对象和OALAudioTrack,但运气不佳 我正在使用cocos2dv3 您可以遵循中提供的示例,例如SingleSourceDemo 其中之一是@LearnCos2D在其评论中建议的ALSource。我会在这里解释。 首先,您应该拥有音频引擎——假设它是OALSimpleAudio。此外,假设您不想将其用于播放效果

以下是ObjectAL/OpenAL iOS文档:

你怎么能在运行时简单地停止/暂停/静音一个特定的声音(不是所有的声音)

我尝试过使用OALSimpleAudio、OpenAL对象和OALAudioTrack,但运气不佳


我正在使用cocos2dv3

您可以遵循中提供的示例,例如SingleSourceDemo

其中之一是@LearnCos2D在其评论中建议的ALSource。我会在这里解释。 首先,您应该拥有音频引擎——假设它是OALSimpleAudio。此外,假设您不想将其用于播放效果-它们将由单独的ALSOURCE管理:

    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,您可以停止/暂停/调高/等在同一频道播放的所有声源。Ok。很酷,谢谢!附近有样品吗?