/
ViroTheatre.js
222 lines (195 loc) · 6.03 KB
/
ViroTheatre.js
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
220
221
222
'use strict';
/**
* Pull in all imports required for the controls within this scene.
*/
import React, { Component } from 'react';
import {StyleSheet} from 'react-native';
import {
AppRegistry,
ViroScene,
ViroVideo,
ViroSceneNavigator,
ViroMaterials,
Viro360Image,
ViroButton,
ViroImage,
ViroNode,
ViroAnimations,
ViroUtils,
} from 'react-viro';
var createReactClass = require('create-react-class');
/**
* Set all the image and asset references required in this scene.
*/
var buttonSize = 0.25;
var VIDEO_REF = "videoref";
var VideoControlRef = "VideoControlRef";
/**
* Several references to video sources (wether it be local or on AWS) stored in an array.
*/
var videos = [
{uri:'https://s3-us-west-2.amazonaws.com/viro/Assets/Viro_Media_Video.mp4'},
{uri:'https://s3-us-west-2.amazonaws.com/viro/Assets/ProductVideo.mp4'},
];
var ViroTheatre = createReactClass({
getInitialState() {
return {
videoControlsAnimation:"fadeIn",
videoPaused: false,
loopVideo: true,
videoIndex: 0,
runAnimation: false,
}
},
/**
* Renders a scene that contains a 360 video and Video Controls.
*/
render: function() {
return (
<ViroScene onClick={this._onVideoTapped} reticleEnabled={this.state.videoControlsAnimation=="fadeIn"}>
<Viro360Image source={require('./res/dark_theatre.jpg')} />
<ViroVideo ref={VIDEO_REF} source={videos[this.state.videoIndex]} volume={1.0}
position={[0, 3.9, -45]} scale={[44, 22, 1]} loop={this.state.loopVideo}
paused={this.state.videoPaused} />
{this._renderVideoControl()}
</ViroScene>
);
},
_onVideoTapped(){
var videoControlsAnimationState = this.state.videoControlsAnimation;
if (videoControlsAnimationState=="fadeIn"){
videoControlsAnimationState="fadeOut";
} else {
videoControlsAnimationState="fadeIn";
}
this.setState({
videoControlsAnimation:videoControlsAnimationState,
runAnimation:true,
});
},
/**
* Render a set of Video UI Controls. This includes (in the order displayed from left to right):
* Restart, Previous Video, Play/Pause, Next Video, Volume.
*/
_renderVideoControl(){
return(
<ViroNode position={[0,-0.8,0]} opacity={1.0}
animation={{ name : this.state.videoControlsAnimation, run : this.state.runAnimation, loop : false}} >
<ViroImage
scale={[1.4, 1.2, 1]}
position={[0, -0.27,-2.1]}
source={require("./res/player_controls_container.png")} />
<ViroButton
position={[-buttonSize-0.1,0,-2]}
scale={[1, 1, 1]}
width={buttonSize}
height={buttonSize}
source={require("./res/previous.png")}
hoverSource={require("./res/previous_hover.png")}
clickSource={require("./res/previous_hover.png")}
onClick={this._playPreviousVideo} />
{this._renderPlayControl()}
<ViroButton
position={[buttonSize+0.1, 0,-2]}
scale={[1, 1, 1]}
width={buttonSize}
height={buttonSize}
source={require("./res/skip.png")}
hoverSource={require("./res/skip_hover.png")}
clickSource={require("./res/skip_hover.png")}
onClick={this._playNextVideo} />
<ViroButton
position={[-0.3, -0.4 ,-2]}
scale={[1, 1, 1]}
width={0.5}
height={0.5}
source={require("./res/icon_2D_hover.png")}
hoverSource={require("./res/icon_2D_hover.png")}
clickSource={require("./res/icon_2D_hover.png")} />
<ViroButton
position={[0.3, -0.4 ,-2]}
scale={[1, 1, 1]}
width={0.5}
height={0.5}
source={require("./res/icon_360.png")}
hoverSource={require("./res/icon_360_hover.png")}
clickSource={require("./res/icon_360_hover.png")}
onClick={this._launchTheatreScene} />
</ViroNode>
);
},
/**
* Renders either the play or pause icon depending on video state.
*/
_renderPlayControl(){
if (this.state.videoPaused){
return (
<ViroButton
position={[0,0,-2]}
scale={[1, 1, 1]}
width={buttonSize}
height={buttonSize}
source={require("./res/play.png")}
hoverSource={require("./res/play_hover.png")}
clickSource={require("./res/play_hover.png")}
onClick={this._togglePauseVideo}/>
);
} else {
return (
<ViroButton
position={[0,0,-2]}
scale={[1, 1, 1]}
width={buttonSize}
height={buttonSize}
source={require("./res/pause.png")}
hoverSource={require("./res/pause_hover.png")}
clickSource={require("./res/pause_hover.png")}
onClick={this._togglePauseVideo}/>
);
}
},
_launchTheatreScene(){
this.props.sceneNavigator.jump("Viro360Theatre", {scene:require('./Viro360Theatre')});
},
_togglePauseVideo() {
this.setState({
videoPaused: !this.state.videoPaused,
})
},
/**
* Play the previous video by setting the videoIndex.
*/
_playPreviousVideo(){
var currentVideo = this.state.videoIndex;
if (currentVideo - 1 > -1){
this.setState({
videoIndex: (currentVideo - 1),
videoPaused: false
});
}
},
/**
* Play the next video by setting the videoIndex.
*/
_playNextVideo(){
var currentVideo = this.state.videoIndex;
if (currentVideo + 1 < videos.length){
this.setState({
videoIndex: (currentVideo + 1),
videoPaused: false
});
}
},
});
ViroAnimations.registerAnimations({
fadeOut:{properties:{opacity: 0.0}, duration: 500},
fadeIn:{properties:{opacity: 1.0}, duration: 500},
});
ViroMaterials.createMaterials({
opaqueWhite: {
shininess: 2.0,
lightingModel: "Lambert",
diffuseColor: "#FFFFFF"
},
});
module.exports = ViroTheatre;