AVPlayer未显示FullScreen

时间:2016-11-03 05:00:29

标签: ios objective-c avplayer avplayerlayer

我正在制作由 AVCapture 录制的录制视频。我将视频网址保存在名为 outputFileURL 的字符串中。我尝试使用 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];

但我得到的视频不是全屏。 任何人都可以帮我解决吗?

2 个答案:

答案 0 :(得分:7)

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

videoLayer.videoGravity=AVLayerVideoGravityResizeAspectFill;

希望这可能会有所帮助。

答案 1 :(得分:0)

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];
}