国产gaysexchina男同gay,japanrcep老熟妇乱子伦视频,吃奶呻吟打开双腿做受动态图,成人色网站,国产av一区二区三区最新精品

6.10 AVPlayerLayer 圖層

2021-09-14 16:23 更新

AVPlayerLayer

最后一個(gè)圖層類型是AVPlayerLayer。盡管它不是Core Animation框架的一部分(AV前綴看上去像),AVPlayerLayer是有別的框架(AVFoundation)提供的,它和Core Animation緊密地結(jié)合在一起,提供了一個(gè)CALayer子類來(lái)顯示自定義的內(nèi)容類型。

AVPlayerLayer是用來(lái)在iOS上播放視頻的。他是高級(jí)接口例如MPMoivePlayer的底層實(shí)現(xiàn),提供了顯示視頻的底層控制。AVPlayerLayer的使用相當(dāng)簡(jiǎn)單:你可以用+playerLayerWithPlayer:方法創(chuàng)建一個(gè)已經(jīng)綁定了視頻播放器的圖層,或者你可以先創(chuàng)建一個(gè)圖層,然后用player屬性綁定一個(gè)AVPlayer實(shí)例。

在我們開始之前,我們需要添加AVFoundation到我們的項(xiàng)目中。然后,清單6.15創(chuàng)建了一個(gè)簡(jiǎn)單的電影播放器,圖6.16是代碼運(yùn)行結(jié)果。

清單6.15 用AVPlayerLayer播放視頻

#import "ViewController.h"
#import 
#import 

@interface ViewController ()

@property (nonatomic, weak) IBOutlet UIView *containerView; @end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    //get video URL
    NSURL *URL = [[NSBundle mainBundle] URLForResource:@"Ship" withExtension:@"mp4"];

    //create player and player layer
    AVPlayer *player = [AVPlayer playerWithURL:URL];
    AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];

    //set player layer frame and attach it to our view
    playerLayer.frame = self.containerView.bounds;
    [self.containerView.layer addSublayer:playerLayer];

    //play the video
    [player play];
}
@end

圖6.17 3D視角下的邊框和圓角AVPlayerLayer

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)