-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
54 lines (42 loc) · 1.05 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
import {
NativeModules,
NativeEventEmitter,
DeviceEventEmitter,
Platform
} from "react-native";
class RNSAudioPlayer {
constructor() {
audioPlayer = NativeModules.RNSimpleAudioPlayer;
emitter =
Platform.OS === "ios"
? new NativeEventEmitter(audioPlayer)
: DeviceEventEmitter;
console.log("audioPlayer", audioPlayer);
}
prepare = url => {
return audioPlayer.prepare(url);
};
addListener = cb => {
emitter.addListener("RNSAudio", cb);
};
removeListener = cb => {
emitter.removeListener("RNSAudio", cb);
};
play = () => {
if (Platform.OS === "ios") return audioPlayer.play({});
return audioPlayer.play();
};
pause = () => {
return audioPlayer.pause();
};
stop = () => {
return audioPlayer.stop();
};
setVolume = newValue => {
audioPlayer.setVolume(newValue);
};
restart = () => {};
}
RNSAudioPlayer.EVENT_TYPES = NativeModules.RNSimpleAudioPlayer.EVENT_TYPES;
RNSAudioPlayer.STATUS = NativeModules.RNSimpleAudioPlayer.STATUS;
export default RNSAudioPlayer;