【问题标题】:AVplayer not playing specific linkAVplayer 不播放特定链接
【发布时间】:2023-03-03 21:43:01
【问题描述】:

使用一个非常简单的 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];

但此链接无法播放:

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

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

【问题讨论】:

    标签: ios objective-c avplayer


    【解决方案1】:

    您的网址没有链接到媒体文件(例如.mp4),而是链接到嵌入式播放器。

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

    【讨论】:

      【解决方案2】:

      在开始播放 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];
          }
      
      }
      

      【讨论】:

        猜你喜欢
        • 2016-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多