AVPlayer 不显示全屏

AVPlayer not showing FullScreen

我正在播放由 AVCapture 录制的视频。我正在将视频 URL 保存在名为 outputFile[=21= 的字符串中]。我尝试使用 AVPlayerLayer 概念播放视频。我使用的代码是

AVPlayer *avPlayerq = [AVPlayer playerWithURL:outputFileURL];
avPlayerq.actionAtItemEnd = AVPlayerActionAtItemEndNone;
AVPlayerLayer *videoLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayerq];
videoLayer.frame= self.view.bounds;

[self.view.layer addSublayer:videoLayer];
[avPlayerq play];

但是我得到的视频不是全屏的。 谁能帮我解决一下?

AVPlayer *player = [[AVPlayer alloc] initWithURL:url];
AVPlayerViewController *playerViewController = [AVPlayerViewController new]; playerViewController.delegate = self; 
playerViewController.player = player; 
[playerViewController.player play]; 
[self presentViewController:playerViewController animated:YES completion:nil];

试试这个

好吧,你必须使用 MPMoviePlayerController

NSString *path = [[NSBundle mainBundle] pathForResource:@"Video_Intro" ofType:@"mov"];

    moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:path]];
    moviePlayer.view.frame = ivVideoThumbnail.frame;

    //moviePlayer.view.top += 20; // Add to fix 20 pixel diff of moviePlayer view


    // Register this class as an observer instead.
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(movieFinishedCallback:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayer];


    [svIntro addSubview:moviePlayer.view];
    moviePlayer.fullscreen = true;
    [moviePlayer play];

同时实现 Observer 方法

-(void)movieFinishedCallback:(id)mPlayer
{
    [moviePlayer.view removeFromSuperview];
}

我添加了以下代码,我可以全屏了。

videoLayer.videoGravity=AVLayerVideoGravityResizeAspectFill;

希望这可能有所帮助。