-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfunc.js
165 lines (133 loc) · 3.84 KB
/
func.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import {NativeModules, DeviceEventEmitter} from 'react-native';
const Widget = NativeModules.FloatingVideoWidget;
/**
* Opens the floating video player and starts
* playing the video.
* @param {object} data The data object.
* @param {object} data.video The video object should atleast have a property named "".
* @param data.video.url The url of video to be played
* @param {Array} data.videos List of video objects structured similar to data.video.
* @param {number} data.seek Seek value of video.
* @param {number} data.index Index of the video in data.videos array.
*/
export function open(data) {
if (!data || typeof data !== "object") throw new Error("data must be an object with atleast one key as video object");
if (!data.video || typeof data.video !== "object" || !data.video.url) throw new Error("video must be an object with atleast one key 'uri: url to video");
if (!data.hasOwnProperty("videos") || data.videos.length == 0) {
let videos = [];
videos.push(data.video);
data.videos = videos;
}
if (!data.hasOwnProperty("seek") || !data.seek ) {
data.seek = 0;
}
if (!data.hasOwnProperty("index") || !data.seek ) {
data.index = 0;
}
Widget.open(data);
}
/**
* Close the floating video player
*
*/
export function close() {
Widget.close();
}
/**
* Request for draw_over_other_apps permission for android 6.0 and above.
* @return {Promise}
*/
export async function requestOverlayPermission() {
return await Widget.requestOverlayPermission();
}
/**
* Play the video
*
*/
export function play() {
Widget.play();
}
/**
* Pause the video
*
*/
export function pause() {
Widget.pause();
}
/**
* Play previous video
*
*/
export function prev() {
Widget.prev();
}
/**
* Play next video
*
*/
export function next() {
Widget.next();
}
/**
* @event onError Called when an error occurs
* @type {function}
*/
export function onError(callback) {
if (!callback) throw new Error("Callback cannot be undefined");
DeviceEventEmitter.addListener("onError", (event) => callback(event))
}
/**
* @event onError Called when video is played.
* @type {function}
*/
export function onPlay(callback) {
if (!callback) throw new Error("Callback cannot be undefined");
DeviceEventEmitter.addListener("onPlay", (event) => callback(event))
}
/**
* @event onPause Called when video is paused
* @type {function}
*/
export function onPause(callback) {
if (!callback) throw new Error("Callback cannot be undefined");
DeviceEventEmitter.addListener("onPause", (event) => callback(event))
}
/**
* @event onNext Called when a you play the next video
* @type {function}
*/
export function onNext(callback) {
if (!callback) throw new Error("Callback cannot be undefined");
DeviceEventEmitter.addListener("onNext", (event) => callback(event))
}
/**
* @event onPrev Called when you play the previous video
* @type {function}
*/
export function onPrev(callback) {
if (!callback) throw new Error("Callback cannot be undefined");
DeviceEventEmitter.addListener("onPrev", (event) => callback(event))
}
/**
* @event onClose Called when the floating video has closed.
* @type {function}
*/
export function onClose(callback) {
if (!callback) throw new Error("Callback cannot be undefined");
DeviceEventEmitter.addListener("onClose", (event) => callback(event))
}
/**
* @event onOpen Called when a new video is played from react-native side or when the floating player is opened
* @type {function}
*/
export function onOpen(callback) {
if (!callback) throw new Error("Callback cannot be undefined");
DeviceEventEmitter.addListener("onOpen", (event) => callback(event))
}
/**
* Removes all listeners
* Use this in your ComponenWillUnmount() function
*/
export function removeAllListeners() {
DeviceEventEmitter.removeAllListeners();
}