cordova-plugin-media3 1.1.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/.travis.yml +0 -0
- package/CODE_OF_CONDUCT.md +46 -0
- package/CONTRIBUTING.md +4 -0
- package/LICENSE +21 -0
- package/README.md +297 -0
- package/package.json +32 -0
- package/plugin.xml +61 -0
- package/src/android/CallbackResponse.java +53 -0
- package/src/android/Configuration.java +104 -0
- package/src/android/DeviceDetector.java +132 -0
- package/src/android/LayoutProvider.java +218 -0
- package/src/android/Payload.java +361 -0
- package/src/android/Player.java +1063 -0
- package/src/android/Plugin.java +287 -0
- package/src/res/drawable/fastforward.png +0 -0
- package/src/res/drawable/next.png +0 -0
- package/src/res/drawable/pause.png +0 -0
- package/src/res/drawable/play.png +0 -0
- package/src/res/drawable/previous.png +0 -0
- package/src/res/drawable/rewind.png +0 -0
- package/src/res/layout/exo_playback_control_view.xml +121 -0
- package/src/res/layout/exo_rounded_corners.xml +6 -0
- package/src/res/layout/exo_simple_player_view.xml +58 -0
- package/src/res/values/constants.xml +23 -0
- package/src/res/values/ids.xml +9 -0
- package/src/res/values/styles.xml +52 -0
- package/www/exoplayer.js +91 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
/*
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2017 Nedim Cholich
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
package co.frontyard.cordova.plugin.exoplayer;
|
|
25
|
+
|
|
26
|
+
import android.util.Log;
|
|
27
|
+
import android.view.*;
|
|
28
|
+
import androidx.media3.common.*;
|
|
29
|
+
import androidx.media3.exoplayer.*;
|
|
30
|
+
import androidx.media3.exoplayer.trackselection.*;
|
|
31
|
+
import androidx.media3.common.C;
|
|
32
|
+
import androidx.media3.common.Format;
|
|
33
|
+
import androidx.media3.common.Tracks;
|
|
34
|
+
// import com.google.android.exoplayer2.video.*;
|
|
35
|
+
import java.lang.*;
|
|
36
|
+
import java.lang.Boolean;
|
|
37
|
+
import java.lang.Integer;
|
|
38
|
+
import java.lang.StackTraceElement;
|
|
39
|
+
import java.lang.StringBuffer;
|
|
40
|
+
import java.util.*;
|
|
41
|
+
import org.json.*;
|
|
42
|
+
|
|
43
|
+
public class Payload {
|
|
44
|
+
|
|
45
|
+
public static String playbackStateToString(int playbackState) {
|
|
46
|
+
String state = "UNKNOWN";
|
|
47
|
+
switch (playbackState) {
|
|
48
|
+
case Player.STATE_IDLE:
|
|
49
|
+
state = "STATE_IDLE";
|
|
50
|
+
break;
|
|
51
|
+
case Player.STATE_BUFFERING:
|
|
52
|
+
state = "STATE_BUFFERING";
|
|
53
|
+
break;
|
|
54
|
+
case Player.STATE_READY:
|
|
55
|
+
state = "STATE_READY";
|
|
56
|
+
break;
|
|
57
|
+
case Player.STATE_ENDED:
|
|
58
|
+
state = "STATE_ENDED";
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
return state;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public static JSONObject startEvent(ExoPlayer player, String audioFocus) {
|
|
65
|
+
Map<String, String> map = new HashMap<String, String>();
|
|
66
|
+
map.put("eventType", "START_EVENT");
|
|
67
|
+
map.put("audioFocus", audioFocus);
|
|
68
|
+
addPlayerState(map, player);
|
|
69
|
+
return new JSONObject(map);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public static JSONObject stopEvent(ExoPlayer player) {
|
|
73
|
+
Map<String, String> map = new HashMap<String, String>();
|
|
74
|
+
map.put("eventType", "STOP_EVENT");
|
|
75
|
+
return new JSONObject(map);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public static JSONObject keyEvent(KeyEvent event) {
|
|
79
|
+
int eventAction = event.getAction();
|
|
80
|
+
Map<String, String> map = new HashMap<String, String>();
|
|
81
|
+
map.put("eventType", "KEY_EVENT");
|
|
82
|
+
map.put("eventAction", eventAction == KeyEvent.ACTION_DOWN ? "ACTION_DOWN" : eventAction == KeyEvent.ACTION_UP ? "ACTION_UP" : "" + eventAction);
|
|
83
|
+
map.put("eventKeycode", KeyEvent.keyCodeToString(event.getKeyCode()));
|
|
84
|
+
return new JSONObject(map);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public static JSONObject touchEvent(MotionEvent event) {
|
|
88
|
+
int eventAction = event.getAction();
|
|
89
|
+
Map<String, String> map = new HashMap<String, String>();
|
|
90
|
+
map.put("eventType", "TOUCH_EVENT");
|
|
91
|
+
map.put("eventAction", eventAction == MotionEvent.ACTION_DOWN ? "ACTION_DOWN" : eventAction == MotionEvent.ACTION_UP ? "ACTION_UP" : eventAction == MotionEvent.ACTION_MOVE ? "ACTION_MOVE" : "" + eventAction);
|
|
92
|
+
map.put("eventAxisX", Float.toString(event.getX()));
|
|
93
|
+
map.put("eventAxisY", Float.toString(event.getY()));
|
|
94
|
+
return new JSONObject(map);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public static JSONObject loadingEvent(ExoPlayer player, boolean loading) {
|
|
98
|
+
Map<String, String> map = new HashMap<String, String>();
|
|
99
|
+
map.put("eventType", "LOADING_EVENT");
|
|
100
|
+
map.put("loading", Boolean.toString(loading));
|
|
101
|
+
addPlayerState(map, player);
|
|
102
|
+
return new JSONObject(map);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public static JSONObject stateEvent(ExoPlayer player, int playbackState, boolean controllerVisible) {
|
|
106
|
+
Map<String, String> map = new HashMap<String, String>();
|
|
107
|
+
map.put("eventType", "STATE_CHANGED_EVENT");
|
|
108
|
+
addPlayerState(map, player);
|
|
109
|
+
addTracksInfo(map, player);
|
|
110
|
+
map.put("playbackState", playbackStateToString(playbackState));
|
|
111
|
+
map.put("controllerVisible", Boolean.toString(controllerVisible));
|
|
112
|
+
|
|
113
|
+
return new JSONObject(map);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public static JSONObject positionDiscontinuityEvent(ExoPlayer player, int reason) {
|
|
117
|
+
Map<String, String> map = new HashMap<String, String>();
|
|
118
|
+
map.put("eventType", "POSITION_DISCONTINUITY_EVENT");
|
|
119
|
+
map.put("reason", Integer.toString(reason));
|
|
120
|
+
addPlayerState(map, player);
|
|
121
|
+
return new JSONObject(map);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public static JSONObject seekEvent(ExoPlayer player, long offset) {
|
|
125
|
+
Map<String, String> map = new HashMap<String, String>();
|
|
126
|
+
map.put("eventType", "SEEK_EVENT");
|
|
127
|
+
map.put("offset", Long.toString(offset));
|
|
128
|
+
addPlayerState(map, player);
|
|
129
|
+
return new JSONObject(map);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public static JSONObject timelineChangedEvent(ExoPlayer player, Timeline timeline) {
|
|
133
|
+
Map<String, String> map = new HashMap<String, String>();
|
|
134
|
+
map.put("eventType", "TIMELINE_EVENT");
|
|
135
|
+
int periodCount = timeline.getPeriodCount();
|
|
136
|
+
for (int i = 0; i < periodCount; i++) {
|
|
137
|
+
Timeline.Period period = new Timeline.Period();
|
|
138
|
+
timeline.getPeriod(i, period);
|
|
139
|
+
map.put("periodDuration" + i, Long.toString(period.getDurationMs()));
|
|
140
|
+
map.put("periodWindowPosition" + i, Long.toString(period.getPositionInWindowMs()));
|
|
141
|
+
}
|
|
142
|
+
int firstWindow = timeline.getFirstWindowIndex(false);
|
|
143
|
+
if (firstWindow > -1) {
|
|
144
|
+
Timeline.Window window = new Timeline.Window();
|
|
145
|
+
timeline.getWindow(firstWindow, window);
|
|
146
|
+
map.put("positionInFirstPeriod", Long.toString(window.getPositionInFirstPeriodMs()));
|
|
147
|
+
}
|
|
148
|
+
addPlayerState(map, player);
|
|
149
|
+
return new JSONObject(map);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public static JSONObject audioFocusEvent(ExoPlayer player, String state) {
|
|
153
|
+
Map<String, String> map = new HashMap<String, String>();
|
|
154
|
+
map.put("eventType", "AUDIO_FOCUS_EVENT");
|
|
155
|
+
map.put("audioFocus", state);
|
|
156
|
+
addPlayerState(map, player);
|
|
157
|
+
return new JSONObject(map);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public static JSONObject playerErrorEvent(ExoPlayer player, PlaybackException origin, String message) {
|
|
161
|
+
int type = 0;
|
|
162
|
+
Map<String, String> map = new HashMap<String, String>();
|
|
163
|
+
map.put("eventType", "PLAYER_ERROR_EVENT");
|
|
164
|
+
|
|
165
|
+
if (null != origin && origin instanceof ExoPlaybackException) {
|
|
166
|
+
Throwable error = (Throwable) origin;
|
|
167
|
+
ExoPlaybackException exoOrigin = (ExoPlaybackException) origin;
|
|
168
|
+
|
|
169
|
+
type = exoOrigin.type;
|
|
170
|
+
if (type == ExoPlaybackException.TYPE_RENDERER) {
|
|
171
|
+
error = exoOrigin.getRendererException();
|
|
172
|
+
map.put("errorType", "RENDERER");
|
|
173
|
+
}
|
|
174
|
+
else if (type == ExoPlaybackException.TYPE_SOURCE) {
|
|
175
|
+
error = exoOrigin.getSourceException();
|
|
176
|
+
map.put("errorType", "SOURCE");
|
|
177
|
+
}
|
|
178
|
+
else if (type == ExoPlaybackException.TYPE_UNEXPECTED) {
|
|
179
|
+
error = exoOrigin.getUnexpectedException();
|
|
180
|
+
map.put("errorType", "UNEXPECTED");
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
map.put("errorType", "UNKNOWN");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
while (null != error.getCause()) {
|
|
187
|
+
error = error.getCause();
|
|
188
|
+
}
|
|
189
|
+
error.fillInStackTrace();
|
|
190
|
+
StringBuffer stackTrace = new StringBuffer();
|
|
191
|
+
if (null != error) {
|
|
192
|
+
StackTraceElement[] st = error.getStackTrace();
|
|
193
|
+
if (null != st && st.length > 0) {
|
|
194
|
+
for (int i = 0; i < st.length; i++) {
|
|
195
|
+
StackTraceElement elem = st[i];
|
|
196
|
+
stackTrace.append(elem.getClassName() + "#" + elem.getMethodName() + "@" + elem.getLineNumber() + (elem.isNativeMethod() ? " NATIVE" : "")).append("\n");
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
map.put("stackTrace", stackTrace.toString());
|
|
201
|
+
map.put("errorMessage", error.getMessage());
|
|
202
|
+
}
|
|
203
|
+
if (null != message) {
|
|
204
|
+
map.put("customMessage", message);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return new JSONObject(map);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private static void addPlayerState(Map<String, String> map, ExoPlayer player) {
|
|
211
|
+
if (null != player) {
|
|
212
|
+
try {
|
|
213
|
+
map.put("duration", Long.toString(player.getDuration()));
|
|
214
|
+
map.put("position", Long.toString(player.getCurrentPosition()));
|
|
215
|
+
map.put("playWhenReady", Boolean.toString(player.getPlayWhenReady()));
|
|
216
|
+
map.put("playbackState", playbackStateToString(player.getPlaybackState()));
|
|
217
|
+
map.put("bufferPercentage", Integer.toString(player.getBufferedPercentage()));
|
|
218
|
+
map.put("videoWidth", Integer.toString(player.getVideoSize().width));
|
|
219
|
+
map.put("videoHeight", Integer.toString(player.getVideoSize().height));
|
|
220
|
+
}
|
|
221
|
+
catch(Exception ex) {
|
|
222
|
+
Log.e(Player.TAG, "Error adding player state", ex);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
public static JSONObject timeUpdateEvent(ExoPlayer player) {
|
|
229
|
+
Map<String, String> map = new HashMap<String, String>();
|
|
230
|
+
map.put("eventType", "TIMEUPDATE_EVENT");
|
|
231
|
+
map.put("message", "Timer running");
|
|
232
|
+
// map.put("playbackState", playbackStateToString(playbackState));
|
|
233
|
+
addPlayerState(map, player);
|
|
234
|
+
return new JSONObject(map);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
public static JSONObject tracksChangedEvent(ExoPlayer player, Tracks tracks) {
|
|
238
|
+
Map<String, String> map = new HashMap<String, String>();
|
|
239
|
+
map.put("eventType", "TRACKS_CHANGED_EVENT");
|
|
240
|
+
addTracksInfo(map, player);
|
|
241
|
+
return new JSONObject(map);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
public static void addTracksInfo(Map<String, String> map, ExoPlayer player) {
|
|
245
|
+
if (null != player && playbackStateToString(player.getPlaybackState()) == "STATE_READY") {
|
|
246
|
+
Tracks currentTracks = player.getCurrentTracks();
|
|
247
|
+
JSONObject result = new JSONObject();
|
|
248
|
+
JSONArray audioArray = new JSONArray();
|
|
249
|
+
JSONArray subtitleArray = new JSONArray();
|
|
250
|
+
|
|
251
|
+
if (currentTracks == null) {
|
|
252
|
+
try {
|
|
253
|
+
result.put("audioTracks", audioArray);
|
|
254
|
+
result.put("subtitleTracks", subtitleArray);
|
|
255
|
+
map.put("tracks", result.toString());
|
|
256
|
+
} catch (JSONException e) {
|
|
257
|
+
// e.printStackTrace();
|
|
258
|
+
Log.e(Player.TAG, "Error adding tracks info", e);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
for (Tracks.Group group : currentTracks.getGroups()) {
|
|
264
|
+
for (int i = 0; i < group.length; i++) {
|
|
265
|
+
Format format = group.getTrackFormat(i);
|
|
266
|
+
JSONObject trackObj = new JSONObject();
|
|
267
|
+
try {
|
|
268
|
+
trackObj.put("id", format.id != null ? format.id : JSONObject.NULL);
|
|
269
|
+
trackObj.put("language", format.language != null ? format.language : JSONObject.NULL);
|
|
270
|
+
trackObj.put("label", format.label != null ? format.label : JSONObject.NULL);
|
|
271
|
+
trackObj.put("bitrate", format.bitrate);
|
|
272
|
+
trackObj.put("codec", format.codecs);
|
|
273
|
+
trackObj.put("selected", format.selectionFlags);
|
|
274
|
+
trackObj.put("format", format.sampleMimeType);
|
|
275
|
+
} catch (JSONException e) {
|
|
276
|
+
// e.printStackTrace();
|
|
277
|
+
Log.e(Player.TAG, "Error adding trackObj info", e);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
switch (group.getType()) {
|
|
281
|
+
case C.TRACK_TYPE_AUDIO:
|
|
282
|
+
audioArray.put(trackObj);
|
|
283
|
+
break;
|
|
284
|
+
case C.TRACK_TYPE_TEXT:
|
|
285
|
+
if (format.sampleMimeType == "application/vobsub") {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (format.language == null) {
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
subtitleArray.put(trackObj);
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
try {
|
|
300
|
+
result.put("audioTracks", audioArray);
|
|
301
|
+
result.put("subtitleTracks", subtitleArray);
|
|
302
|
+
} catch (JSONException e) {
|
|
303
|
+
// e.printStackTrace();
|
|
304
|
+
Log.e(Player.TAG, "Error adding tracks info", e);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
map.put("tracks", result.toString());
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// public static JSONObject audioTrackeEvent(ExoPlayer player) {
|
|
313
|
+
// Map<String, String> map = new HashMap<String, String>();
|
|
314
|
+
// Tracks currentTracks = player.getCurrentTracks();
|
|
315
|
+
// JSONObject result = new JSONObject();
|
|
316
|
+
// JSONArray audioArray = new JSONArray();
|
|
317
|
+
// JSONArray subtitleArray = new JSONArray();
|
|
318
|
+
|
|
319
|
+
// if (currentTracks == null) return result;
|
|
320
|
+
|
|
321
|
+
// for (Tracks.Group group : currentTracks.getGroups()) {
|
|
322
|
+
// int trackType = group.getType();
|
|
323
|
+
|
|
324
|
+
// if (trackType == C.TRACK_TYPE_AUDIO) {
|
|
325
|
+
// for (int i = 0; i < group.length; i++) {
|
|
326
|
+
// Format format = group.getTrackFormat(i);
|
|
327
|
+
// Log.d("Tracks", "Audio: " + format.language + " | " + format.sampleRate + "Hz");
|
|
328
|
+
// map.put("Audios" + i, "Audio: " + format.language + " | " + format.sampleRate + "Hz");
|
|
329
|
+
// }
|
|
330
|
+
// }
|
|
331
|
+
|
|
332
|
+
// if (trackType == C.TRACK_TYPE_TEXT) {
|
|
333
|
+
// for (int i = 0; i < group.length; i++) {
|
|
334
|
+
// Format format = group.getTrackFormat(i);
|
|
335
|
+
// Log.d("Tracks", "Subtitle: " + format.language + " | " + format.sampleMimeType);
|
|
336
|
+
// map.put("Subtitles" + i, "Subtitle: " + format.language + " | " + format.sampleMimeType);
|
|
337
|
+
// }
|
|
338
|
+
// }
|
|
339
|
+
// }
|
|
340
|
+
// map.put("eventType", "AUDIO_TRACK_EVENT");
|
|
341
|
+
// // map.put("controllerVisible", Boolean.toString(controllerVisible));
|
|
342
|
+
// return new JSONObject(map);
|
|
343
|
+
// }
|
|
344
|
+
|
|
345
|
+
// // public static JSONObject resolutionEvent(ExoPlayer player, int videoWidth, int videoHeight) {
|
|
346
|
+
// Map<String, String> map = new HashMap<String, String>();
|
|
347
|
+
// map.put("eventType", "RESOLUTION_EVENT");
|
|
348
|
+
// map.put("width", Integer.toString(videoWidth));
|
|
349
|
+
// map.put("height", Integer.toString(videoHeight));
|
|
350
|
+
// return new JSONObject(map);
|
|
351
|
+
// }
|
|
352
|
+
|
|
353
|
+
// public static JSONObject videoSizeChangedEvent(ExoPlayer player, VideoSize videoSize) {
|
|
354
|
+
// Map<String, String> map = new HashMap<String, String>();
|
|
355
|
+
// map.put("eventType", "VIDEO_SIZE_CHANGED_EVENT");
|
|
356
|
+
// map.put("width", Integer.toString(videoSize.width));
|
|
357
|
+
// map.put("height", Integer.toString(videoSize.height));
|
|
358
|
+
// // addPlayerState(map, player);
|
|
359
|
+
// return new JSONObject(map);
|
|
360
|
+
// }
|
|
361
|
+
}
|