forked from dhoncrisley/react-native-nodemediaclient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodePlayerModule.js
More file actions
62 lines (54 loc) · 1.39 KB
/
NodePlayerModule.js
File metadata and controls
62 lines (54 loc) · 1.39 KB
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
import React from "react";
import {
requireNativeComponent,
UIManager,
findNodeHandle,
} from "react-native";
const NodePlayerView = (props, ref) => {
const playerRef = React.useRef();
const _onChange = (event) => {
if (!props.onStatus) {
return;
}
props.onStatus(event.nativeEvent.code, event.nativeEvent.msg);
};
const pause = () => {
if (playerRef.current)
UIManager.dispatchViewManagerCommand(
findNodeHandle(playerRef.current),
UIManager.RCTNodePlayer?.Commands?.pause,
null
);
};
const start = () => {
if (playerRef.current)
UIManager.dispatchViewManagerCommand(
findNodeHandle(playerRef.current),
UIManager.RCTNodePlayer?.Commands?.start,
null
);
};
const stop = () => {
if (playerRef.current)
UIManager.dispatchViewManagerCommand(
findNodeHandle(playerRef.current),
UIManager.RCTNodePlayer?.Commands?.stop,
null
);
};
React.useImperativeHandle(ref, () => ({ pause, start, stop }), [
pause,
start,
stop,
]);
React.useEffect(() => {
return () => {
stop();
};
}, []);
return <RCTNodePlayer {...props} ref={playerRef} onChange={_onChange} />;
};
const RCTNodePlayer = requireNativeComponent("RCTNodePlayer", NodePlayerView, {
nativeOnly: { onChange: true },
});
module.exports = React.forwardRef(NodePlayerView);