forked from buhe/react-native-pili
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.js
83 lines (71 loc) · 2.02 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
/**
* Created by buhe on 16/5/4.
*/
import React, {
Component,
PropTypes
} from 'react';
import {
requireNativeComponent,
View,
} from 'react-native';
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
aspectRatio: PropTypes.oneOf([0, 1, 2, 3, 4]),
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;