-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLive.js
143 lines (133 loc) · 3.73 KB
/
Live.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
/**
* Created by buhe on 16/5/4.
*/
import React, {Component} from 'react';
import {requireNativeComponent, View} from 'react-native';
import PropTypes from 'prop-types';
class Live extends Component {
constructor(props, context) {
super(props, context);
//console.log(props)
this._onReady = this
._onReady
.bind(this);
this._onLoading = this
._onLoading
.bind(this);
this._onPaused = this
._onPaused
.bind(this);
this._onStop = this
._onStop
.bind(this);
this._onError = this
._onError
.bind(this);
this._onPlaying = this
._onPlaying
.bind(this);
this._onAutoReconnecting = this
._onAutoReconnecting
.bind(this);
this._onProg = this
._onProg
.bind(this);
}
setNativeProps(nativeProps) {
this
._root
.setNativeProps(nativeProps);
}
seek = (time) => {
this.setNativeProps({seek: time})
}
setVolume=(volume)=>{
this.setNativeProps({volume:volume})
}
_onReady(event) {
this.props.onReady && this
.props
.onReady(event.nativeEvent)
}
_onAutoReconnecting(event) {
this.props.onAutoReconnecting && this
.props
.onAutoReconnecting(event.nativeEvent)
}
_onCompleted(event) {
this.props.onCompleted && this
.props
.onCompleted(event.nativeEvent)
}
_onLoading(event) {
this.props.onLoading && this
.props
.onLoading(event.nativeEvent);
}
_onPaused(event) {
this.props.onPaused && this
.props
.onPaused(event.nativeEvent);
}
_onStop(event) {
this.props._onStop && this
.props
._onStop(event.nativeEvent);
}
_onError(event) {
this.props.onError && this
.props
.onError(event.nativeEvent);
}
_onPlaying(event) {
this.props.onPlaying && this
.props
.onPlaying(event.nativeEvent);
}
_onProg(event) {
this.props.onProg && this
.props
.onProg(event.nativeEvent)
}
render() {
const nativeProps = Object.assign({}, this.props);
Object.assign(nativeProps, {
onLoading: this._onLoading,
onPaused: this._onPaused,
onStop: this._onStop,
onError: this._onError,
onPlaying: this._onPlaying,
onReady: this._onReady,
onAutoReconnecting: this._onAutoReconnecting,
onCompleted: this.on_onCompleted,
onProg: this._onProg
});
return (<RCTLive ref={component => this._root = component} {...nativeProps}/>)
}
}
Live.propTypes = {
source: PropTypes
.shape({ // 是否符合指定格式的物件
uri: PropTypes.string.isRequired,
controller: PropTypes.bool, //Android only
timeout: PropTypes.number, //Android only
hardCodec: PropTypes.bool, //Android only
live: PropTypes.bool, //Android only
}).isRequired,
paused: PropTypes.bool,
muted: PropTypes.bool,
volume:PropTypes.number,
//autoPlay:PropTypes.bool,
aspectRatio: PropTypes.oneOf([0, 1, 2, 3, 4]),
onLoading: PropTypes.func,
onPaused: PropTypes.func,
onStop: PropTypes.func,
onError: PropTypes.func,
onPlaying: PropTypes.func,
onReady: PropTypes.func,
onAutoReconnecting: PropTypes.func,
onProg: PropTypes.func,
...View.propTypes
}
const RCTLive = requireNativeComponent('RCTLive', Live);
module.exports = Live;