AVPlayerLayer

大美女
AVPlayerLayer 盡管不是CoreAnimation框架的一部分涡匀,并且它是AVFundation框架提供的食听,但AVPlayerLayer 和CoreAnimation結(jié)合使用烧董,可以更好的展示內(nèi)容類型。
AVPlayerLayer 是高級接口如MPMoivePlayer的底層實(shí)現(xiàn)列吼,也是顯示視頻的底層控制沪编。
- 播放視頻(無聲音)
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageV;
@property (weak, nonatomic) IBOutlet UIView *clipView;
@property (nonatomic,strong) CALayer *colorLayer;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *str = @"http://mp4.vjshi.com/2018-04-26/ee158debdab620838aee91f6bf238d5c.mp4";
// NSURL *url = [[NSBundle mainBundle] URLForResource:@"AV" withExtension:@"mp4"];
NSURL *url = [NSURL URLWithString:str];
AVPlayer *player = [AVPlayer playerWithURL:url];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.masksToBounds= YES;
playerLayer.borderColor = [UIColor redColor].CGColor;
playerLayer.borderWidth = 5.0f;
playerLayer.cornerRadius = 20.0f;
playerLayer.frame = self.clipView.bounds;
[self.clipView.layer addSublayer:playerLayer];
[player play];
}
@end
-
效果示意:
圖層視頻