gpt4 book ai didi

ios - AVPlayerview来自左上角

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

我正在使用 AVPlayer 来播放视频。我在全屏模式下遇到问题。视频播放器来自左上角。看起来很奇怪。

NSString *filePath = [self.video_Array objectAtIndex:index];
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:filePath ofType: nil];
url = [[NSURL alloc] initFileURLWithPath: soundFilePath];
currentItem = [AVPlayerItem playerItemWithURL:url];
_playerViewController = [[AVPlayerViewController alloc] init];
_playerViewController.videoGravity = AVLayerVideoGravityResize;
_playerViewController.view.frame = self.view.bounds;
_playerViewController.showsPlaybackControls = NO;
_video=[AVPlayer playerWithURL:url];
_video = [AVPlayer playerWithPlayerItem:currentItem];
_playerViewController.player = _video;
[_playerViewController.player play];
[self.view addSubview:_playerViewController.view];

最佳答案

请引用我的代码,它在我的应用程序中运行良好,

 -(void)videoPlayer:(NSString *)filePath{

playerViewController = [[AVPlayerViewController alloc] init];
self.viewPlayerContainer.frame = CGRectMake(0, 74, self.view.bounds.size.width, self.view.bounds.size.width);

NSURL *url = [NSURL fileURLWithPath:filePath];

AVURLAsset *asset = [AVURLAsset assetWithURL: url];
AVPlayerItem *item = [AVPlayerItem playerItemWithAsset: asset];

AVPlayer * player = [[AVPlayer alloc] initWithPlayerItem: item];
playerViewController.player = player;
playerViewController.videoGravity = AVLayerVideoGravityResizeAspectFill;
[playerViewController.view setFrame:CGRectMake(0, 0, self.viewPlayerContainer.bounds.size.width, self.viewPlayerContainer.bounds.size.height)];
[playerViewController addObserver:self forKeyPath:@"videoBounds" options:NSKeyValueObservingOptionNew context:nil];

playerViewController.showsPlaybackControls = YES;

[self.viewPlayerContainer addSubview:playerViewController.view];

[player play];
}

关于ios - AVPlayerview来自左上角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38786233/

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