forked from jaydgoss/react-native-nodemediaclient
-
Notifications
You must be signed in to change notification settings - Fork 6
/
NodePlayerModule.js
77 lines (66 loc) · 1.83 KB
/
NodePlayerModule.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
//
// NodePlayerModule.js
//
// Created by Mingliang Chen on 2017/11/29.
// Copyright © 2017年 NodeMedia. All rights reserved.
//
import React, { Component } from 'react';
import { PropTypes } from 'prop-types';
import { requireNativeComponent, View, UIManager, findNodeHandle } from 'react-native';
var RCT_VIDEO_REF = 'NodePlayerView';
class NodePlayerView extends Component {
constructor(props) {
super(props);
}
_onChange(event) {
if (!this.props.onStatus) {
return;
}
this.props.onStatus(event.nativeEvent.code, event.nativeEvent.msg);
}
pause() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs[RCT_VIDEO_REF]),
UIManager.RCTNodePlayer.Commands.pause,
null
);
}
start() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs[RCT_VIDEO_REF]),
UIManager.RCTNodePlayer.Commands.start,
null
);
}
stop() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs[RCT_VIDEO_REF]),
UIManager.RCTNodePlayer.Commands.stop,
null
);
}
render() {
return <RCTNodePlayer
{...this.props}
ref={RCT_VIDEO_REF}
onChange={this._onChange.bind(this)}
/>;
};
}
NodePlayerView.name = RCT_VIDEO_REF;
NodePlayerView.propTypes = {
inputUrl: PropTypes.string,
bufferTime: PropTypes.number,
maxBufferTime: PropTypes.number,
autoplay: PropTypes.bool,
audioEnable: PropTypes.bool,
scaleMode: PropTypes.oneOf(['ScaleToFill', 'ScaleAspectFit', 'ScaleAspectFill']),
renderType: PropTypes.oneOf(['SURFACEVIEW', 'TEXTUREVIEW']),
cryptoKey:PropTypes.string,
onStatus: PropTypes.func,
...View.propTypes // 包含默认的View的属性
};
const RCTNodePlayer = requireNativeComponent('RCTNodePlayer', NodePlayerView, {
nativeOnly: { onChange: true }
});
module.exports = NodePlayerView;