【问题标题】:MPMoviePlayerController initialPlaybackTime property not working in iOS 8.4MPMoviePlayerController initialPlaybackTime 属性在 iOS 8.4 中不起作用
【发布时间】:2015-09-18 21:50:48
【问题描述】:

设置 initialPlaybackTime 属性后,视频(HTTP 流)仍然从头开始播放。

相同的代码在 iOS

 self.moviePlayer.initialPlaybackTime = self.lastPlaybackTime;
[self.moviePlayer play];

【问题讨论】:

  • 我也遇到了同样的问题,而且不是所有的文件类型现在都可以播放。此外,这是一个雷达openradar.me/20762442,该组件存在问题。看起来苹果在该版本中破坏了已弃用的 mpmoviewplayer,您必须转向 AVKit
  • setCurrenPlaybackTime 似乎也被破坏了。
  • 我已经玩了几个小时了,但一点运气都没有,似乎社区的普遍反应是它目前已损坏。
  • 我已经向苹果提交了错误报告。还没有回应。

标签: ios objective-c mpmovieplayercontroller ios9 ios8.4


【解决方案1】:

这对我有用,基本上你需要在电影开始播放时 setCurrentPlaybackTime,但你还需要一个标志 playbackDurationSet 当你呈现电影播放器​​时设置为 NO当电影第一次被寻找到播放持续时间时,它设置为 YES。

注意:此标志是必需的,因为当您从搜索擦除器中搜索电影时,moviePlayerPlaybackStateChanged 被触发,playbackState 为 MPMoviePlaybackStatePlaying

BOOL playbackDurationSet = NO;
- (void)moviePlayerPlaybackStateChanged:(NSNotification*)notification
{
    MPMoviePlayerController* player = (MPMoviePlayerController*)notification.object;
    switch ( player.playbackState ) {
        case MPMoviePlaybackStatePlaying:
        if(!playbackDurationSet){
           [self.moviePlayer setCurrentPlaybackTime:yourStartTime];
           playbackDurationSet = YES;
        }
        break;
    }
}

- (void)moviePlayerPresented
{
      playbackDurationSet = NO;
}

【讨论】:

    【解决方案2】:

    我也看到了其中一些问题。由于 MPMoviePlayerController 在 iOS 9 中已被弃用,因此它们不太可能被修复。

    【讨论】:

      【解决方案3】:

      hariszaman 回答对我有用:

      - (void)moviePlaybackStateChanged:(NSNotification*)notif
      {
          //...
          if (self.videoPlayer.playbackState == MPMoviePlaybackStatePlaying) {
      
              if (self.currentBookmark) {
                  if ([[PSDeviceInfo sharedInstance] is_iOSatLeast84]){
                      NSTimeInterval toTime = [self.currentBookmark.seconds doubleValue];
                      [self.videoPlayer setCurrentPlaybackTime:toTime];
                      self.currentBookmark = nil;
                  }
              }
          }
      
      if (self.videoPlayer.playbackState == MPMoviePlaybackStatePaused) {
          //...
      }
      
      if (self.videoPlayer.playbackState == MPMoviePlaybackStateStopped) {
          //...
      }
      }
      

      还有:

          - (void)configureMoviePlayer
          {
              if (self.currentBookmark) {
                  if ([[PSDeviceInfo sharedInstance] is_iOSatLeast84]){
                      // will set start after did start
                  }else {
                      NSTimeInterval toTime = [self.currentBookmark.seconds doubleValue];
                      self.videoPlayer.initialPlaybackTime = toTime;            
                      self.currentBookmark = nil;
                  }
              }
              else {
                  self.videoPlayer.initialPlaybackTime = 0;
              }
              //...
          }
      

      方法是_iOSatLeast84:

      - (BOOL)is_iOSatLeast84
      {
          // version 8.4
          NSString *version = [[UIDevice currentDevice] systemVersion];
          BOOL isAtLeast84 = [version floatValue] >= 8.35;
      
          return isAtLeast84;
      }
      

      尽管所有这些都是一种解决方法,但它可以完成工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-05-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-20
        相关资源
        最近更新 更多