@capgo/capacitor-video-player 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapgoCapacitorVideoPlayer.podspec +17 -0
- package/Package.swift +28 -0
- package/README.md +431 -0
- package/android/build.gradle +72 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/capgo/videoplayer/FullscreenExoPlayerFragment.java +1406 -0
- package/android/src/main/java/com/capgo/videoplayer/Notifications/MyRunnable.java +21 -0
- package/android/src/main/java/com/capgo/videoplayer/Notifications/NotificationCenter.java +61 -0
- package/android/src/main/java/com/capgo/videoplayer/PickerVideo/AdapterVideoList.java +47 -0
- package/android/src/main/java/com/capgo/videoplayer/PickerVideo/ModelVideo.java +49 -0
- package/android/src/main/java/com/capgo/videoplayer/PickerVideo/PickerVideoFragment.java +116 -0
- package/android/src/main/java/com/capgo/videoplayer/PickerVideo/VideoRecyclerViewHolder.java +65 -0
- package/android/src/main/java/com/capgo/videoplayer/Utilities/FilesUtils.java +38 -0
- package/android/src/main/java/com/capgo/videoplayer/Utilities/FragmentUtils.java +32 -0
- package/android/src/main/java/com/capgo/videoplayer/VideoPlayer.java +71 -0
- package/android/src/main/java/com/capgo/videoplayer/VideoPlayerPlugin.java +1239 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/android/src/main/res/drawable/bg_round_rect_white_50.xml +9 -0
- package/android/src/main/res/drawable/bg_rounded_rectangle_white_corner_rounded.xml +10 -0
- package/android/src/main/res/drawable/exo_close_btn.xml +12 -0
- package/android/src/main/res/drawable/gradient_transparent_middle.xml +12 -0
- package/android/src/main/res/drawable/ic_arrow_left.xml +5 -0
- package/android/src/main/res/drawable/ic_baseline_lq.xml +7 -0
- package/android/src/main/res/drawable/ic_exo_icon_fastforward.xml +35 -0
- package/android/src/main/res/drawable/ic_exo_icon_pause.xml +26 -0
- package/android/src/main/res/drawable/ic_exo_icon_play.xml +36 -0
- package/android/src/main/res/drawable/ic_exo_icon_rewind.xml +35 -0
- package/android/src/main/res/drawable/ic_expand.xml +5 -0
- package/android/src/main/res/drawable/ic_fit.xml +5 -0
- package/android/src/main/res/drawable/ic_image_background.xml +12 -0
- package/android/src/main/res/drawable/ic_img_16_9_background.xml +10 -0
- package/android/src/main/res/drawable/ic_img_9_16_background.xml +10 -0
- package/android/src/main/res/drawable/ic_outline_lock.xml +5 -0
- package/android/src/main/res/drawable/ic_outline_lock_open.xml +5 -0
- package/android/src/main/res/drawable/ic_pip_white.xml +5 -0
- package/android/src/main/res/drawable/ic_views.xml +18 -0
- package/android/src/main/res/drawable/ic_zoom.xml +5 -0
- package/android/src/main/res/layout/bridge_layout_main.xml +15 -0
- package/android/src/main/res/layout/exo_playback_control_view.xml +287 -0
- package/android/src/main/res/layout/exoplayer_layout_youtube.xml +361 -0
- package/android/src/main/res/layout/fragment_fs_exoplayer.xml +50 -0
- package/android/src/main/res/layout/fragment_picker_video.xml +21 -0
- package/android/src/main/res/layout/row_video.xml +76 -0
- package/android/src/main/res/values/colors.xml +14 -0
- package/android/src/main/res/values/strings.xml +3 -0
- package/android/src/main/res/values/styles.xml +3 -0
- package/dist/docs.json +686 -0
- package/dist/esm/definitions.d.ts +307 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web-utils/video-types.d.ts +4 -0
- package/dist/esm/web-utils/video-types.js +9 -0
- package/dist/esm/web-utils/video-types.js.map +1 -0
- package/dist/esm/web-utils/videoplayer.d.ts +30 -0
- package/dist/esm/web-utils/videoplayer.js +323 -0
- package/dist/esm/web-utils/videoplayer.js.map +1 -0
- package/dist/esm/web.d.ts +121 -0
- package/dist/esm/web.js +675 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +1019 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +1021 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/VideoPlayerPlugin/VideoPlayer.swift +8 -0
- package/ios/Sources/VideoPlayerPlugin/VideoPlayerPlugin.swift +23 -0
- package/ios/Tests/VideoPlayerPluginTests/VideoPlayerPluginTests.swift +15 -0
- package/package.json +85 -0
|
@@ -0,0 +1,1239 @@
|
|
|
1
|
+
package com.capgo.videoplayer;
|
|
2
|
+
|
|
3
|
+
import android.Manifest;
|
|
4
|
+
import android.app.Activity;
|
|
5
|
+
import android.app.UiModeManager;
|
|
6
|
+
import android.content.Context;
|
|
7
|
+
import android.content.pm.ActivityInfo;
|
|
8
|
+
import android.content.res.Configuration;
|
|
9
|
+
import android.os.Build;
|
|
10
|
+
import android.util.Log;
|
|
11
|
+
import android.view.ViewGroup;
|
|
12
|
+
import android.widget.FrameLayout;
|
|
13
|
+
import android.widget.Toast;
|
|
14
|
+
import androidx.fragment.app.Fragment;
|
|
15
|
+
import com.capgo.videoplayer.Notifications.MyRunnable;
|
|
16
|
+
import com.capgo.videoplayer.Notifications.NotificationCenter;
|
|
17
|
+
import com.capgo.videoplayer.PickerVideo.PickerVideoFragment;
|
|
18
|
+
import com.capgo.videoplayer.Utilities.FilesUtils;
|
|
19
|
+
import com.capgo.videoplayer.Utilities.FragmentUtils;
|
|
20
|
+
import com.getcapacitor.Bridge;
|
|
21
|
+
import com.getcapacitor.JSObject;
|
|
22
|
+
import com.getcapacitor.PermissionState;
|
|
23
|
+
import com.getcapacitor.Plugin;
|
|
24
|
+
import com.getcapacitor.PluginCall;
|
|
25
|
+
import com.getcapacitor.PluginMethod;
|
|
26
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
27
|
+
import com.getcapacitor.annotation.Permission;
|
|
28
|
+
import com.getcapacitor.annotation.PermissionCallback;
|
|
29
|
+
import java.util.HashMap;
|
|
30
|
+
import java.util.Map;
|
|
31
|
+
|
|
32
|
+
@CapacitorPlugin(
|
|
33
|
+
name = "VideoPlayer",
|
|
34
|
+
permissions = {
|
|
35
|
+
@Permission(alias = "mediaVideo", strings = { Manifest.permission.READ_MEDIA_VIDEO }),
|
|
36
|
+
@Permission(alias = "publicStorage", strings = { Manifest.permission.READ_EXTERNAL_STORAGE })
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
public class VideoPlayerPlugin extends Plugin {
|
|
40
|
+
|
|
41
|
+
// Permission alias constants
|
|
42
|
+
private static final String PERMISSION_DENIED_ERROR = "Unable to access media videos, user denied permission request";
|
|
43
|
+
|
|
44
|
+
static final String PUBLICSTORAGE = "publicStorage";
|
|
45
|
+
static final String MEDIAVIDEO = "mediaVideo";
|
|
46
|
+
|
|
47
|
+
private VideoPlayer implementation;
|
|
48
|
+
private static final String TAG = "VideoPlayer";
|
|
49
|
+
private final int frameLayoutViewId = 256;
|
|
50
|
+
private final int pickerLayoutViewId = 257;
|
|
51
|
+
|
|
52
|
+
private Context context;
|
|
53
|
+
private String videoPath;
|
|
54
|
+
private String subTitlePath;
|
|
55
|
+
private Boolean isTV;
|
|
56
|
+
private String fsPlayerId;
|
|
57
|
+
private String mode;
|
|
58
|
+
private Boolean exitOnEnd = true;
|
|
59
|
+
private Boolean loopOnEnd = false;
|
|
60
|
+
private Boolean pipEnabled = true;
|
|
61
|
+
private Boolean bkModeEnabled = true;
|
|
62
|
+
private Boolean showControls = true;
|
|
63
|
+
private String displayMode = "all";
|
|
64
|
+
private FullscreenExoPlayerFragment fsFragment;
|
|
65
|
+
private PickerVideoFragment pkFragment;
|
|
66
|
+
private FilesUtils filesUtils;
|
|
67
|
+
private JSObject headers;
|
|
68
|
+
private FragmentUtils fragmentUtils;
|
|
69
|
+
private PluginCall call;
|
|
70
|
+
private final Float[] rateList = { 0.25f, 0.5f, 0.75f, 1f, 2f, 4f };
|
|
71
|
+
private Float videoRate = 1f;
|
|
72
|
+
private String title;
|
|
73
|
+
private String smallTitle;
|
|
74
|
+
private String accentColor;
|
|
75
|
+
private Boolean chromecast = true;
|
|
76
|
+
private String artwork;
|
|
77
|
+
private String url;
|
|
78
|
+
private String playerId;
|
|
79
|
+
private String subtitle = "";
|
|
80
|
+
private String language = "";
|
|
81
|
+
private JSObject subTitleOptions;
|
|
82
|
+
private final JSObject ret = new JSObject();
|
|
83
|
+
|
|
84
|
+
@Override
|
|
85
|
+
public void load() {
|
|
86
|
+
// Get context
|
|
87
|
+
this.context = getContext();
|
|
88
|
+
implementation = new VideoPlayer(this.context);
|
|
89
|
+
this.filesUtils = new FilesUtils(this.context);
|
|
90
|
+
this.fragmentUtils = new FragmentUtils(getBridge());
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@PermissionCallback
|
|
94
|
+
private void permissionsCallback(PluginCall call) {
|
|
95
|
+
if (!isPermissionsGranted()) {
|
|
96
|
+
call.reject(PERMISSION_DENIED_ERROR);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
switch (call.getMethodName()) {
|
|
100
|
+
case "initPlayer" -> _initPlayer(call);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@PluginMethod
|
|
105
|
+
public void echo(PluginCall call) {
|
|
106
|
+
String value = call.getString("value");
|
|
107
|
+
|
|
108
|
+
JSObject ret = new JSObject();
|
|
109
|
+
ret.put("value", implementation.echo(value));
|
|
110
|
+
call.resolve(ret);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private boolean isPermissionsGranted() {
|
|
114
|
+
String permissionSet = PUBLICSTORAGE;
|
|
115
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
116
|
+
permissionSet = MEDIAVIDEO;
|
|
117
|
+
}
|
|
118
|
+
return getPermissionState(permissionSet) == PermissionState.GRANTED;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@PluginMethod
|
|
122
|
+
public void initPlayer(PluginCall call) {
|
|
123
|
+
this.call = call;
|
|
124
|
+
ret.put("method", "initPlayer");
|
|
125
|
+
ret.put("result", false);
|
|
126
|
+
// Check if running on a TV Device
|
|
127
|
+
isTV = isDeviceTV(context);
|
|
128
|
+
Log.d(TAG, "**** isTV " + isTV + " ****");
|
|
129
|
+
String _mode = call.getString("mode");
|
|
130
|
+
if (_mode == null) {
|
|
131
|
+
ret.put("message", "Must provide a Mode (fullscreen/embedded)");
|
|
132
|
+
call.resolve(ret);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
mode = _mode;
|
|
136
|
+
playerId = call.getString("playerId");
|
|
137
|
+
if (playerId == null) {
|
|
138
|
+
ret.put("message", "Must provide a PlayerId");
|
|
139
|
+
call.resolve(ret);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
videoRate = 1f;
|
|
143
|
+
if (call.getData().has("rate")) {
|
|
144
|
+
Float mRate = call.getFloat("rate");
|
|
145
|
+
if (isInRate(rateList, mRate)) {
|
|
146
|
+
videoRate = mRate;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
Boolean _exitOnEnd = true;
|
|
150
|
+
if (call.getData().has("exitOnEnd")) {
|
|
151
|
+
_exitOnEnd = call.getBoolean("exitOnEnd");
|
|
152
|
+
}
|
|
153
|
+
exitOnEnd = _exitOnEnd;
|
|
154
|
+
Boolean _loopOnEnd = false;
|
|
155
|
+
if (call.getData().has("loopOnEnd")) {
|
|
156
|
+
_loopOnEnd = call.getBoolean("loopOnEnd");
|
|
157
|
+
}
|
|
158
|
+
if (!exitOnEnd) loopOnEnd = _loopOnEnd;
|
|
159
|
+
Boolean _pipEnabled = true;
|
|
160
|
+
if (call.getData().has("pipEnabled")) {
|
|
161
|
+
_pipEnabled = call.getBoolean("pipEnabled");
|
|
162
|
+
}
|
|
163
|
+
pipEnabled = _pipEnabled;
|
|
164
|
+
Boolean _bkModeEnabled = true;
|
|
165
|
+
if (call.getData().has("bkmodeEnabled")) {
|
|
166
|
+
_bkModeEnabled = call.getBoolean("bkmodeEnabled");
|
|
167
|
+
}
|
|
168
|
+
bkModeEnabled = _bkModeEnabled;
|
|
169
|
+
Boolean _showControls = true;
|
|
170
|
+
if (call.getData().has("showControls")) {
|
|
171
|
+
_showControls = call.getBoolean("showControls");
|
|
172
|
+
}
|
|
173
|
+
showControls = _showControls;
|
|
174
|
+
String _displayMode = "all";
|
|
175
|
+
if (call.getData().has("displayMode")) {
|
|
176
|
+
_displayMode = call.getString("displayMode");
|
|
177
|
+
}
|
|
178
|
+
displayMode = _displayMode;
|
|
179
|
+
if ("fullscreen".equals(mode)) {
|
|
180
|
+
fsPlayerId = playerId;
|
|
181
|
+
url = call.getString("url");
|
|
182
|
+
if (url == null) {
|
|
183
|
+
ret.put("message", "Must provide an url");
|
|
184
|
+
call.resolve(ret);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (call.getData().has("subtitle")) {
|
|
188
|
+
subtitle = call.getString("subtitle");
|
|
189
|
+
}
|
|
190
|
+
if (call.getData().has("language")) {
|
|
191
|
+
language = call.getString("language");
|
|
192
|
+
}
|
|
193
|
+
subTitleOptions = new JSObject();
|
|
194
|
+
if (call.getData().has("subtitleOptions")) {
|
|
195
|
+
subTitleOptions = call.getObject("subtitleOptions");
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
JSObject _headers = new JSObject();
|
|
199
|
+
if (call.getData().has("headers")) {
|
|
200
|
+
_headers = call.getObject("headers");
|
|
201
|
+
}
|
|
202
|
+
headers = _headers;
|
|
203
|
+
String _title = "";
|
|
204
|
+
if (call.getData().has("title")) {
|
|
205
|
+
_title = call.getString("title");
|
|
206
|
+
}
|
|
207
|
+
title = _title;
|
|
208
|
+
String _smallTitle = "";
|
|
209
|
+
if (call.getData().has("smallTitle")) {
|
|
210
|
+
_smallTitle = call.getString("smallTitle");
|
|
211
|
+
}
|
|
212
|
+
smallTitle = _smallTitle;
|
|
213
|
+
String _accentColor = "";
|
|
214
|
+
if (call.getData().has("accentColor")) {
|
|
215
|
+
_accentColor = call.getString("accentColor");
|
|
216
|
+
}
|
|
217
|
+
accentColor = _accentColor;
|
|
218
|
+
Boolean _chromecast = true;
|
|
219
|
+
if (call.getData().has("chromecast")) {
|
|
220
|
+
_chromecast = call.getBoolean("chromecast");
|
|
221
|
+
}
|
|
222
|
+
chromecast = _chromecast;
|
|
223
|
+
String _artwork = "";
|
|
224
|
+
if (call.getData().has("artwork")) {
|
|
225
|
+
_artwork = call.getString("artwork");
|
|
226
|
+
}
|
|
227
|
+
artwork = _artwork;
|
|
228
|
+
AddObserversToNotificationCenter();
|
|
229
|
+
Log.v(TAG, "display url: " + url);
|
|
230
|
+
Log.v(TAG, "display subtitle: " + subtitle);
|
|
231
|
+
Log.v(TAG, "display language: " + language);
|
|
232
|
+
Log.v(TAG, "headers: " + headers);
|
|
233
|
+
Log.v(TAG, "title: " + title);
|
|
234
|
+
Log.v(TAG, "smallTitle: " + smallTitle);
|
|
235
|
+
Log.v(TAG, "accentColor: " + accentColor);
|
|
236
|
+
Log.v(TAG, "chromecast: " + chromecast);
|
|
237
|
+
Log.v(TAG, "artwork: " + artwork);
|
|
238
|
+
if (url.equals("internal") || url.contains("DCIM") || url.contains("Documents")) {
|
|
239
|
+
// Check for permissions to access media video files
|
|
240
|
+
if (isPermissionsGranted()) {
|
|
241
|
+
_initPlayer(call);
|
|
242
|
+
} else {
|
|
243
|
+
this.bridge.saveCall(call);
|
|
244
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
245
|
+
requestPermissionForAlias(MEDIAVIDEO, call, "permissionsCallback");
|
|
246
|
+
} else {
|
|
247
|
+
requestPermissionForAlias(PUBLICSTORAGE, call, "permissionsCallback");
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
} else {
|
|
251
|
+
_initPlayer(call);
|
|
252
|
+
}
|
|
253
|
+
} else if ("embedded".equals(mode)) {
|
|
254
|
+
ret.put("message", "Embedded Mode not implemented");
|
|
255
|
+
call.resolve(ret);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
@PluginMethod
|
|
261
|
+
public void isPlaying(final PluginCall call) {
|
|
262
|
+
this.call = call;
|
|
263
|
+
JSObject ret = new JSObject();
|
|
264
|
+
ret.put("method", "isPlaying");
|
|
265
|
+
String playerId = call.getString("playerId");
|
|
266
|
+
if (playerId == null) {
|
|
267
|
+
ret.put("result", false);
|
|
268
|
+
ret.put("message", "Must provide a PlayerId");
|
|
269
|
+
call.resolve(ret);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
|
|
273
|
+
bridge
|
|
274
|
+
.getActivity()
|
|
275
|
+
.runOnUiThread(
|
|
276
|
+
new Runnable() {
|
|
277
|
+
@Override
|
|
278
|
+
public void run() {
|
|
279
|
+
JSObject ret = new JSObject();
|
|
280
|
+
ret.put("method", "isPlaying");
|
|
281
|
+
if (fsFragment != null) {
|
|
282
|
+
boolean playing = fsFragment.isPlaying();
|
|
283
|
+
ret.put("result", true);
|
|
284
|
+
ret.put("value", playing);
|
|
285
|
+
call.resolve(ret);
|
|
286
|
+
} else {
|
|
287
|
+
ret.put("result", false);
|
|
288
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
289
|
+
call.resolve(ret);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
);
|
|
294
|
+
} else {
|
|
295
|
+
ret.put("result", false);
|
|
296
|
+
ret.put("message", "player is not defined");
|
|
297
|
+
call.resolve(ret);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
@PluginMethod
|
|
302
|
+
public void play(final PluginCall call) {
|
|
303
|
+
this.call = call;
|
|
304
|
+
JSObject ret = new JSObject();
|
|
305
|
+
ret.put("method", "play");
|
|
306
|
+
String playerId = call.getString("playerId");
|
|
307
|
+
if (playerId == null) {
|
|
308
|
+
ret.put("result", false);
|
|
309
|
+
ret.put("message", "Must provide a PlayerId");
|
|
310
|
+
call.resolve(ret);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
|
|
314
|
+
bridge
|
|
315
|
+
.getActivity()
|
|
316
|
+
.runOnUiThread(
|
|
317
|
+
new Runnable() {
|
|
318
|
+
@Override
|
|
319
|
+
public void run() {
|
|
320
|
+
JSObject ret = new JSObject();
|
|
321
|
+
ret.put("method", "play");
|
|
322
|
+
if (fsFragment != null) {
|
|
323
|
+
fsFragment.play();
|
|
324
|
+
boolean playing = fsFragment.isPlaying();
|
|
325
|
+
ret.put("result", true);
|
|
326
|
+
ret.put("value", true);
|
|
327
|
+
call.resolve(ret);
|
|
328
|
+
} else {
|
|
329
|
+
ret.put("result", false);
|
|
330
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
331
|
+
call.resolve(ret);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
);
|
|
336
|
+
} else {
|
|
337
|
+
ret.put("result", false);
|
|
338
|
+
ret.put("message", "player is not defined");
|
|
339
|
+
call.resolve(ret);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
@PluginMethod
|
|
344
|
+
public void pause(final PluginCall call) {
|
|
345
|
+
this.call = call;
|
|
346
|
+
JSObject ret = new JSObject();
|
|
347
|
+
ret.put("method", "pause");
|
|
348
|
+
String playerId = call.getString("playerId");
|
|
349
|
+
if (playerId == null) {
|
|
350
|
+
ret.put("result", false);
|
|
351
|
+
ret.put("message", "Must provide a PlayerId");
|
|
352
|
+
call.resolve(ret);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
|
|
356
|
+
bridge
|
|
357
|
+
.getActivity()
|
|
358
|
+
.runOnUiThread(
|
|
359
|
+
new Runnable() {
|
|
360
|
+
@Override
|
|
361
|
+
public void run() {
|
|
362
|
+
JSObject ret = new JSObject();
|
|
363
|
+
ret.put("method", "pause");
|
|
364
|
+
if (fsFragment != null) {
|
|
365
|
+
fsFragment.pause();
|
|
366
|
+
ret.put("result", true);
|
|
367
|
+
ret.put("value", true);
|
|
368
|
+
call.resolve(ret);
|
|
369
|
+
} else {
|
|
370
|
+
ret.put("result", false);
|
|
371
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
372
|
+
call.resolve(ret);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
);
|
|
377
|
+
} else {
|
|
378
|
+
ret.put("result", false);
|
|
379
|
+
ret.put("message", "player is not defined");
|
|
380
|
+
call.resolve(ret);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
@PluginMethod
|
|
385
|
+
public void getDuration(final PluginCall call) {
|
|
386
|
+
this.call = call;
|
|
387
|
+
JSObject ret = new JSObject();
|
|
388
|
+
ret.put("method", "getDuration");
|
|
389
|
+
String playerId = call.getString("playerId");
|
|
390
|
+
if (playerId == null) {
|
|
391
|
+
ret.put("result", false);
|
|
392
|
+
ret.put("message", "Must provide a PlayerId");
|
|
393
|
+
call.resolve(ret);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
|
|
397
|
+
bridge
|
|
398
|
+
.getActivity()
|
|
399
|
+
.runOnUiThread(
|
|
400
|
+
new Runnable() {
|
|
401
|
+
@Override
|
|
402
|
+
public void run() {
|
|
403
|
+
JSObject ret = new JSObject();
|
|
404
|
+
ret.put("method", "getDuration");
|
|
405
|
+
if (fsFragment != null) {
|
|
406
|
+
int duration = fsFragment.getDuration();
|
|
407
|
+
ret.put("result", true);
|
|
408
|
+
ret.put("value", duration);
|
|
409
|
+
call.resolve(ret);
|
|
410
|
+
} else {
|
|
411
|
+
ret.put("result", false);
|
|
412
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
413
|
+
call.resolve(ret);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
);
|
|
418
|
+
} else {
|
|
419
|
+
ret.put("result", false);
|
|
420
|
+
ret.put("message", "player is not defined");
|
|
421
|
+
call.resolve(ret);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
@PluginMethod
|
|
426
|
+
public void getCurrentTime(final PluginCall call) {
|
|
427
|
+
this.call = call;
|
|
428
|
+
JSObject ret = new JSObject();
|
|
429
|
+
ret.put("method", "getCurrentTime");
|
|
430
|
+
String playerId = call.getString("playerId");
|
|
431
|
+
if (playerId == null) {
|
|
432
|
+
ret.put("result", false);
|
|
433
|
+
ret.put("message", "Must provide a PlayerId");
|
|
434
|
+
call.resolve(ret);
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
|
|
438
|
+
bridge
|
|
439
|
+
.getActivity()
|
|
440
|
+
.runOnUiThread(
|
|
441
|
+
new Runnable() {
|
|
442
|
+
@Override
|
|
443
|
+
public void run() {
|
|
444
|
+
JSObject ret = new JSObject();
|
|
445
|
+
ret.put("method", "getCurrentTime");
|
|
446
|
+
if (fsFragment != null) {
|
|
447
|
+
int curTime = fsFragment.getCurrentTime();
|
|
448
|
+
ret.put("result", true);
|
|
449
|
+
ret.put("value", curTime);
|
|
450
|
+
call.resolve(ret);
|
|
451
|
+
} else {
|
|
452
|
+
ret.put("result", false);
|
|
453
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
454
|
+
call.resolve(ret);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
);
|
|
459
|
+
} else {
|
|
460
|
+
ret.put("result", false);
|
|
461
|
+
ret.put("message", "player is not defined");
|
|
462
|
+
call.resolve(ret);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
@PluginMethod
|
|
467
|
+
public void setCurrentTime(final PluginCall call) {
|
|
468
|
+
this.call = call;
|
|
469
|
+
JSObject ret = new JSObject();
|
|
470
|
+
ret.put("method", "setCurrentTime");
|
|
471
|
+
String playerId = call.getString("playerId");
|
|
472
|
+
if (playerId == null) {
|
|
473
|
+
ret.put("result", false);
|
|
474
|
+
ret.put("message", "Must provide a PlayerId");
|
|
475
|
+
call.resolve(ret);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
Double value = call.getDouble("seektime");
|
|
479
|
+
if (value == null) {
|
|
480
|
+
ret.put("result", false);
|
|
481
|
+
ret.put("message", "Must provide a time in second");
|
|
482
|
+
call.resolve(ret);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
final int cTime = (int) Math.round(value);
|
|
486
|
+
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
|
|
487
|
+
bridge
|
|
488
|
+
.getActivity()
|
|
489
|
+
.runOnUiThread(
|
|
490
|
+
new Runnable() {
|
|
491
|
+
@Override
|
|
492
|
+
public void run() {
|
|
493
|
+
JSObject ret = new JSObject();
|
|
494
|
+
ret.put("method", "setCurrentTime");
|
|
495
|
+
if (fsFragment != null) {
|
|
496
|
+
fsFragment.setCurrentTime(cTime);
|
|
497
|
+
ret.put("result", true);
|
|
498
|
+
ret.put("value", cTime);
|
|
499
|
+
call.resolve(ret);
|
|
500
|
+
} else {
|
|
501
|
+
ret.put("result", false);
|
|
502
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
503
|
+
call.resolve(ret);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
);
|
|
508
|
+
} else {
|
|
509
|
+
ret.put("result", false);
|
|
510
|
+
ret.put("message", "player is not defined");
|
|
511
|
+
call.resolve(ret);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
@PluginMethod
|
|
516
|
+
public void getVolume(final PluginCall call) {
|
|
517
|
+
this.call = call;
|
|
518
|
+
JSObject ret = new JSObject();
|
|
519
|
+
ret.put("method", "getVolume");
|
|
520
|
+
String playerId = call.getString("playerId");
|
|
521
|
+
if (playerId == null) {
|
|
522
|
+
ret.put("result", false);
|
|
523
|
+
ret.put("message", "Must provide a PlayerId");
|
|
524
|
+
call.resolve(ret);
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
|
|
528
|
+
bridge
|
|
529
|
+
.getActivity()
|
|
530
|
+
.runOnUiThread(
|
|
531
|
+
new Runnable() {
|
|
532
|
+
@Override
|
|
533
|
+
public void run() {
|
|
534
|
+
JSObject ret = new JSObject();
|
|
535
|
+
ret.put("method", "getVolume");
|
|
536
|
+
if (fsFragment != null) {
|
|
537
|
+
Float volume = fsFragment.getVolume();
|
|
538
|
+
ret.put("result", true);
|
|
539
|
+
ret.put("value", volume);
|
|
540
|
+
call.resolve(ret);
|
|
541
|
+
} else {
|
|
542
|
+
ret.put("result", false);
|
|
543
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
544
|
+
call.resolve(ret);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
);
|
|
549
|
+
} else {
|
|
550
|
+
ret.put("result", false);
|
|
551
|
+
ret.put("message", "player is not defined");
|
|
552
|
+
call.resolve(ret);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
@PluginMethod
|
|
557
|
+
public void setVolume(final PluginCall call) {
|
|
558
|
+
this.call = call;
|
|
559
|
+
JSObject ret = new JSObject();
|
|
560
|
+
ret.put("method", "setVolume");
|
|
561
|
+
String playerId = call.getString("playerId");
|
|
562
|
+
if (playerId == null) {
|
|
563
|
+
ret.put("result", false);
|
|
564
|
+
ret.put("message", "Must provide a PlayerId");
|
|
565
|
+
call.resolve(ret);
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
Float volume = call.getFloat("volume");
|
|
569
|
+
if (volume == null) {
|
|
570
|
+
ret.put("result", false);
|
|
571
|
+
ret.put("method", "setVolume");
|
|
572
|
+
ret.put("message", "Must provide a volume value");
|
|
573
|
+
call.resolve(ret);
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
|
|
577
|
+
bridge
|
|
578
|
+
.getActivity()
|
|
579
|
+
.runOnUiThread(
|
|
580
|
+
new Runnable() {
|
|
581
|
+
@Override
|
|
582
|
+
public void run() {
|
|
583
|
+
JSObject ret = new JSObject();
|
|
584
|
+
ret.put("method", "setVolume");
|
|
585
|
+
if (fsFragment != null) {
|
|
586
|
+
fsFragment.setVolume(volume);
|
|
587
|
+
ret.put("result", true);
|
|
588
|
+
ret.put("value", volume);
|
|
589
|
+
call.resolve(ret);
|
|
590
|
+
} else {
|
|
591
|
+
ret.put("result", false);
|
|
592
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
593
|
+
call.resolve(ret);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
);
|
|
598
|
+
} else {
|
|
599
|
+
ret.put("result", false);
|
|
600
|
+
ret.put("message", "player is not defined");
|
|
601
|
+
call.resolve(ret);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
@PluginMethod
|
|
606
|
+
public void getMuted(final PluginCall call) {
|
|
607
|
+
this.call = call;
|
|
608
|
+
JSObject ret = new JSObject();
|
|
609
|
+
ret.put("method", "getMuted");
|
|
610
|
+
String playerId = call.getString("playerId");
|
|
611
|
+
if (playerId == null) {
|
|
612
|
+
ret.put("result", false);
|
|
613
|
+
ret.put("message", "Must provide a PlayerId");
|
|
614
|
+
call.resolve(ret);
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
|
|
618
|
+
bridge
|
|
619
|
+
.getActivity()
|
|
620
|
+
.runOnUiThread(
|
|
621
|
+
new Runnable() {
|
|
622
|
+
@Override
|
|
623
|
+
public void run() {
|
|
624
|
+
JSObject ret = new JSObject();
|
|
625
|
+
ret.put("method", "getMuted");
|
|
626
|
+
if (fsFragment != null) {
|
|
627
|
+
boolean value = fsFragment.getMuted();
|
|
628
|
+
ret.put("result", true);
|
|
629
|
+
ret.put("value", value);
|
|
630
|
+
call.resolve(ret);
|
|
631
|
+
} else {
|
|
632
|
+
ret.put("result", false);
|
|
633
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
634
|
+
call.resolve(ret);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
);
|
|
639
|
+
} else {
|
|
640
|
+
ret.put("result", false);
|
|
641
|
+
ret.put("message", "player is not defined");
|
|
642
|
+
call.resolve(ret);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
@PluginMethod
|
|
647
|
+
public void setMuted(final PluginCall call) {
|
|
648
|
+
this.call = call;
|
|
649
|
+
JSObject ret = new JSObject();
|
|
650
|
+
ret.put("method", "setMuted");
|
|
651
|
+
String playerId = call.getString("playerId");
|
|
652
|
+
if (playerId == null) {
|
|
653
|
+
ret.put("result", false);
|
|
654
|
+
ret.put("message", "Must provide a PlayerId");
|
|
655
|
+
call.resolve(ret);
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
Boolean value = call.getBoolean("muted");
|
|
659
|
+
if (value == null) {
|
|
660
|
+
ret.put("result", true);
|
|
661
|
+
ret.put("message", "Must provide a boolean true/false");
|
|
662
|
+
call.resolve(ret);
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
final boolean bValue = value;
|
|
666
|
+
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
|
|
667
|
+
bridge
|
|
668
|
+
.getActivity()
|
|
669
|
+
.runOnUiThread(
|
|
670
|
+
new Runnable() {
|
|
671
|
+
@Override
|
|
672
|
+
public void run() {
|
|
673
|
+
JSObject ret = new JSObject();
|
|
674
|
+
ret.put("method", "setMuted");
|
|
675
|
+
if (fsFragment != null) {
|
|
676
|
+
fsFragment.setMuted(bValue);
|
|
677
|
+
ret.put("result", true);
|
|
678
|
+
ret.put("value", bValue);
|
|
679
|
+
call.resolve(ret);
|
|
680
|
+
} else {
|
|
681
|
+
ret.put("result", false);
|
|
682
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
683
|
+
call.resolve(ret);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
);
|
|
688
|
+
} else {
|
|
689
|
+
ret.put("result", false);
|
|
690
|
+
ret.put("message", "player is not defined");
|
|
691
|
+
call.resolve(ret);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
@PluginMethod
|
|
696
|
+
public void getRate(final PluginCall call) {
|
|
697
|
+
this.call = call;
|
|
698
|
+
JSObject ret = new JSObject();
|
|
699
|
+
ret.put("method", "getRate");
|
|
700
|
+
String playerId = call.getString("playerId");
|
|
701
|
+
if (playerId == null) {
|
|
702
|
+
ret.put("result", false);
|
|
703
|
+
ret.put("message", "Must provide a PlayerId");
|
|
704
|
+
call.resolve(ret);
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
|
|
708
|
+
bridge
|
|
709
|
+
.getActivity()
|
|
710
|
+
.runOnUiThread(
|
|
711
|
+
new Runnable() {
|
|
712
|
+
@Override
|
|
713
|
+
public void run() {
|
|
714
|
+
JSObject ret = new JSObject();
|
|
715
|
+
ret.put("method", "getRate");
|
|
716
|
+
if (fsFragment != null) {
|
|
717
|
+
Float rate = fsFragment.getRate();
|
|
718
|
+
ret.put("result", true);
|
|
719
|
+
ret.put("value", rate);
|
|
720
|
+
call.resolve(ret);
|
|
721
|
+
} else {
|
|
722
|
+
ret.put("result", false);
|
|
723
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
724
|
+
call.resolve(ret);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
);
|
|
729
|
+
} else {
|
|
730
|
+
ret.put("result", false);
|
|
731
|
+
ret.put("message", "player is not defined");
|
|
732
|
+
call.resolve(ret);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
@PluginMethod
|
|
737
|
+
public void setRate(final PluginCall call) {
|
|
738
|
+
this.call = call;
|
|
739
|
+
JSObject ret = new JSObject();
|
|
740
|
+
ret.put("method", "setRate");
|
|
741
|
+
String playerId = call.getString("playerId");
|
|
742
|
+
if (playerId == null) {
|
|
743
|
+
ret.put("result", false);
|
|
744
|
+
ret.put("message", "Must provide a PlayerId");
|
|
745
|
+
call.resolve(ret);
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
Float rate = call.getFloat("rate");
|
|
749
|
+
if (rate == null) {
|
|
750
|
+
ret.put("result", false);
|
|
751
|
+
ret.put("method", "setRate");
|
|
752
|
+
ret.put("message", "Must provide a volume value");
|
|
753
|
+
call.resolve(ret);
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
if (isInRate(rateList, rate)) {
|
|
757
|
+
videoRate = rate;
|
|
758
|
+
} else {
|
|
759
|
+
videoRate = 1f;
|
|
760
|
+
}
|
|
761
|
+
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
|
|
762
|
+
bridge
|
|
763
|
+
.getActivity()
|
|
764
|
+
.runOnUiThread(
|
|
765
|
+
new Runnable() {
|
|
766
|
+
@Override
|
|
767
|
+
public void run() {
|
|
768
|
+
JSObject ret = new JSObject();
|
|
769
|
+
ret.put("method", "setRate");
|
|
770
|
+
if (fsFragment != null) {
|
|
771
|
+
fsFragment.setRate(videoRate);
|
|
772
|
+
ret.put("result", true);
|
|
773
|
+
ret.put("value", videoRate);
|
|
774
|
+
call.resolve(ret);
|
|
775
|
+
} else {
|
|
776
|
+
ret.put("result", false);
|
|
777
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
778
|
+
call.resolve(ret);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
);
|
|
783
|
+
} else {
|
|
784
|
+
ret.put("result", false);
|
|
785
|
+
ret.put("message", "player is not defined");
|
|
786
|
+
call.resolve(ret);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
@PluginMethod
|
|
791
|
+
public void stopAllPlayers(PluginCall call) {
|
|
792
|
+
this.call = call;
|
|
793
|
+
bridge
|
|
794
|
+
.getActivity()
|
|
795
|
+
.runOnUiThread(
|
|
796
|
+
new Runnable() {
|
|
797
|
+
@Override
|
|
798
|
+
public void run() {
|
|
799
|
+
JSObject ret = new JSObject();
|
|
800
|
+
ret.put("method", "stopAllPlayers");
|
|
801
|
+
if (fsFragment != null) {
|
|
802
|
+
fsFragment.pause();
|
|
803
|
+
ret.put("result", true);
|
|
804
|
+
ret.put("value", true);
|
|
805
|
+
call.resolve(ret);
|
|
806
|
+
} else {
|
|
807
|
+
ret.put("result", false);
|
|
808
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
809
|
+
call.resolve(ret);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
@PluginMethod
|
|
817
|
+
public void isControllerIsFullyVisible(PluginCall call) {
|
|
818
|
+
this.call = call;
|
|
819
|
+
bridge
|
|
820
|
+
.getActivity()
|
|
821
|
+
.runOnUiThread(
|
|
822
|
+
new Runnable() {
|
|
823
|
+
@Override
|
|
824
|
+
public void run() {
|
|
825
|
+
JSObject ret = new JSObject();
|
|
826
|
+
ret.put("method", "isControllerIsFullyVisible");
|
|
827
|
+
if (fsFragment != null) {
|
|
828
|
+
ret.put("result", true);
|
|
829
|
+
ret.put("value", fsFragment.isControllerIsFullyVisible());
|
|
830
|
+
call.resolve(ret);
|
|
831
|
+
} else {
|
|
832
|
+
ret.put("result", false);
|
|
833
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
834
|
+
call.resolve(ret);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
@PluginMethod
|
|
842
|
+
public void showController(PluginCall call) {
|
|
843
|
+
this.call = call;
|
|
844
|
+
bridge
|
|
845
|
+
.getActivity()
|
|
846
|
+
.runOnUiThread(
|
|
847
|
+
new Runnable() {
|
|
848
|
+
@Override
|
|
849
|
+
public void run() {
|
|
850
|
+
JSObject ret = new JSObject();
|
|
851
|
+
ret.put("method", "showController");
|
|
852
|
+
if (fsFragment != null) {
|
|
853
|
+
fsFragment.showController();
|
|
854
|
+
ret.put("result", true);
|
|
855
|
+
ret.put("value", true);
|
|
856
|
+
call.resolve(ret);
|
|
857
|
+
} else {
|
|
858
|
+
ret.put("result", false);
|
|
859
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
860
|
+
call.resolve(ret);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
@PluginMethod
|
|
868
|
+
public void exitPlayer(PluginCall call) {
|
|
869
|
+
this.call = call;
|
|
870
|
+
bridge
|
|
871
|
+
.getActivity()
|
|
872
|
+
.runOnUiThread(
|
|
873
|
+
new Runnable() {
|
|
874
|
+
@Override
|
|
875
|
+
public void run() {
|
|
876
|
+
JSObject ret = new JSObject();
|
|
877
|
+
ret.put("method", "exitPlayer");
|
|
878
|
+
if (fsFragment != null) {
|
|
879
|
+
fsFragment.playerExit();
|
|
880
|
+
ret.put("result", true);
|
|
881
|
+
ret.put("value", true);
|
|
882
|
+
call.resolve(ret);
|
|
883
|
+
} else {
|
|
884
|
+
ret.put("result", false);
|
|
885
|
+
ret.put("message", "Fullscreen fragment is not defined");
|
|
886
|
+
call.resolve(ret);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
);
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
public boolean isDeviceTV(Context context) {
|
|
894
|
+
//Since Android TV is only API 21+ that is the only time we will compare configurations
|
|
895
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
896
|
+
UiModeManager uiManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
|
|
897
|
+
return uiManager != null && uiManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
|
|
898
|
+
}
|
|
899
|
+
return false;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
private void _initPlayer(PluginCall call) {
|
|
903
|
+
// Got Permissions ;
|
|
904
|
+
if (url.equals("internal")) {
|
|
905
|
+
createPickerVideoFragment(call);
|
|
906
|
+
} else {
|
|
907
|
+
// get the videoPath
|
|
908
|
+
videoPath = filesUtils.getFilePath(url);
|
|
909
|
+
// get the subTitlePath if any
|
|
910
|
+
if (subtitle != null && subtitle.length() > 0) {
|
|
911
|
+
subTitlePath = filesUtils.getFilePath(subtitle);
|
|
912
|
+
} else {
|
|
913
|
+
subTitlePath = null;
|
|
914
|
+
}
|
|
915
|
+
Log.v(TAG, "*** calculated videoPath: " + videoPath);
|
|
916
|
+
Log.v(TAG, "*** calculated subTitlePath: " + subTitlePath);
|
|
917
|
+
if (videoPath != null) {
|
|
918
|
+
createFullScreenFragment(
|
|
919
|
+
call,
|
|
920
|
+
videoPath,
|
|
921
|
+
videoRate,
|
|
922
|
+
exitOnEnd,
|
|
923
|
+
loopOnEnd,
|
|
924
|
+
pipEnabled,
|
|
925
|
+
bkModeEnabled,
|
|
926
|
+
showControls,
|
|
927
|
+
displayMode,
|
|
928
|
+
subTitlePath,
|
|
929
|
+
language,
|
|
930
|
+
subTitleOptions,
|
|
931
|
+
headers,
|
|
932
|
+
title,
|
|
933
|
+
smallTitle,
|
|
934
|
+
accentColor,
|
|
935
|
+
chromecast,
|
|
936
|
+
artwork,
|
|
937
|
+
isTV,
|
|
938
|
+
playerId,
|
|
939
|
+
false,
|
|
940
|
+
null
|
|
941
|
+
);
|
|
942
|
+
} else {
|
|
943
|
+
Map<String, Object> info = new HashMap<String, Object>() {
|
|
944
|
+
{
|
|
945
|
+
put("dismiss", "1");
|
|
946
|
+
put("currentTime", "0");
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
NotificationCenter.defaultCenter().postNotification("playerFullscreenDismiss", info);
|
|
950
|
+
ret.put("message", "initPlayer command failed: Video file not found");
|
|
951
|
+
call.resolve(ret);
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
private Boolean isInRate(Float arr[], Float rate) {
|
|
958
|
+
Boolean ret = false;
|
|
959
|
+
for (Float el : arr) {
|
|
960
|
+
if (el.equals(rate)) {
|
|
961
|
+
ret = true;
|
|
962
|
+
break;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
return ret;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
private void AddObserversToNotificationCenter() {
|
|
969
|
+
NotificationCenter.defaultCenter().addMethodForNotification(
|
|
970
|
+
"playerItemPlay",
|
|
971
|
+
new MyRunnable() {
|
|
972
|
+
@Override
|
|
973
|
+
public void run() {
|
|
974
|
+
JSObject data = new JSObject();
|
|
975
|
+
data.put("fromPlayerId", this.getInfo().get("fromPlayerId"));
|
|
976
|
+
data.put("currentTime", this.getInfo().get("currentTime"));
|
|
977
|
+
notifyListeners("jeepCapVideoPlayerPlay", data);
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
);
|
|
982
|
+
NotificationCenter.defaultCenter().addMethodForNotification(
|
|
983
|
+
"playerItemPause",
|
|
984
|
+
new MyRunnable() {
|
|
985
|
+
@Override
|
|
986
|
+
public void run() {
|
|
987
|
+
JSObject data = new JSObject();
|
|
988
|
+
data.put("fromPlayerId", this.getInfo().get("fromPlayerId"));
|
|
989
|
+
data.put("currentTime", this.getInfo().get("currentTime"));
|
|
990
|
+
notifyListeners("jeepCapVideoPlayerPause", data);
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
);
|
|
995
|
+
NotificationCenter.defaultCenter().addMethodForNotification(
|
|
996
|
+
"playerItemReady",
|
|
997
|
+
new MyRunnable() {
|
|
998
|
+
@Override
|
|
999
|
+
public void run() {
|
|
1000
|
+
JSObject data = new JSObject();
|
|
1001
|
+
data.put("fromPlayerId", this.getInfo().get("fromPlayerId"));
|
|
1002
|
+
data.put("currentTime", this.getInfo().get("currentTime"));
|
|
1003
|
+
notifyListeners("jeepCapVideoPlayerReady", data);
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
);
|
|
1008
|
+
NotificationCenter.defaultCenter().addMethodForNotification(
|
|
1009
|
+
"playerItemEnd",
|
|
1010
|
+
new MyRunnable() {
|
|
1011
|
+
@Override
|
|
1012
|
+
public void run() {
|
|
1013
|
+
final JSObject data = new JSObject();
|
|
1014
|
+
data.put("fromPlayerId", this.getInfo().get("fromPlayerId"));
|
|
1015
|
+
data.put("currentTime", this.getInfo().get("currentTime"));
|
|
1016
|
+
bridge
|
|
1017
|
+
.getActivity()
|
|
1018
|
+
.runOnUiThread(
|
|
1019
|
+
new Runnable() {
|
|
1020
|
+
@Override
|
|
1021
|
+
public void run() {
|
|
1022
|
+
FrameLayout frameLayoutView = getBridge().getActivity().findViewById(frameLayoutViewId);
|
|
1023
|
+
|
|
1024
|
+
if (frameLayoutView != null) {
|
|
1025
|
+
((ViewGroup) getBridge().getWebView().getParent()).removeView(frameLayoutView);
|
|
1026
|
+
fragmentUtils.removeFragment(fsFragment);
|
|
1027
|
+
}
|
|
1028
|
+
fsFragment = null;
|
|
1029
|
+
NotificationCenter.defaultCenter().removeAllNotifications();
|
|
1030
|
+
notifyListeners("jeepCapVideoPlayerEnded", data);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
);
|
|
1037
|
+
NotificationCenter.defaultCenter().addMethodForNotification(
|
|
1038
|
+
"playerFullscreenDismiss",
|
|
1039
|
+
new MyRunnable() {
|
|
1040
|
+
@Override
|
|
1041
|
+
public void run() {
|
|
1042
|
+
boolean ret = false;
|
|
1043
|
+
final JSObject data = new JSObject();
|
|
1044
|
+
if (Integer.valueOf((String) this.getInfo().get("dismiss")) == 1) ret = true;
|
|
1045
|
+
data.put("dismiss", ret);
|
|
1046
|
+
data.put("currentTime", this.getInfo().get("currentTime"));
|
|
1047
|
+
bridge
|
|
1048
|
+
.getActivity()
|
|
1049
|
+
.runOnUiThread(
|
|
1050
|
+
new Runnable() {
|
|
1051
|
+
@Override
|
|
1052
|
+
public void run() {
|
|
1053
|
+
FrameLayout frameLayoutView = getBridge().getActivity().findViewById(frameLayoutViewId);
|
|
1054
|
+
|
|
1055
|
+
if (frameLayoutView != null) {
|
|
1056
|
+
((ViewGroup) getBridge().getWebView().getParent()).removeView(frameLayoutView);
|
|
1057
|
+
fragmentUtils.removeFragment(fsFragment);
|
|
1058
|
+
}
|
|
1059
|
+
fsFragment = null;
|
|
1060
|
+
NotificationCenter.defaultCenter().removeAllNotifications();
|
|
1061
|
+
notifyListeners("jeepCapVideoPlayerExit", data);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
);
|
|
1068
|
+
NotificationCenter.defaultCenter().addMethodForNotification(
|
|
1069
|
+
"videoPathInternalReady",
|
|
1070
|
+
new MyRunnable() {
|
|
1071
|
+
@Override
|
|
1072
|
+
public void run() {
|
|
1073
|
+
long videoId = (Long) this.getInfo().get("videoId");
|
|
1074
|
+
// Get the previously saved call
|
|
1075
|
+
FrameLayout pickerLayoutView = getBridge().getActivity().findViewById(pickerLayoutViewId);
|
|
1076
|
+
if (pickerLayoutView != null) {
|
|
1077
|
+
((ViewGroup) getBridge().getWebView().getParent()).removeView(pickerLayoutView);
|
|
1078
|
+
fragmentUtils.removeFragment(pkFragment);
|
|
1079
|
+
}
|
|
1080
|
+
pkFragment = null;
|
|
1081
|
+
if (videoId != -1) {
|
|
1082
|
+
Log.v(TAG, "§§§§ Notification videoPathInternalReady chromecast: " + chromecast);
|
|
1083
|
+
createFullScreenFragment(
|
|
1084
|
+
call,
|
|
1085
|
+
videoPath,
|
|
1086
|
+
videoRate,
|
|
1087
|
+
exitOnEnd,
|
|
1088
|
+
loopOnEnd,
|
|
1089
|
+
pipEnabled,
|
|
1090
|
+
bkModeEnabled,
|
|
1091
|
+
showControls,
|
|
1092
|
+
displayMode,
|
|
1093
|
+
null,
|
|
1094
|
+
null,
|
|
1095
|
+
null,
|
|
1096
|
+
headers,
|
|
1097
|
+
title,
|
|
1098
|
+
smallTitle,
|
|
1099
|
+
accentColor,
|
|
1100
|
+
chromecast,
|
|
1101
|
+
artwork,
|
|
1102
|
+
isTV,
|
|
1103
|
+
fsPlayerId,
|
|
1104
|
+
true,
|
|
1105
|
+
videoId
|
|
1106
|
+
);
|
|
1107
|
+
} else {
|
|
1108
|
+
Toast.makeText(context, "No Video files found ", Toast.LENGTH_SHORT).show();
|
|
1109
|
+
Map<String, Object> info = new HashMap<String, Object>() {
|
|
1110
|
+
{
|
|
1111
|
+
put("dismiss", "1");
|
|
1112
|
+
put("currentTime", "0");
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
NotificationCenter.defaultCenter().postNotification("playerFullscreenDismiss", info);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
);
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
private void createFullScreenFragment(
|
|
1123
|
+
final PluginCall call,
|
|
1124
|
+
String videoPath,
|
|
1125
|
+
Float videoRate,
|
|
1126
|
+
Boolean exitOnEnd,
|
|
1127
|
+
Boolean loopOnEnd,
|
|
1128
|
+
Boolean pipEnabled,
|
|
1129
|
+
Boolean bkModeEnabled,
|
|
1130
|
+
Boolean showControls,
|
|
1131
|
+
String displayMode,
|
|
1132
|
+
String subTitle,
|
|
1133
|
+
String language,
|
|
1134
|
+
JSObject subTitleOptions,
|
|
1135
|
+
JSObject headers,
|
|
1136
|
+
String title,
|
|
1137
|
+
String smallTitle,
|
|
1138
|
+
String accentColor,
|
|
1139
|
+
Boolean chromecast,
|
|
1140
|
+
String artwork,
|
|
1141
|
+
Boolean isTV,
|
|
1142
|
+
String playerId,
|
|
1143
|
+
Boolean isInternal,
|
|
1144
|
+
Long videoId
|
|
1145
|
+
) {
|
|
1146
|
+
Log.v(TAG, "§§§§ createFullScreenFragment chromecast: " + chromecast);
|
|
1147
|
+
|
|
1148
|
+
fsFragment = implementation.createFullScreenFragment(
|
|
1149
|
+
videoPath,
|
|
1150
|
+
videoRate,
|
|
1151
|
+
exitOnEnd,
|
|
1152
|
+
loopOnEnd,
|
|
1153
|
+
pipEnabled,
|
|
1154
|
+
bkModeEnabled,
|
|
1155
|
+
showControls,
|
|
1156
|
+
displayMode,
|
|
1157
|
+
subTitle,
|
|
1158
|
+
language,
|
|
1159
|
+
subTitleOptions,
|
|
1160
|
+
headers,
|
|
1161
|
+
title,
|
|
1162
|
+
smallTitle,
|
|
1163
|
+
accentColor,
|
|
1164
|
+
chromecast,
|
|
1165
|
+
artwork,
|
|
1166
|
+
isTV,
|
|
1167
|
+
playerId,
|
|
1168
|
+
isInternal,
|
|
1169
|
+
videoId
|
|
1170
|
+
);
|
|
1171
|
+
bridge
|
|
1172
|
+
.getActivity()
|
|
1173
|
+
.runOnUiThread(
|
|
1174
|
+
new Runnable() {
|
|
1175
|
+
@Override
|
|
1176
|
+
public void run() {
|
|
1177
|
+
JSObject ret = new JSObject();
|
|
1178
|
+
ret.put("method", "initPlayer");
|
|
1179
|
+
FrameLayout frameLayoutView = getBridge().getActivity().findViewById(frameLayoutViewId);
|
|
1180
|
+
if (frameLayoutView != null) {
|
|
1181
|
+
ret.put("result", false);
|
|
1182
|
+
ret.put("message", "FrameLayout for ExoPlayer already exists");
|
|
1183
|
+
} else {
|
|
1184
|
+
// Initialize a new FrameLayout as container for fragment
|
|
1185
|
+
frameLayoutView = new FrameLayout(getActivity().getApplicationContext());
|
|
1186
|
+
frameLayoutView.setId(frameLayoutViewId);
|
|
1187
|
+
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
|
|
1188
|
+
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
1189
|
+
FrameLayout.LayoutParams.MATCH_PARENT
|
|
1190
|
+
);
|
|
1191
|
+
// Apply the Layout Parameters to frameLayout
|
|
1192
|
+
frameLayoutView.setLayoutParams(lp);
|
|
1193
|
+
|
|
1194
|
+
((ViewGroup) getBridge().getWebView().getParent()).addView(frameLayoutView);
|
|
1195
|
+
fragmentUtils.loadFragment(fsFragment, frameLayoutViewId);
|
|
1196
|
+
ret.put("result", true);
|
|
1197
|
+
}
|
|
1198
|
+
call.resolve(ret);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
);
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
private void createPickerVideoFragment(final PluginCall call) {
|
|
1205
|
+
pkFragment = implementation.createPickerVideoFragment();
|
|
1206
|
+
|
|
1207
|
+
bridge
|
|
1208
|
+
.getActivity()
|
|
1209
|
+
.runOnUiThread(
|
|
1210
|
+
new Runnable() {
|
|
1211
|
+
@Override
|
|
1212
|
+
public void run() {
|
|
1213
|
+
JSObject ret = new JSObject();
|
|
1214
|
+
ret.put("method", "initPlayer");
|
|
1215
|
+
FrameLayout pickerLayoutView = getBridge().getActivity().findViewById(pickerLayoutViewId);
|
|
1216
|
+
if (pickerLayoutView != null) {
|
|
1217
|
+
ret.put("result", false);
|
|
1218
|
+
ret.put("message", "FrameLayout for VideoPicker already exists");
|
|
1219
|
+
} else {
|
|
1220
|
+
// Initialize a new FrameLayout as container for fragment
|
|
1221
|
+
pickerLayoutView = new FrameLayout(getActivity().getApplicationContext());
|
|
1222
|
+
pickerLayoutView.setId(pickerLayoutViewId);
|
|
1223
|
+
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
|
|
1224
|
+
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
1225
|
+
FrameLayout.LayoutParams.MATCH_PARENT
|
|
1226
|
+
);
|
|
1227
|
+
// Apply the Layout Parameters to frameLayout
|
|
1228
|
+
pickerLayoutView.setLayoutParams(lp);
|
|
1229
|
+
|
|
1230
|
+
((ViewGroup) getBridge().getWebView().getParent()).addView(pickerLayoutView);
|
|
1231
|
+
fragmentUtils.loadFragment(pkFragment, pickerLayoutViewId);
|
|
1232
|
+
ret.put("result", true);
|
|
1233
|
+
}
|
|
1234
|
+
call.resolve(ret);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
);
|
|
1238
|
+
}
|
|
1239
|
+
}
|