AVPlayer全屏

use*_*429 8 objective-c ios avplayer avplayerlayer

我在我的应用程序中使用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];
Run Code Online (Sandbox Code Playgroud)

Mic*_*ann 7

你必须提供自己的按钮.

对于playpause有在AVPlayer直接的API.

对于全屏......好吧......你知道你在哪里画画:你只需要将你的UIWindow和相应的UIView&图层调整为全尺寸.

对于搜索,你有类似的方法 seekToTime:


Cod*_*hse 6

供将来参考iOS 8 AVKit具有可用的AVPlayerViewController类,它将包装AVPlayer并具有标准的MPMoviePlayerController类控件.

AVPlayerViewController

AVPlayerViewController * filePlayerViewController = [AVPlayerViewController alloc];
//Show the controls
filePlayerViewController.showsPlaybackControls = true;
AVPlayer * filePlayer = [AVPlayer playerWithURL:[NSURL fileURLWithPath:self.videoFile.localURL]];
filePlayerViewController.player = self.filePlayer;
Run Code Online (Sandbox Code Playgroud)