【问题标题】:ObjectAL/OpenAL for iOS - stop/pause/mute sound at runtime?iOS 的 ObjectAL/OpenAL - 在运行时停止/暂停/静音?
【发布时间】:2014-04-01 23:03:25
【问题描述】:

这是 ObjectAL/OpenAL iOS 文档:

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

到底如何才能在运行时简单地停止/暂停/静音特定声音(不是所有声音)?

我尝试过使用 OALSimpleAudio、OpenAL Objects 和 OALAudioTrack,但没有成功。

我正在使用 cocos2d v3。

【问题讨论】:

  • ALSource 是您正在寻找的。使用 ALChannelSource,您可以停止/暂停/音高/等所有在同一频道中播放的声源。
  • 好的。酷谢谢!周围有样品吗?

标签: cocos2d-iphone audio


【解决方案1】:

您可以按照ObjectAL demos 中提供的示例进行操作,例如 SingleSourceDemo。

其中一个是@LearnCocos2D 在他的评论中建议的 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

等等。希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多