通话后停止收音机

时间:2013-01-02 05:00:10

标签: objective-c ios cocoa-touch

我正在制作iphone Live广播应用程序。我的应用程序在后台模式下工作正常。但是,如果当无线电应用程序在后台模式下播放时手机响铃,我的收音机会停止。

MP AVAudioSessionDelegateMediaPlayerOnly end interruption. Interruptor <Phone> category <completed> resumable <0>,  _state = 6
2013-01-02 10:26:24.487 Radio99[2527:707] MP endInterruptionFromInterruptor :: resuming playback at 1.000000

1 个答案:

答案 0 :(得分:0)

仅使用AudioStreamer。 (切勿在通话后使用AVAudioPlayerMPMoviePlayerController播放无线电。

NSURL *url =[NSURL URLWithString:@"http://y1.eoews.com/assets/ringtones/2012/5/18/34049/oiuxsvnbtxks7a0tg6xpdo66exdhi8h0bplp7twp.mp3"];
AudioStreamer *tempStreamer = [[AudioStreamer alloc] initWithURL:url];
self.streamer = tempStreamer;
[tempStreamer release]; [streamer start];

在后台添加此代码

- (void)applicationDidEnterBackground:(UIApplication *)application
   {

    CTCallCenter *_center = [[CTCallCenter alloc] init];

    _center.callEventHandler = ^(CTCall *call) 
        {

        if ([call.callState isEqualToString:CTCallStateIncoming]) 
            {   
                NSLog(@"Pause");
                [streamPlayer pause];
            }

        if ([call.callState isEqualToString:CTCallStateDisconnected]) 
            {
            NSLog(@"call:%@", call.callState);
            NSLog(@"Play");
            [streamPlayer start];
            }
        };
    }
}