2

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 :

- (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]; but I get an error playpause undeclared !

How can I declare playpause inside MyAudioSessionInterruptionListener ?

Yuliani Noriega
  • 1,085
  • 12
  • 23
Ben
  • 1,031
  • 3
  • 17
  • 31

2 Answers2

1

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. 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..

Hope that helps

Daniel
  • 22,363
  • 9
  • 64
  • 71
  • Thank you for this fast reply. Like you said this class is not in AudioStreamer, so how is it possible to pass this class in the inClientData argument ? – Ben Sep 13 '11 at 21:06
  • well, its just bytes, so perhaps an array might work for your purposes, I would probably make AudioStreamer have a delegate which gets informed of interruptions and you can have your class be the delegate so it gets informed of the interruption, then you can call a method on AudioStreamer which will call the delegate method – Daniel Sep 13 '11 at 21:10
-2

So after testing all posibility the best was using 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");
}


}
Ben
  • 1,031
  • 3
  • 17
  • 31
  • this is not the answer to your question, the answer to your question is what i have posted above...your question being why doesnt your line of code [self playpause] work – Daniel Sep 15 '11 at 19:51
  • You are true Daniel my question was about [self playpause] and thank you because you put me on the right way with your answer and details, but I was also looking for the solution at the same time, so I just wanted to share the code who was working in this case for me ... In case if somebody needed. – Ben Sep 15 '11 at 23:31