首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVPlayerview来自左上角

AVPlayerview来自左上角
EN

Stack Overflow用户
提问于 2016-08-05 17:47:17
回答 2查看 154关注 0票数 0

我在用AVPlayer播放视频。我对全屏模式有个问题。视频播放器来自左上角。看起来很奇怪。

代码语言:javascript
复制
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];
EN

回答 2

Stack Overflow用户

发布于 2016-08-05 18:48:58

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

代码语言:javascript
复制
 -(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];
}
票数 1
EN

Stack Overflow用户

发布于 2016-08-05 17:56:41

您可以使用AVPlayerViewController播放全屏视频

代码语言:javascript
复制
AVPlayerViewController+Fullscreen.h

#import <AVKit/AVKit.h>

@interface AVPlayerViewController (Fullscreen)

-(void)goFullscreen;

@end

AVPlayerViewController+Fullscreen.m

代码语言:javascript
复制
#import "AVPlayerViewController+Fullscreen.h"

@implementation AVPlayerViewController (Fullscreen)



 -(void)goFullscreen {
        self.modalPresentationStyle = UIModalPresentationOverFullScreen;
       [self presentViewController:self animated:YES completion:nil];
    }

@end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38786233

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档