This repository was archived by the owner on Nov 4, 2025. It is now read-only.
forked from duyluonglc/react-native-gvr
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGVRVideo.js
More file actions
97 lines (88 loc) · 2.49 KB
/
GVRVideo.js
File metadata and controls
97 lines (88 loc) · 2.49 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
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
/*
* @Author: tiero
* @Date: 2017-01-05 17:39:15
* @Last Modified by: tiero
* @Last Modified time: 2017-01-05 17:40:04
*/
import React from 'react'
import PropTypes from 'prop-types'
import { requireNativeComponent, ViewPropTypes, NativeModules, UIManager, findNodeHandle, Platform } from 'react-native'
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource'
const IS_IOS = Platform.OS === 'ios'
const VrVideoModule = IS_IOS ? NativeModules['VrVideoManager'] : NativeModules['VrVideoModule']
class VideoView extends React.Component {
setRef = view => {
this.rctView = view
}
seekTo (position) {
if (IS_IOS) {
VrVideoModule.seekTo(findNodeHandle(this.rctView), position)
} else {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.rctView),
UIManager.VrVideo.Commands.seekTo,
[position]
)
}
}
getDuration () {
return VrVideoModule.getDuration(findNodeHandle(this.rctView))
}
getPlayableDuration () {
if (IS_IOS) {
return VrVideoModule.getPlayableDuration(findNodeHandle(this.rctView))
} else {
return new Promise((resolve, reject) => {
reject('getPlayableDuration not supported on Android')
})
}
}
getFormat(uri) {
if (uri.includes('.m3u8')) {
return 'hls'
} else if (uri.includes('.mpeg')) {
return 'mpeg'
} else if (uri.includes('.mp4')) {
return 'mp4'
}
return 'mp4'
}
render () {
const { source, paused } = this.props
return <RCTViedoView
{...this.props}
paused={paused == null ? false : paused}
ref={this.setRef}
src={{
uri: source.uri,
type: source.type || '',
format: this.getFormat(source.uri)
}}
/>
}
}
VideoView.propTypes = {
...ViewPropTypes,
src: PropTypes.object,
source: PropTypes.oneOfType([
PropTypes.shape({
uri: PropTypes.string,
type: PropTypes.string
})
]),
paused: PropTypes.bool,
volume: PropTypes.number,
displayMode: PropTypes.string,
enableFullscreenButton: PropTypes.bool,
enableCardboardButton: PropTypes.bool,
enableInfoButton: PropTypes.bool,
enableTouchTracking: PropTypes.bool,
hidesTransitionView: PropTypes.bool,
onContentLoad: PropTypes.func,
onTap: PropTypes.func,
onUpdatePosition: PropTypes.func,
onChangeDisplayMode: PropTypes.func
}
// requireNativeComponent automatically resolves this to "VideoManager"
var RCTViedoView = requireNativeComponent('VrVideo', VideoView)
export default VideoView