如果我启动此流然后关闭wifi,则“playbackBufferEmpty”会被触发,我可以尝试重新启动流来响应。但是,如果我关闭wifi并立即重新开启,则流停止播放,但没有任何观察者被触发。
- (void)restartStream
{
[self.activityIndicator startAnimating];
NSLog(@"Removing Observers");
[self.radioStream removeObserver:self forKeyPath:@"status"];
[self.radioStream removeObserver:self forKeyPath:@"timedMetadata"];
[self.radioStream removeObserver:self forKeyPath:@"playbackBufferEmpty"];
[self.radioStream removeObserver:self forKeyPath:@"playbackLikelyToKeepUp"];
NSLog(@"Creating New AVPlayerItem");
self.radioStream = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://mystream.com"]];
[self.radioStream addObserver:self forKeyPath:@"status" options:0 context:nil];
[self.radioStream addObserver:self forKeyPath:@"timedMetadata" options:NSKeyValueObservingOptionNew context:nil];
[self.radioStream addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil];
[self.radioStream addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil];
NSLog(@"Playing radioPlayer with new AVPlayerItem");
self.radioPlayer = [AVPlayer playerWithPlayerItem:self.radioStream];
}
答案 0 :(得分:0)
似乎是模拟器的问题。在设备上触发“status”或“playbackBufferEmpty”。