forked from mgiroux/VR360PlayerView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FW360PlayerViewController.m
219 lines (176 loc) · 5.52 KB
/
FW360PlayerViewController.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//
// FW360PlayerViewController.m
// FW360Player
//
// Created by Marc Giroux on 2016-04-18.
// Copyright © 2016 5th Wall. All rights reserved.
//
#import "FW360PlayerViewController.h"
@implementation FW360PlayerViewController
@synthesize isPlaying, delegate, playerView, duration;
- (instancetype)initWithCardboard:(NSURL *)video withLicense:(NSString *)license
{
self = [super init];
playerType = 1;
cardboardPlayer = [[KMPlayer360DoubleViewController alloc] initWithContentURL:video andAppKey:license];
cardboardPlayer.moviePlayer.delegate = self;
cardboardPlayer.moviePlayer.shouldAutoplay = YES;
cardboardPlayer.moviePlayer.repeatMode = KMMovieRepeatModeNone;
isPlaying = true;
// Default settings for Stepping
cardboardPlayer.moviePlayer.stepX = 2;
cardboardPlayer.moviePlayer.stepY = 2;
// Default Fovs
SCNView *videoView = (SCNView *)cardboardPlayer.view.subviews[0].subviews[0];
SCNCamera *camera = (SCNCamera *)videoView.scene.rootNode.childNodes[0].camera;
camera.yFov = 60;
camera.xFov = camera.yFov * 1.22;
playerView = cardboardPlayer.view;
duration = CMTimeGetSeconds(cardboardPlayer.moviePlayer.duration);
return self;
}
- (instancetype)initWithTouch:(NSURL *)video withLicense:(NSString *)license
{
self = [super init];
playerType = 2;
touchPlayer = [[KMPlayer360ViewController alloc] initWithContentURL:video andAppKey:license];
touchPlayer.moviePlayer.delegate = self;
touchPlayer.moviePlayer.shouldAutoplay = YES;
touchPlayer.moviePlayer.repeatMode = KMMovieRepeatModeNone;
isPlaying = true;
// Default settings for Stepping
touchPlayer.moviePlayer.stepX = 2;
touchPlayer.moviePlayer.stepY = 2;
// Default Fovs
SCNView *videoView = (SCNView *)touchPlayer.view.subviews[0].subviews[0];
SCNCamera *camera = (SCNCamera *)videoView.scene.rootNode.childNodes[0].camera;
camera.yFov = 60;
camera.xFov = camera.yFov * 1.22;
playerView = touchPlayer.view;
duration = CMTimeGetSeconds(touchPlayer.moviePlayer.duration);
recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap:)];
return self;
}
- (void)setTouchControlSpeed:(int)x y:(int)y
{
touchSpeedX = x;
touchSpeedY = y;
if (playerType == 1) {
cardboardPlayer.moviePlayer.stepX = x;
cardboardPlayer.moviePlayer.stepY = y;
} else {
touchPlayer.moviePlayer.stepX = x;
touchPlayer.moviePlayer.stepY = y;
}
}
- (void)setFieldOfView:(double)base
{
SCNView *videoView = (SCNView *)cardboardPlayer.view.subviews[0].subviews[0];
SCNCamera *camera = (SCNCamera *)videoView.scene.rootNode.childNodes[0].camera;
camera.yFov = base;
camera.xFov = camera.yFov * 1.22;
}
- (void)play
{
isPlaying = true;
if (playerType == 1) {
[cardboardPlayer.moviePlayer play];
} else {
[touchPlayer.moviePlayer play];
}
}
- (void)pause
{
isPlaying = false;
if (playerType == 1) {
[cardboardPlayer.moviePlayer pause];
} else {
[touchPlayer.moviePlayer pause];
}
}
- (void)seekTotime:(int)seconds
{
CMTimeScale videoTimeScale;
if (playerType == 1) {
videoTimeScale = [cardboardPlayer.moviePlayer getVideoTimeScale];
[cardboardPlayer.moviePlayer pause];
} else {
videoTimeScale = [touchPlayer.moviePlayer getVideoTimeScale];
[touchPlayer.moviePlayer pause];
}
CMTime seekTime = CMTimeMakeWithSeconds(seconds, videoTimeScale);
if (playerType == 1) {
[cardboardPlayer.moviePlayer seekToTime:seekTime];
[cardboardPlayer.moviePlayer play];
} else {
[touchPlayer.moviePlayer seekToTime:seekTime];
[touchPlayer.moviePlayer play];
}
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if (delegate != nil && playerType == 1) {
[delegate FWPlayerDidTouch:self];
}
}
- (void)didTap:(UITapGestureRecognizer *)tap
{
if (delegate != nil) {
[delegate FWPlayerDidTouch:self];
}
}
#pragma mark - Player Delegate
- (void)playerPlaybackDidFinish
{
if (delegate != nil) {
[delegate FWPlayerDidFinishPlaying:self];
}
}
- (void)setInitialRotation:(int)initialRotation
{
if (playerType == 1) {
cardboardPlayer.moviePlayer.addedRotation = initialRotation;
} else {
touchPlayer.moviePlayer.addedRotation = initialRotation;
}
}
#pragma mark - Private methods
- (void)viewDidAppear:(BOOL)animated
{
if (playerType == 1) {
[self.view addSubview:cardboardPlayer.view];
} else {
[self.view addSubview:touchPlayer.view];
[self.view addGestureRecognizer:recognizer];
}
if (delegate != nil) {
if ([delegate respondsToSelector:@selector(FWPlayerDidAppear:)]) {
[delegate FWPlayerDidAppear:self];
}
}
}
- (void)viewDidDisappear:(BOOL)animated
{
if (delegate != nil) {
if ([delegate respondsToSelector:@selector(FWPlayerDidDisappear:)]) {
[delegate FWPlayerDidDisappear:self];
}
}
}
- (BOOL)prefersStatusBarHidden
{
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
if (playerType == 1) {
return UIInterfaceOrientationMaskLandscapeRight;
} else {
return UIInterfaceOrientationMaskLandscape;
}
}
-(BOOL)shouldAutorotate
{
return YES;
}
@end