gpt4 book ai didi

ios - AVPlayer 到全屏,顶部和底部没有黑条

转载 作者:行者123 更新时间:2023-11-29 00:24:05 36 4
gpt4 key购买 nike

我嵌入了我的视频并添加了一个 notificationCenter 观察器,如下所示:

 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"export" ofType:@"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:filePath];

_playerViewController = [[AVPlayerViewController alloc] init];
// grab a local URL to our video
//NSURL *videoURL = [myBundle URLForResource:@"export" withExtension:@"mp4"];
NSLog(@"Video URL: %@",videoURL);
if(videoURL)
{

_playerViewController.showsPlaybackControls = NO;

AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:videoURL];

// create an AVPlayer
_playerViewController.player = [AVPlayer playerWithPlayerItem:playerItem];
//self.player.volume = PLAYER_VOLUME;
_playerViewController.modalPresentationStyle =
UIModalPresentationOverFullScreen;
AVPlayerLayer *playerLayer = [AVPlayerLayer
playerLayerWithPlayer:_playerViewController.player];
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
playerLayer.zPosition = -1;
playerLayer.frame = [UIApplication sharedApplication].keyWindow.bounds;
[self.playerView.layer addSublayer:playerLayer];

[_playerViewController.player play];
// Adding Observer for your video file,
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:@selector(videoDidFinish:)
name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
}

当视频播放完毕后,会调用下面的方法:

 -(void)videoDidFinish:(id)notification{
AVPlayerItem *p = [notification object];
//do something with player if you want
[_playerViewController.player pause];

//Remove Observer
[[NSNotificationCenter defaultCenter] removeObserver:self];

//your initial view can proceed from here
UIViewController *controler = [self.storyboard
instantiateViewControllerWithIdentifier:@"loginScreenId"];
[self.navigationController pushViewController:controler animated:YES];
}

我无法解决两件事:

  1. 我正在从当前的 AV View Controller 推送到下一个 View Controller 。它已成功连接到下一个 View Controller ,但屏幕顶部和底部有黑条。我怎样才能摆脱这个?
  2. 如何让 AVPlayer 全屏显示?

最佳答案

我终于明白了。我只是将Launch.storyborad添加到项目中并替换了代码

playerLayer.frame = [UIApplication sharedApplication].keyWindow.bounds;

playerLayer.frame = self.view.frame;

获取全屏视频。

关于ios - AVPlayer 到全屏,顶部和底部没有黑条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43501181/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com