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 :
- (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 undeclar开发者_运维技巧ed !
How can I declare playpause inside MyAudioSessionInterruptionListener ?
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
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");
}
}
精彩评论