我在我的应用程序中使用AVPlayer而不是MPMoviePlayerController,因为我想把播放器放在子层。然而,我需要像播放,暂停,搜索和全屏控制。如何在AVPlayer中获得该按钮?这就是我对玩家的看法:
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];发布于 2014-03-12 13:02:35
你必须提供你自己的按钮。
对于play和pause,在AVPlayer中有直接的API。
对于全屏…well…你知道你是在哪里绘制的:你只需要调整你的UIWindow和相应的UIView & layer的大小就可以了。
对于搜索,您确实有像seekToTime:这样的方法
发布于 2015-07-10 10:18:22
为了便于将来参考,iOS 8 AVKit提供了包装AVPlayer的AVPlayerViewController类,并具有标准的MPMoviePlayerController类控件。
AVPlayerViewController * filePlayerViewController = [AVPlayerViewController alloc];
//Show the controls
filePlayerViewController.showsPlaybackControls = true;
AVPlayer * filePlayer = [AVPlayer playerWithURL:[NSURL fileURLWithPath:self.videoFile.localURL]];
filePlayerViewController.player = self.filePlayer;https://stackoverflow.com/questions/22342361
复制相似问题