-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
145 lines (129 loc) · 3.72 KB
/
index.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
import React,{ Component} from 'react';
import PropTypes from 'prop-types';
import {
requireNativeComponent,
View,
UIManager,
findNodeHandle,
ViewPropTypes,
} from 'react-native';
/*var VideoView = React.createClass({
propTypes:{
style: View.propTypes.style,
source:PropTypes.shape({
url:PropTypes.string,
headers:PropTypes.object,
}),
...View.propTypes,//包含默认的View的属性
},
render(){
return(
<RCTVideoView
style = {this.props.style}
source = {this.props.source}
/>
);
}
});*/
/*var VideoView = {
name:'VideoView',
propTypes:{
style: View.propTypes.style,
source:PropTypes.shape({
url:PropTypes.string,
headers:PropTypes.object,
}),
...View.propTypes,//包含默认的View的属性,如果没有这句会报‘has no propType for native prop’错误
}
};*/
var RCT_VIDEO_REF = 'VideoView';
class VideoView extends Component{
constructor(props){
super(props);
}
/*_onChange(event){
if(!this.props.onPrepared){
return;
}
this.props.onPrepared(event.nativeEvent.duration);
}*/
_onPrepared(event){
console.log("_onPrepared" , event)
if(!this.props.onPrepared){
return;
}
this.props.onPrepared(event.nativeEvent.duration);
}
_onError(event){
console.log("______onError" , event , " :::::::::::::::; ")
if(!this.props.onError){
return;
}
this.props.onError(event.nativeEvent);
}
_onBufferUpdate(event){
console.log("_onBufferUpdate" , event)
if(!this.props.onBufferUpdate){
return;
}
this.props.onBufferUpdate(event.nativeEvent.buffer);
}
_onProgress(event){
console.log("_onProgress" , event)
if(!this.props.onProgress){
return;
}
this.props.onProgress(event.nativeEvent.progress);
}
pause(){
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs[RCT_VIDEO_REF]),
UIManager.VideoView.Commands.pause,//Commands.pause与native层定义的COMMAND_PAUSE_NAME一致
null//命令携带的参数数据
);
}
start(){
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs[RCT_VIDEO_REF]),
UIManager.VideoView.Commands.start,
null
);
}
seekTo(millSecond){
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs[RCT_VIDEO_REF]),
UIManager.VideoView.Commands.seekTo,
[millSecond]
);
}
render(){
//return <RCTVideoView {...this.props} onChange={this._onChange.bind(this)}/>;
return <RCTVideoView
{...this.props}
ref = {RCT_VIDEO_REF}
style={{width: 500, height: 500}}
onPrepared={this._onPrepared.bind(this)}
onError={this._onError.bind(this)}
onBufferUpdate={this._onBufferUpdate.bind(this)}
onProgress={this._onProgress.bind(this)}
/>;
};
}
VideoView.name = "VideoView";
// VideoView.propTypes = {
// onPrepared:PropTypes.func,
// onCompletion:PropTypes.func,
// onError:PropTypes.func,
// onBufferUpdate:PropTypes.func,
// onProgress:PropTypes.func,
// style: propTypes.style,
// source:PropTypes.shape({
// url:PropTypes.string,
// headers:PropTypes.object,
// }),
// ...ViewPropTypes,
// };
var RCTVideoView = requireNativeComponent('VideoView',VideoView,{
nativeOnly: {onChange: true}
});
module.exports = VideoView;