【问题标题】:First video is stretched on iPad (AVPlayer)第一个视频在 iPad 上拉伸(AVPlayer)
【发布时间】:2016-12-07 07:00:14
【问题描述】:

我正在为我的应用制作视频。我正在使用 Avplayer。视频在除 iPad 之外的所有设备上都能准确播放。对于第一个视频,它变得越来越紧张。代码如下:

    NSURL *url = [NSURL URLWithString:feed.video_url];

    cell.videoItem = [AVPlayerItem playerItemWithURL:url];
    cell.videoPlayer = [AVPlayer playerWithPlayerItem:cell.videoItem];
    cell.avLayer = [AVPlayerLayer playerLayerWithPlayer:cell.videoPlayer];
    [cell.avLayer setBackgroundColor:[UIColor whiteColor].CGColor];
    [cell.avLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

    cell.videoPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(playerItemDidReachEnd:)
                                                 name:AVPlayerItemDidPlayToEndTimeNotification
                                               object:[cell.videoPlayer currentItem]];

    timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(hideMuteImage) userInfo:nil repeats:NO];

    [cell.viewForVideo.layer addSublayer:cell.avLayer];

    [cell.videoPlayer play];

请给我一些建议。谢谢

【问题讨论】:

    标签: ios ipad video avplayer


    【解决方案1】:

    实际上,问题是视图初始化...视图在第一次单元执行后初始化。因此,我在填充表格单元格之前添加,并将 VideoGravity 设置为 AVLayerVideoGravityResize 而不是 AVLayerVideoGravityResizeAspectFill。

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
            cell.viewForVideo.frame = CGRectMake(0, 0, self.view.frame.size.width - 5, 480);
        }
    

    还是谢谢。

    【讨论】:

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