AVPlayer连接丢失重新启动

我正在使用AVPlayer对象在我的iOS应用程序中播放远程广播stream。 该stream正常工作,并在后台播放。

做一些连接testing我遇到了一些问题。 一旦玩家连接失败,玩家停下来(如你所期望的),但是当连接回来时,我不能让玩家再次开始。

我粗暴地设置了一个计时器,每秒只打(玩家播放)强制它开始,但没有运气。 我最好的猜测是基于没有被请求的数据而死的。

我有一个观察者设置来监视玩家何时准备开始,或者是否有错误,但看起来在初始时间之后根本没有被调用。

我的问题是如何强制AVPlayer在可用时再次获取stream。

我已经将audio播放器分类为BCRadio

-(BCRadio*)initWithRadioOneAndAutoPlay:(BOOL)autoPlay whenReady:(void(^)(void))ready whenFailed:(void(^)(void))failed whenBecameActive:(void(^)(void))active { // Current item self.playerItem = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:@"http://69.64.92.79:8276"]]; // Super it self = [super initWithPlayerItem:self.playerItem]; // Observe for it become ready [self addObserver:self forKeyPath:@"status" options:0 context:nil]; // If app comes from background and if app goes inactive [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appBecameActive) name:UIApplicationDidBecomeActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appEnteredBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; // Set blocks self.playerReady = ready; self.playerFailed = failed; self.playerActive = active; self.willAutoPlay = autoPlay; // Register for remote notifications [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; // Play is pressed [[NSNotificationCenter defaultCenter] addObserverForName:@"TogglePlay" object:nil queue:NULL usingBlock:^(NSNotification *notification){ [self doPlay:YES]; }]; // Pause is pressed [[NSNotificationCenter defaultCenter] addObserverForName:@"TogglePause" object:nil queue:NULL usingBlock:^(NSNotification *notification){ [self doPlay:NO]; }]; // Check if playing NSTimer *timer = [NSTimer bk_scheduledTimerWithTimeInterval:1 block:^(NSTimer *timer){ [self statusMonitor]; } repeats:YES]; [timer fire]; // Monitor reachability and pause when needed Reachability* reach = [Reachability reachabilityWithHostname:@"69.64.92.79"]; reach.reachableBlock = ^(Reachability*reach){ if(self.willAutoPlayOnResume && !self.playing){ self.willAutoPlayOnResume = NO; [self doPlay:YES]; } }; reach.unreachableBlock = ^(Reachability*reach){ if(self.playing){ self.willAutoPlayOnResume = YES; [self doPlay:NO]; } }; [reach startNotifier]; return self; }