[IOS]播放音乐的过程中,处理来电接入,挂断来电的事件

来源:互联网 发布:简单网络架构图 编辑:程序博客网 时间:2024/05/13 19:29

1, 在    MyAppDelegate 的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中调用


AudioSessionInitialize(NULL, NULL, interruptionListener, (__bridge void*)self);

2, 定义函数  

void interruptionListener( void *inClientData,

                          UInt32 inInterruptionState)


void interruptionListener( void *inClientData,   UInt32 inInterruptionState)

{

MyAppDelegate *pTHIS = (__bridgeMyAppDelegate*)inClientData;

if (inInterruptionState ==kAudioSessionBeginInterruption)

{

        [pTHIS.self.viewController.playerPauseQueue];

        NSLog(@"被打断,暂停播放");

    }

elseif (inInterruptionState == kAudioSessionEndInterruption)

{

// we were playing back when we were interrupted, so reset and resume now        

        [pTHIS.self.viewController.playerStartQueue:TRUE];

        

        NSLog(@"被打断结束,重新开始播放");

}

}


原创粉丝点击