This repository has been archived by the owner on Jul 28, 2020. It is now read-only.
forked from TheWidlarzGroup/react-native-video
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRCTAVPlayerLayer.m
77 lines (64 loc) · 1.54 KB
/
RCTAVPlayerLayer.m
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
73
74
75
76
77
#import "RCTAVPlayerLayer.h"
#import "RCTAVPlayer.h"
#import "RCTAVPlayerManager.h"
#import <AVFoundation/AVFoundation.h>
@implementation RCTAVPlayerLayer
{
NSString* _resizeMode;
AVPlayerLayer* _playerLayer;
}
-(instancetype)init
{
if (self = [super init])
{
_resizeMode = @"AVLayerVideoGravityResizeAspectFill";
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
[CATransaction begin];
[CATransaction setAnimationDuration:0];
_playerLayer.frame = self.bounds;
[CATransaction commit];
}
-(void)setBackgroundColor:(UIColor *)backgroundColor
{
}
-(void)setResizeMode:(NSString*)mode
{
_resizeMode = mode;
_playerLayer.videoGravity = mode;
}
-(void)removeFromSuperview
{
[_playerLayer removeFromSuperlayer];
_playerLayer = nil;
[super removeFromSuperview];
}
-(void)setPlayer:(AVPlayer*)player
{
if (player != nil) {
//[_playerLayer removeFromSuperlayer];
_playerLayer = (AVPlayerLayer*)self.layer;
[_playerLayer setPlayer:player];
_playerLayer.frame = self.bounds;
_playerLayer.needsDisplayOnBoundsChange = YES;
_playerLayer.videoGravity = _resizeMode;
self.layer.needsDisplayOnBoundsChange = YES;
} else {
[_playerLayer setPlayer:nil];
}
}
-(void)setPlayerUuid:(NSString*)playerUuid
{
RCTAVPlayer* player = [RCTAVPlayerManager getPlayer:playerUuid];
AVPlayer* avPlayer = [player getAVPlayer];
[self setPlayer:avPlayer];
}
+(Class)layerClass
{
return [AVPlayerLayer class];
}
@end