简体   繁体   English

iOS音频中断

[英]IOS Audio interruption

I am developing an audio streaming app with the old AudioStreamer from Matt and i am trying to make the interruption (when receive a call) by using : 我正在使用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");
        }
}

My problem is I am trying to call the function "playpause" with the [self playpause]; 我的问题是我试图用[self playpause]调用函数“ playpause”; but I get an error playpause undeclared ! 但是我出现了一个未声明的playpause错误!

How can I declare playpause inside MyAudioSessionInterruptionListener ? 如何在MyAudioSessionInterruptionListener内部声明playpause?

its not [self playPause] it should be [streamer playpause] assuming the AudioStreamer class is the class with the method...The listener method is a static C function outside your class, therefore you cant call a method on self, since self implies you are inside the instance of the class. 它不是[self playPause],应该是[streamer playpause],假设AudioStreamer类是带有该方法的类... listener方法是您类之外的静态C函数,因此您不能在self上调用方法,因为self意味着您位于该类的实例内。 If the class with the method is not the AudioStreamer then you are going to have to pass that class along as well in the inClientData argument in order to be able to get a hold of it.. 如果带有该方法的类不是AudioStreamer,那么您将必须在inClientData参数中传递该类,以便能够掌握它。

Hope that helps 希望能有所帮助

So after testing all posibility the best was using Notification. 因此,在测试所有可能性之后,最好的方法是使用Notification。

Here the code : 这里的代码:

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");
}


}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM