forked from brandlive1941/react-native-video-stream
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.js
92 lines (78 loc) · 2.22 KB
/
Player.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
/**
* Created by buhe on 16/5/4.
*/
import React, {Component} from 'react';
import {
requireNativeComponent,
View
} from 'react-native';
import { PropTypes } from 'prop-types';
class Player extends Component {
constructor(props, context) {
super(props, context);
this._onLoading = this._onLoading.bind(this);
this._onPaused = this._onPaused.bind(this);
this._onShutdown = this._onShutdown.bind(this);
this._onError = this._onError.bind(this);
this._onPlaying = this._onPlaying.bind(this);
}
_onLoading(event) {
this.props.onLoading && this.props.onLoading(event.nativeEvent);
}
_onPaused(event) {
this.props.onPaused && this.props.onPaused(event.nativeEvent);
}
_onShutdown(event) {
this.props.onShutdown && this.props.onShutdown(event.nativeEvent);
}
_onError(event) {
this.props.onError && this.props.onError(event.nativeEvent);
}
_onPlaying(event) {
this.props.onPlaying && this.props.onPlaying(event.nativeEvent);
}
render() {
const nativeProps = Object.assign({}, this.props);
Object.assign(nativeProps, {
onLoading: this._onLoading,
onPaused: this._onPaused,
onShutdown: this._onShutdown,
onError: this._onError,
onPlaying: this._onPlaying,
});
return (
<RCTPlayer
{...nativeProps}
/>
)
}
}
Player.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,
started:PropTypes.bool,
muted:PropTypes.bool, //iOS only
onLoading: PropTypes.func,
onPaused: PropTypes.func,
onShutdown: PropTypes.func,
onError: PropTypes.func,
onPlaying: PropTypes.func,
...View.propTypes,
}
const RCTPlayer = requireNativeComponent('RCTPlayer', Player);
module.exports = Player;
//var iface = {
// propTypes: {
// ...View.propTypes,
// source: PropTypes.object,
// started:PropTypes.bool,
// muted:PropTypes.bool, //iOS only
// },
// };
//
//module.exports = requireNativeComponent('RCTPlayer', iface);