第一个视频在 iPad (AVPlayer) 上被拉伸

First video is stretched on iPad (AVPlayer)

我正在为我的应用制作视频。我正在使用 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];

请给我一些建议。谢谢

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

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

谢谢。