AVplayer 没有播放特定 link

AVplayer not playing specific link

使用非常简单的 AVPlayer 实现:

AVURLAsset *asset = [AVURLAsset assetWithURL:self.currentCollateral.url];
AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];
AVPlayer *player = [AVPlayer playerWithPlayerItem:item];
AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.player = player;
[player play];
[self presentViewController:playerViewController animated:YES completion:nil];

但是这个link不会播放:

https://www.screencast.com/users/DoorAndHardware/folders/2016%20Orlando%20Conference/media/08848a5a-d414-4bdd-861f-95cf9890d1a1/embed\

不确定我错过了什么。代码适用于其他 links。似乎无法在文档中找到任何相关内容。感谢您的帮助!

您的 URL 不会 link 到媒体文件(例如 .mp4 ),而是到嵌入式播放器。

如果您查看 linked 播放器站点的源代码,您可以看到 used URL。 URL 应该适用于您的代码。

在 avplayer 上开始播放任何视频之前,我们需要检查给定的 URL 是否已准备好播放。在 avplayer 上添加以下观察者。

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

#pragma Observer for Player status.
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    if (object == _audioPlayer && [keyPath isEqualToString:@"status"]) {
        if (_audioPlayer.status == AVPlayerStatusFailed) {
            NSLog(@"AVPlayer Failed");

        } else if (_audioPlayer.status == AVPlayerStatusReadyToPlay) {
            NSLog(@"AVPlayerStatusReadyToPlay");
                [_audioPlayer play];

        } else if (_audioPlayer.status == AVPlayerItemStatusUnknown) {
            NSLog(@"AVPlayer Unknown");

        }
        [_audioPlayer removeObserver:self forKeyPath:@"status" context:nil];
    }

}