【问题标题】:AVPlayer live radio streaming stop after 15 minutes or soAVPlayer 直播电台流媒体在 15 分钟左右后停止
【发布时间】:2013-04-29 11:22:49
【问题描述】:

作为标题,我正在尝试使用 AVPlayer 实例在 iOSOS X 上直播互联网广播。使用简单的player = [AVPlayer playerWithURL:URL];,一切都按预期工作

在使用该应用程序时,我注意到流在 15 分钟后才停止,或多或少。问题是没有注意到。

[player addObserver:self forKeyPath:@"status" options:0 context:nil];
[player addObserver:self forKeyPath:@"rate" options:0 context:nil];

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    if (object == player) {
        if ([keyPath isEqualToString:@"status"]) {
            NSLog(@"status -> %ld", player.status);
        }
        if ([keyPath isEqualToString:@"rate"]) {
            NSLog(@"rate -> %f", player.rate);
        }
    }
}

两个值都切换为1,但即使音频停止播放,也不会再次切换。在 iOS 上,右上角的 play 图标消失了,但由于 player.rate 值没有改变,应用程序仍然认为有音频播放。

一开始我以为是直播,所以我尝试了 5by5 和 twit 的其他直播,同样的事情发生了。

然后我以为是我的连接,所以在直播开始后,我关闭了我的连接,大约一分钟后,我观察到的AVPlayerItemDidPlayToEndTimeNotification被解雇了。

花了一些时间来测试这个。

那么知道为什么会这样吗?更重要的是,如何解决?

【问题讨论】:

    标签: ios xcode macos avplayer


    【解决方案1】:

    好的,我注意到player.currentTime 卡住了,而player.rate1。所以至少在 OS X 上我可以跟踪它并在卡住时重新启动流。

    2013-04-30 12:49:07.730 Radio[60315:303] rate -> 1.000000
    2013-04-30 12:49:07.731 Radio[60315:303] status -> 1
    2013-04-30 13:09:04.154 Radio[60315:303] Stuck at 1195 x 1
    2013-04-30 13:09:05.155 Radio[60315:303] Stuck at 1195 x 2
    2013-04-30 13:09:06.155 Radio[60315:303] Stuck at 1195 x 3
    2013-04-30 13:09:07.155 Radio[60315:303] >> Stuck! Restart stream <<
    2013-04-30 13:09:09.426 Radio[60315:303] rate -> 1.000000
    2013-04-30 13:09:09.426 Radio[60315:303] status -> 1
    

    【讨论】:

    • 很好的解决方法!我认为 AVPlayer 存在问题,因为当卡住发生时,AVPlayer 的周期性观察者将不再被解雇。
    猜你喜欢
    • 2016-09-17
    • 2016-05-18
    • 2018-10-22
    • 2022-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多