【问题标题】:AVPlayer AutoplayAVPlayer 自动播放
【发布时间】:2014-10-01 08:54:44
【问题描述】:

如何在osx中​​制作avplayer自动播放?

我试过了:

NSURL *videoURL = [[NSBundle mainBundle]
URLForResource:@"video name" withExtension:@"mp4"];
self.movieView.player = [AVPlayer playerWithURL:videoURL];

它不会自动播放?

【问题讨论】:

    标签: macos avplayer


    【解决方案1】:

    你还没有调用 play 方法。

    [self.movieView.player play]
    

    【讨论】:

      【解决方案2】:

      我认为,AVplayer首先检查URL内容是否可用。您必须在其上添加观察者。

       [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");
                  loader.hidden = true;
              } else if (_audioPlayer.status == AVPlayerStatusReadyToPlay) {
                  NSLog(@"AVPlayerStatusReadyToPlay");
                      [_audioPlayer play];
      
              } else if (_audioPlayer.status == AVPlayerItemStatusUnknown) {
                  NSLog(@"AVPlayer Unknown");
      
              }
              [_audioPlayer removeObserver:self forKeyPath:@"status" context:nil];
          }
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-31
        • 2023-03-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多