首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVPlayer全屏

AVPlayer全屏
EN

Stack Overflow用户
提问于 2014-03-12 12:58:33
回答 2查看 13.6K关注 0票数 8

我在我的应用程序中使用AVPlayer而不是MPMoviePlayerController,因为我想把播放器放在子层。然而,我需要像播放,暂停,搜索和全屏控制。如何在AVPlayer中获得该按钮?这就是我对玩家的看法:

代码语言:javascript
复制
    AVURLAsset *avasset = [[AVURLAsset alloc] initWithURL:URL1 options:nil];

    AVPlayerItem *item = [[AVPlayerItem alloc] initWithAsset:avasset];
    player = [[[AVPlayer alloc] initWithPlayerItem:item]retain];

    playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
    CGSize size = self.view.bounds.size;
    float x = size.width/2.0-187.0;
    float y = size.height/2.0 - 125.0;

    playerLayer.frame = CGRectMake(x, y, 474, 320);
    [playerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    [self.view.layer addSublayer:playerLayer];
    [player play];
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-03-12 13:02:35

你必须提供你自己的按钮。

对于playpause,在AVPlayer中有直接的API。

对于全屏…well…你知道你是在哪里绘制的:你只需要调整你的UIWindow和相应的UIView & layer的大小就可以了。

对于搜索,您确实有像seekToTime:这样的方法

票数 6
EN

Stack Overflow用户

发布于 2015-07-10 10:18:22

为了便于将来参考,iOS 8 AVKit提供了包装AVPlayer的AVPlayerViewController类,并具有标准的MPMoviePlayerController类控件。

AVPlayerViewController

代码语言:javascript
复制
AVPlayerViewController * filePlayerViewController = [AVPlayerViewController alloc];
//Show the controls
filePlayerViewController.showsPlaybackControls = true;
AVPlayer * filePlayer = [AVPlayer playerWithURL:[NSURL fileURLWithPath:self.videoFile.localURL]];
filePlayerViewController.player = self.filePlayer;
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22342361

复制
相关文章

相似问题

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