【问题标题】:Detect whether a sound effect is currently playing in SimpleAudioEngine在 SimpleAudioEngine 中检测当前是否正在播放音效
【发布时间】:2011-11-18 15:28:13
【问题描述】:

我想检测 [SimpleAudioEngine sharedEngine] 当前是否正在播放任何效果。对于背景音乐,有一种方法可以为您提供背景音乐是​​否正在播放的信息:

[[SimpleAudioEngine sharedEngine] isBackgroundMusicPlaying];

音效是否存在类似的东西?如果不是,我还能如何检测我是否已经在播放效果?

【问题讨论】:

    标签: objective-c cocos2d-iphone simpleaudioengine


    【解决方案1】:

    SimpleAudioEngine 没有像isBackgroundMusicPlaying 这样的方法用于效果,但你可以存储一个名为 isPlaying 的BOOL 并使用CDSoundSource

    CDSoundSource* currentSound = [[CDAudioManager sharedManager] audioSourceForChannel:kASC_Right];
    [currentSound load:audioFile];
    currentSound.delegate = self;
    currentSound.backgroundMusic = NO;
    isPlaying = YES;
    [currentSound play];
    

    然后实现回调:

    - (void) cdAudioSourceDidFinishPlaying:(CDLongAudioSource *) audioSource {
        isPlaying = NO;
    }
    

    我不知道这是否是初始化 CDSoundSource 的正确方法,因为我无耻地窃取了 this topic 的代码。也许你应该看看CDAudioManager Class Reference

    希望这有助于为您指明正确的方向。

    【讨论】:

      猜你喜欢
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      • 2013-06-28
      • 2018-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      相关资源
      最近更新 更多