-
Notifications
You must be signed in to change notification settings - Fork 27
/
index.js
126 lines (102 loc) · 3.08 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
import React, { Component, PropTypes } from 'react';
import {
NativeAppEventEmitter,
NativeModules,
Platform,
StyleSheet,
requireNativeComponent,
DeviceEventEmitter,
View,
} from 'react-native';
const IJKPlayerManager = NativeModules.IJKPlayerManager || NativeModules.IJKPlayerModule;
const REF = 'RCTIJKPlayer';
function convertNativeProps(props) {
const newProps = { ...props };
return newProps;
}
export default class RCTIJKPlayer extends Component {
static PlayBackState = {
IJKMPMoviePlaybackStateStopped: 0,
IJKMPMoviePlaybackStatePlaying: 1,
IJKMPMoviePlaybackStatePaused: 2,
IJKMPMoviePlaybackStateInterrupted: 3,
IJKMPMoviePlaybackStateSeekingForward: 4,
IJKMPMoviePlaybackStateSeekingBackward: 5,
}
static constants = {
PlayBackState: this.PlayBackState,
};
static propTypes = {
...View.propTypes,
push_url: PropTypes.string,
onLiveStateChange: PropTypes.func,
};
static defaultProps = {
};
setNativeProps(props) {
this.refs[REF].setNativeProps(props);
}
constructor() {
super();
this.state = {
isAuthorized: false,
isRecording: false
};
}
async componentWillMount() {
const emitter = Platform.OS == 'ios' ? NativeAppEventEmitter : DeviceEventEmitter;
// this.playBackStateChangeListener = emitter.addListener('PlayBackState', this._onPlayBackStateChange);
}
componentWillUnmount() {
// this.playBackStateChangeListener.remove();
this.stop();
this.shutdown();
}
render() {
const style = [styles.base, this.props.style];
const nativeProps = convertNativeProps(this.props);
return <_RCTIJKPlayer ref={REF} {...nativeProps} />;
}
start(options) {
console.log("ijkplayer index start begin");
return IJKPlayerManager.start(options);
}
stop() {
console.log("stop");
IJKPlayerManager.stop();
}
resume() {
console.log("resume");
IJKPlayerManager.resume();
}
pause() {
console.log("pause");
IJKPlayerManager.pause();
}
shutdown() {
console.log("shutdown");
IJKPlayerManager.shutdown();
}
seekTo(currentPlaybackTime) {
console.log("seekTo ", currentPlaybackTime);
IJKPlayerManager.seekTo(currentPlaybackTime);
}
playbackInfo() {
let self = this;
return IJKPlayerManager.playbackInfo()
.then(data => {
for (var k in data) {
if (data.hasOwnProperty(k)) {
data[k] = +data[k];
}
}
// console.log(data);
if (self.props.onPlayBackInfo) self.props.onPlayBackInfo(data);
}).catch(error => console.log("error", error));
}
}
export const constants = RCTIJKPlayer.constants;
const _RCTIJKPlayer = requireNativeComponent('RCTIJKPlayer', RCTIJKPlayer);
const styles = StyleSheet.create({
base: {},
});