【问题标题】:Stop radio after call通话后停止收音机
【发布时间】:2013-01-02 05:00:09
【问题描述】:

我正在制作一个 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

【问题讨论】:

  • [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];添加此行后,它可以在 iphone 4 上运行,但在 iphone 5 上仍然无法运行。

标签: objective-c ios cocoa-touch


【解决方案1】:

仅使用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];
            }
        };
    }
}

【讨论】:

  • [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; [[AVAudioSession sharedInstance] setActive: YES error: nil]; [[UIApplication sharedApplication]beginReceivingRemoteControlEvents];添加上面的线路和无线电工作完美!!!!
猜你喜欢
  • 2017-12-07
  • 1970-01-01
  • 1970-01-01
  • 2013-04-18
  • 1970-01-01
  • 1970-01-01
  • 2021-02-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多