0

我正在制作一个 iphone Live Radio 应用程序。我的应用程序在后台模式下运行良好。但是,如果收音机应用程序在后台模式下播放时电话响起,我的收音机就会停止。

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
4

1 回答 1

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];
            }
        };
    }
}
于 2013-01-04T05:48:08.300 回答