[英]AVPlayer Full Screen
i'm using AVPlayer in my apps instead MPMoviePlayerController since i want to put the player as sublayer. 我在我的应用程序中使用AVPlayer而不是MPMoviePlayerController,因为我想将播放器作为子层。 However i need control like play, pause, search, and full screen.
但是我需要控制,如播放,暂停,搜索和全屏。 How do i get that button in AVPlayer?
如何在AVPlayer中获得该按钮? This is how i put the player:
这就是我放置玩家的方式:
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];
You'll have to provide your own buttons. 你必须提供自己的按钮。
For play
and pause
there are direct API's in AVPlayer. 对于
play
和pause
,AVPlayer中有直接的API。
For full screen… well… you know where you are drawing: you just need to size your UIWindow and corresponding UIView & layer to be full size. 对于全屏......好吧......你知道你在哪里画画:你只需要将你的UIWindow和相应的UIView&图层调整为全尺寸。
For search, you do have methods like seekToTime:
对于搜索,您可以使用
seekToTime:
等方法seekToTime:
For future reference iOS 8 AVKit has the AVPlayerViewController class available that will wrap a AVPlayer and has the standard MPMoviePlayerController class controls. 供将来参考iOS 8 AVKit具有可用的AVPlayerViewController类,它将包装AVPlayer并具有标准的MPMoviePlayerController类控件。
AVPlayerViewController AVPlayerViewController
AVPlayerViewController * filePlayerViewController = [AVPlayerViewController alloc];
//Show the controls
filePlayerViewController.showsPlaybackControls = true;
AVPlayer * filePlayer = [AVPlayer playerWithURL:[NSURL fileURLWithPath:self.videoFile.localURL]];
filePlayerViewController.player = self.filePlayer;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.