2

我正在使用来自 Matt 的旧 AudioStreamer 开发一个音频流应用程序,并且我试图通过使用以下方式进行中断(当接到电话时):

- (void)MyAudioSessionInterruptionListener(void *inClientData, UInt32 inInterruptionState)
{
        AudioStreamer *streamer = (AudioStreamer*)inClientData;
        if (inInterruptionState == kAudioSessionBeginInterruption)
        {
            [streamer stop];    
            NSLog(@"kAudioSessionBeginInterruption");
        }
        else if (inInterruptionState == kAudioSessionEndInterruption)
        {
            [self playpause]; 
            NSLog(@"kAudioSessionEndInterruption");
        }
}

我的问题是我试图用 [self playpause] 调用函数“playpause”;但我得到一个错误 playpause undeclared !

如何在 MyAudioSessionInterruptionListener 中声明播放暂停?

4

2 回答 2

1

它不是 [self playPause] 它应该是 [streamer playpause] 假设 AudioStreamer 类是具有该方法的类...侦听器方法是类外部的静态 C 函数,因此您不能在 self 上调用方法,因为 self 暗示你在类的实例中。如果具有该方法的类不是 AudioStreamer,那么您将不得不在 inClientData 参数中传递该类,以便能够获得它。

希望有帮助

于 2011-09-13T20:56:24.437 回答
-2

因此,在测试了所有可能性之后,最好的方法是使用通知。

这里的代码:

void MyAudioSessionInterruptionListener(void *inClientData, UInt32 inInterruptionState)
{
if (inInterruptionState == kAudioSessionBeginInterruption) {


    [[NSNotificationCenter defaultCenter] postNotificationName:@"stopstreamer" object:nil];

    NSLog(@"kAudioSessionBeginInterruption");
}


else if (inInterruptionState == kAudioSessionEndInterruption) {

    [[NSNotificationCenter defaultCenter] postNotificationName:@"TogglePlayPause" object:nil];

    NSLog(@"kAudioSessionEndInterruption");
}


}
于 2011-09-15T01:43:24.980 回答