AVPlayerLayer
AVPlayerLayer 尽管不是CoreAnimation框架的一部分,并且它是AVFundation框架提供的,但AVPlayerLayer 和CoreAnimation结合使用,可以更好的展示内容类型。
AVPlayerLayer 是高级接口如MPMoivePlayer的底层实现,也是显示视频的底层控制。
- 播放视频(无声音)
#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
-
效果示意: