forked from facebookarchive/AsyncDisplayKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASVideoNode.m
More file actions
72 lines (56 loc) · 1.72 KB
/
Copy pathASVideoNode.m
File metadata and controls
72 lines (56 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#import "ASVideoNode.h"
@interface ASVideoNode ()
@property (nonatomic) AVPlayer *player;
@end
@implementation ASVideoNode
- (instancetype)initWithURL:(NSURL *)URL;
{
return [self initWithURL:URL videoGravity:ASVideoGravityResizeAspect];
}
- (instancetype)initWithURL:(NSURL *)URL videoGravity:(ASVideoGravity)gravity;
{
if (!(self = [super initWithLayerBlock:^CALayer *{
AVPlayerLayer *layer = [[AVPlayerLayer alloc] init];
AVPlayerItem *item = [[AVPlayerItem alloc] initWithURL:URL];
layer.player = [[AVPlayer alloc] initWithPlayerItem:item];
return layer;
}])) { return nil; }
self.gravity = gravity;
return self;
}
- (void)setGravity:(ASVideoGravity)gravity;
{
switch (gravity) {
case ASVideoGravityResize:
((AVPlayerLayer *)self.layer).videoGravity = AVLayerVideoGravityResize;
break;
case ASVideoGravityResizeAspect:
((AVPlayerLayer *)self.layer).videoGravity = AVLayerVideoGravityResizeAspect;
break;
case ASVideoGravityResizeAspectFill:
((AVPlayerLayer *)self.layer).videoGravity = AVLayerVideoGravityResizeAspectFill;
break;
default:
((AVPlayerLayer *)self.layer).videoGravity = AVLayerVideoGravityResizeAspect;
break;
}
}
- (ASVideoGravity)gravity;
{
if ([((AVPlayerLayer *)self.layer).contentsGravity isEqualToString:AVLayerVideoGravityResize]) {
return ASVideoGravityResize;
}
if ([((AVPlayerLayer *)self.layer).contentsGravity isEqualToString:AVLayerVideoGravityResizeAspectFill]) {
return ASVideoGravityResizeAspectFill;
}
return ASVideoGravityResizeAspect;
}
- (void)play;
{
[[((AVPlayerLayer *)self.layer) player] play];
}
- (void)pause;
{
[[((AVPlayerLayer *)self.layer) player] pause];
}
@end