@capgo/capacitor-jw-player 0.0.5 → 0.0.13
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/README.md +19 -4
- package/android/src/main/java/ee/forgr/capacitor_jw_player/CastOptionsProvider.java +4 -9
- package/android/src/main/java/ee/forgr/capacitor_jw_player/JwPlayerPlugin.java +62 -59
- package/android/src/main/java/ee/forgr/capacitor_jw_player/PlayerActivity.java +65 -74
- package/dist/docs.json +6 -2
- package/dist/esm/definitions.d.ts +2 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.js.map +1 -1
- package/ios/Sources/JwPlayerPlugin/JwPlayer.swift +4 -4
- package/ios/Sources/JwPlayerPlugin/JwPlayerPlugin.swift +128 -132
- package/ios/Sources/JwPlayerPlugin/LinkedList.swift +28 -29
- package/ios/Sources/JwPlayerPlugin/VideosToPlay.swift +4 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,6 +27,21 @@ npm install @capgo/capacitor-jw-player
|
|
|
27
27
|
npx cap sync
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
## Android
|
|
31
|
+
|
|
32
|
+
Edit `build.gradle` in order for the plugin to work:
|
|
33
|
+
```gradle
|
|
34
|
+
allprojects {
|
|
35
|
+
repositories {
|
|
36
|
+
google()
|
|
37
|
+
mavenCentral()
|
|
38
|
+
maven {
|
|
39
|
+
url 'https://mvn.jwplayer.com/content/repositories/releases/'
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
30
45
|
## Usage Examples
|
|
31
46
|
|
|
32
47
|
### Basic Setup and Playback
|
|
@@ -217,14 +232,14 @@ Initialize the JW Player
|
|
|
217
232
|
### play(...)
|
|
218
233
|
|
|
219
234
|
```typescript
|
|
220
|
-
play(options: { mediaUrl: string; mediaType: 'video' | 'playlist'; }) => Promise<void>
|
|
235
|
+
play(options: { mediaUrl: string; mediaType: 'video' | 'playlist'; autostart?: boolean; }) => Promise<void>
|
|
221
236
|
```
|
|
222
237
|
|
|
223
238
|
Play a video
|
|
224
239
|
|
|
225
|
-
| Param | Type
|
|
226
|
-
| ------------- |
|
|
227
|
-
| **`options`** | <code>{ mediaUrl: string; mediaType: 'video' \| 'playlist'; }</code> | - The options for the JW Player |
|
|
240
|
+
| Param | Type | Description |
|
|
241
|
+
| ------------- | ----------------------------------------------------------------------------------------- | ------------------------------- |
|
|
242
|
+
| **`options`** | <code>{ mediaUrl: string; mediaType: 'video' \| 'playlist'; autostart?: boolean; }</code> | - The options for the JW Player |
|
|
228
243
|
|
|
229
244
|
--------------------
|
|
230
245
|
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
package ee.forgr.capacitor_jw_player;
|
|
2
2
|
|
|
3
3
|
import android.content.Context;
|
|
4
|
-
|
|
5
4
|
import androidx.annotation.NonNull;
|
|
6
|
-
|
|
7
5
|
import com.google.android.gms.cast.CastMediaControlIntent;
|
|
8
6
|
import com.google.android.gms.cast.LaunchOptions;
|
|
9
7
|
import com.google.android.gms.cast.framework.CastOptions;
|
|
10
8
|
import com.google.android.gms.cast.framework.OptionsProvider;
|
|
11
9
|
import com.google.android.gms.cast.framework.SessionProvider;
|
|
12
|
-
|
|
13
10
|
import java.util.List;
|
|
14
11
|
import java.util.Locale;
|
|
15
12
|
|
|
@@ -18,14 +15,12 @@ public class CastOptionsProvider implements OptionsProvider {
|
|
|
18
15
|
@NonNull
|
|
19
16
|
@Override
|
|
20
17
|
public CastOptions getCastOptions(@NonNull Context context) {
|
|
21
|
-
LaunchOptions launchOptions = new LaunchOptions.Builder()
|
|
22
|
-
.setLocale(Locale.US)
|
|
23
|
-
.build();
|
|
18
|
+
LaunchOptions launchOptions = new LaunchOptions.Builder().setLocale(Locale.US).build();
|
|
24
19
|
|
|
25
20
|
return new CastOptions.Builder()
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
.setReceiverApplicationId(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID)
|
|
22
|
+
.setLaunchOptions(launchOptions)
|
|
23
|
+
.build();
|
|
29
24
|
}
|
|
30
25
|
|
|
31
26
|
@Override
|
|
@@ -2,7 +2,6 @@ package ee.forgr.capacitor_jw_player;
|
|
|
2
2
|
|
|
3
3
|
import android.content.Intent;
|
|
4
4
|
import android.util.Log;
|
|
5
|
-
|
|
6
5
|
import com.getcapacitor.JSArray;
|
|
7
6
|
import com.getcapacitor.JSObject;
|
|
8
7
|
import com.getcapacitor.Plugin;
|
|
@@ -13,13 +12,12 @@ import com.google.android.gms.cast.framework.CastContext;
|
|
|
13
12
|
import com.jwplayer.pub.api.JWPlayer;
|
|
14
13
|
import com.jwplayer.pub.api.configuration.PlayerConfig;
|
|
15
14
|
import com.jwplayer.pub.api.license.LicenseUtil;
|
|
16
|
-
import com.jwplayer.pub.api.media.playlists.PlaylistItem;
|
|
17
15
|
import com.jwplayer.pub.api.media.audio.AudioTrack;
|
|
18
16
|
import com.jwplayer.pub.api.media.captions.Caption;
|
|
19
|
-
|
|
17
|
+
import com.jwplayer.pub.api.media.playlists.PlaylistItem;
|
|
20
18
|
import java.lang.ref.WeakReference;
|
|
21
|
-
import java.util.List;
|
|
22
19
|
import java.util.ArrayList;
|
|
20
|
+
import java.util.List;
|
|
23
21
|
|
|
24
22
|
@CapacitorPlugin(name = "JwPlayer")
|
|
25
23
|
public class JwPlayerPlugin extends Plugin {
|
|
@@ -55,6 +53,7 @@ public class JwPlayerPlugin extends Plugin {
|
|
|
55
53
|
public void play(PluginCall call) {
|
|
56
54
|
String mediaUrl = call.getString("mediaUrl");
|
|
57
55
|
String mediaType = call.getString("mediaType");
|
|
56
|
+
boolean autostart = Boolean.TRUE.equals(call.getBoolean("autostart", false));
|
|
58
57
|
|
|
59
58
|
if (mediaUrl == null || mediaUrl.isEmpty()) {
|
|
60
59
|
call.reject("mediaUrl is required for play");
|
|
@@ -70,10 +69,11 @@ public class JwPlayerPlugin extends Plugin {
|
|
|
70
69
|
Intent intent = new Intent(getContext(), PlayerActivity.class);
|
|
71
70
|
intent.putExtra(PlayerActivity.EXTRA_MEDIA_URL, mediaUrl);
|
|
72
71
|
intent.putExtra(PlayerActivity.EXTRA_MEDIA_TYPE, mediaType);
|
|
72
|
+
intent.putExtra(PlayerActivity.AUTOSTART, autostart);
|
|
73
73
|
getActivity().startActivity(intent);
|
|
74
74
|
|
|
75
75
|
// We resolve immediately, actual playback state comes via events
|
|
76
|
-
call.resolve();
|
|
76
|
+
call.resolve();
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
@PluginMethod
|
|
@@ -90,7 +90,7 @@ public class JwPlayerPlugin extends Plugin {
|
|
|
90
90
|
@PluginMethod
|
|
91
91
|
public void resume(PluginCall call) {
|
|
92
92
|
Log.d(TAG, "Resume called");
|
|
93
|
-
|
|
93
|
+
if (staticPlayerInstance != null) {
|
|
94
94
|
staticPlayerInstance.play();
|
|
95
95
|
call.resolve();
|
|
96
96
|
} else {
|
|
@@ -101,15 +101,15 @@ public class JwPlayerPlugin extends Plugin {
|
|
|
101
101
|
@PluginMethod
|
|
102
102
|
public void stop(PluginCall call) {
|
|
103
103
|
Log.d(TAG, "Stop called");
|
|
104
|
-
|
|
104
|
+
if (staticPlayerInstance != null) {
|
|
105
105
|
staticPlayerInstance.stop();
|
|
106
|
-
|
|
106
|
+
// Consider finishing PlayerActivity here? Maybe PlayerActivity should finish itself on stop.
|
|
107
107
|
call.resolve();
|
|
108
108
|
} else {
|
|
109
109
|
call.reject("Player not active");
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
|
|
112
|
+
|
|
113
113
|
@PluginMethod
|
|
114
114
|
public void seekTo(PluginCall call) {
|
|
115
115
|
Double time = call.getDouble("time");
|
|
@@ -117,14 +117,14 @@ public class JwPlayerPlugin extends Plugin {
|
|
|
117
117
|
call.reject("time parameter is required");
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
|
-
|
|
120
|
+
if (staticPlayerInstance != null) {
|
|
121
121
|
staticPlayerInstance.seek(time);
|
|
122
122
|
call.resolve();
|
|
123
123
|
} else {
|
|
124
124
|
call.reject("Player not active");
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
|
|
128
128
|
@PluginMethod
|
|
129
129
|
public void setVolume(PluginCall call) {
|
|
130
130
|
Double volume = call.getDouble("volume"); // JW Player Android uses 0-100
|
|
@@ -132,9 +132,9 @@ public class JwPlayerPlugin extends Plugin {
|
|
|
132
132
|
call.reject("volume parameter is required");
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
if (staticPlayerInstance != null) {
|
|
136
136
|
// Cast the result to int
|
|
137
|
-
staticPlayerInstance.setVolume((int) (volume.floatValue() * 100));
|
|
137
|
+
staticPlayerInstance.setVolume((int) (volume.floatValue() * 100));
|
|
138
138
|
call.resolve();
|
|
139
139
|
} else {
|
|
140
140
|
call.reject("Player not active");
|
|
@@ -148,15 +148,15 @@ public class JwPlayerPlugin extends Plugin {
|
|
|
148
148
|
call.reject("speed parameter is required");
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
151
|
-
|
|
151
|
+
if (staticPlayerInstance != null) {
|
|
152
152
|
staticPlayerInstance.setPlaybackRate(speed.floatValue());
|
|
153
153
|
call.resolve();
|
|
154
154
|
} else {
|
|
155
155
|
call.reject("Player not active");
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
|
|
159
|
+
@PluginMethod
|
|
160
160
|
public void getPosition(PluginCall call) {
|
|
161
161
|
if (staticPlayerInstance != null) {
|
|
162
162
|
JSObject ret = new JSObject();
|
|
@@ -179,7 +179,7 @@ public class JwPlayerPlugin extends Plugin {
|
|
|
179
179
|
call.reject("Player not active", "-1"); // Return -1 or similar on error
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
-
|
|
182
|
+
|
|
183
183
|
@PluginMethod
|
|
184
184
|
public void loadPlaylist(PluginCall call) {
|
|
185
185
|
String playlistUrl = call.getString("playlistUrl");
|
|
@@ -190,16 +190,14 @@ public class JwPlayerPlugin extends Plugin {
|
|
|
190
190
|
if (staticPlayerInstance != null) {
|
|
191
191
|
Log.d(TAG, "Loading playlist from URL: " + playlistUrl);
|
|
192
192
|
// Use PlayerConfig with a single playlist item URL
|
|
193
|
-
PlaylistItem playlistItem = new PlaylistItem.Builder()
|
|
194
|
-
.file(playlistUrl)
|
|
195
|
-
.build();
|
|
193
|
+
PlaylistItem playlistItem = new PlaylistItem.Builder().file(playlistUrl).build();
|
|
196
194
|
List<PlaylistItem> playlist = new ArrayList<>();
|
|
197
195
|
playlist.add(playlistItem);
|
|
198
196
|
PlayerConfig config = new PlayerConfig.Builder()
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
197
|
+
.playlist(playlist)
|
|
198
|
+
// Autostart false when just loading?
|
|
199
|
+
.autostart(false)
|
|
200
|
+
.build();
|
|
203
201
|
staticPlayerInstance.setup(config); // Use setup for subsequent loads
|
|
204
202
|
call.resolve();
|
|
205
203
|
} else {
|
|
@@ -231,7 +229,7 @@ public class JwPlayerPlugin extends Plugin {
|
|
|
231
229
|
if (!playlist.isEmpty()) {
|
|
232
230
|
Log.d(TAG, "Loading playlist with " + playlist.size() + " items");
|
|
233
231
|
// Use PlayerConfig for loading multiple items too
|
|
234
|
-
|
|
232
|
+
PlayerConfig config = new PlayerConfig.Builder()
|
|
235
233
|
.playlist(playlist)
|
|
236
234
|
.autostart(false) // Or true depending on desired behavior
|
|
237
235
|
.build();
|
|
@@ -389,7 +387,7 @@ public class JwPlayerPlugin extends Plugin {
|
|
|
389
387
|
}
|
|
390
388
|
}
|
|
391
389
|
|
|
392
|
-
// --- Static methods for PlayerActivity Communication ---
|
|
390
|
+
// --- Static methods for PlayerActivity Communication ---
|
|
393
391
|
|
|
394
392
|
public static void setStaticPlayerInstance(JWPlayer player) {
|
|
395
393
|
Log.d(TAG, "Setting static player instance: " + (player != null));
|
|
@@ -404,7 +402,7 @@ public class JwPlayerPlugin extends Plugin {
|
|
|
404
402
|
plugin.notifyListeners("playerDismissed", null);
|
|
405
403
|
}
|
|
406
404
|
}
|
|
407
|
-
|
|
405
|
+
|
|
408
406
|
public static void notifyPipChanged(boolean isInPip) {
|
|
409
407
|
JwPlayerPlugin plugin = staticPluginRef != null ? staticPluginRef.get() : null;
|
|
410
408
|
if (plugin != null) {
|
|
@@ -431,8 +429,8 @@ public class JwPlayerPlugin extends Plugin {
|
|
|
431
429
|
plugin.notifyListeners(type, data);
|
|
432
430
|
}
|
|
433
431
|
}
|
|
434
|
-
|
|
435
|
-
|
|
432
|
+
|
|
433
|
+
public static void notifyWarning(String type, String message) {
|
|
436
434
|
JwPlayerPlugin plugin = staticPluginRef != null ? staticPluginRef.get() : null;
|
|
437
435
|
if (plugin != null) {
|
|
438
436
|
JSObject data = new JSObject();
|
|
@@ -442,26 +440,26 @@ public class JwPlayerPlugin extends Plugin {
|
|
|
442
440
|
}
|
|
443
441
|
|
|
444
442
|
public static void notifyPlaylistItem(int index, PlaylistItem item) {
|
|
445
|
-
|
|
443
|
+
JwPlayerPlugin plugin = staticPluginRef != null ? staticPluginRef.get() : null;
|
|
446
444
|
if (plugin != null) {
|
|
447
445
|
JSObject data = new JSObject();
|
|
448
446
|
data.put("index", index);
|
|
449
447
|
if (item != null) {
|
|
450
|
-
|
|
451
|
-
|
|
448
|
+
data.put("title", item.getTitle());
|
|
449
|
+
// data.put("file", item.getFile()); // Be careful with accessing file directly
|
|
452
450
|
}
|
|
453
451
|
plugin.notifyListeners("playlistItem", data);
|
|
454
452
|
}
|
|
455
453
|
}
|
|
456
|
-
|
|
454
|
+
|
|
457
455
|
public static void notifyPlaylistComplete() {
|
|
458
456
|
JwPlayerPlugin plugin = staticPluginRef != null ? staticPluginRef.get() : null;
|
|
459
457
|
if (plugin != null) {
|
|
460
458
|
plugin.notifyListeners("complete", null); // Maybe playlistComplete event?
|
|
461
459
|
}
|
|
462
460
|
}
|
|
463
|
-
|
|
464
|
-
|
|
461
|
+
|
|
462
|
+
public static void notifyPause(String reason) {
|
|
465
463
|
JwPlayerPlugin plugin = staticPluginRef != null ? staticPluginRef.get() : null;
|
|
466
464
|
if (plugin != null) {
|
|
467
465
|
JSObject data = new JSObject();
|
|
@@ -469,62 +467,67 @@ public class JwPlayerPlugin extends Plugin {
|
|
|
469
467
|
plugin.notifyListeners("pause", data);
|
|
470
468
|
}
|
|
471
469
|
}
|
|
472
|
-
|
|
470
|
+
|
|
473
471
|
public static void notifyPlay(String reason) {
|
|
474
472
|
JwPlayerPlugin plugin = staticPluginRef != null ? staticPluginRef.get() : null;
|
|
475
473
|
if (plugin != null) {
|
|
476
474
|
JSObject data = new JSObject();
|
|
477
|
-
|
|
475
|
+
data.put("reason", reason); // Android uses enum names
|
|
478
476
|
plugin.notifyListeners("play", data);
|
|
479
477
|
}
|
|
480
478
|
}
|
|
481
|
-
|
|
482
|
-
|
|
479
|
+
|
|
480
|
+
public static void notifyComplete() {
|
|
483
481
|
JwPlayerPlugin plugin = staticPluginRef != null ? staticPluginRef.get() : null;
|
|
484
482
|
if (plugin != null) {
|
|
485
483
|
plugin.notifyListeners("complete", null);
|
|
486
484
|
}
|
|
487
485
|
}
|
|
488
|
-
|
|
489
|
-
|
|
486
|
+
|
|
487
|
+
public static void notifySeek(double position, double offset) {
|
|
490
488
|
JwPlayerPlugin plugin = staticPluginRef != null ? staticPluginRef.get() : null;
|
|
491
489
|
if (plugin != null) {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
490
|
+
JSObject data = new JSObject();
|
|
491
|
+
data.put("position", position);
|
|
492
|
+
data.put("offset", offset);
|
|
495
493
|
plugin.notifyListeners("seek", data);
|
|
496
494
|
}
|
|
497
495
|
}
|
|
498
|
-
|
|
499
|
-
|
|
496
|
+
|
|
497
|
+
public static void notifySeeked() {
|
|
500
498
|
JwPlayerPlugin plugin = staticPluginRef != null ? staticPluginRef.get() : null;
|
|
501
499
|
if (plugin != null) {
|
|
502
500
|
plugin.notifyListeners("seeked", null);
|
|
503
501
|
}
|
|
504
502
|
}
|
|
505
|
-
|
|
506
|
-
|
|
503
|
+
|
|
504
|
+
public static void notifyTime(double position, double duration) {
|
|
507
505
|
JwPlayerPlugin plugin = staticPluginRef != null ? staticPluginRef.get() : null;
|
|
508
506
|
if (plugin != null) {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
507
|
+
JSObject data = new JSObject();
|
|
508
|
+
data.put("position", position);
|
|
509
|
+
data.put("duration", duration);
|
|
512
510
|
plugin.notifyListeners("time", data);
|
|
513
511
|
}
|
|
514
512
|
}
|
|
515
|
-
|
|
513
|
+
|
|
516
514
|
// Helper to map Android state enum to iOS-like integers
|
|
517
515
|
private int mapPlayerStateToInt(com.jwplayer.pub.api.PlayerState state) {
|
|
518
516
|
switch (state) {
|
|
519
|
-
case IDLE:
|
|
520
|
-
|
|
521
|
-
case
|
|
522
|
-
|
|
523
|
-
case
|
|
524
|
-
|
|
517
|
+
case IDLE:
|
|
518
|
+
return 0;
|
|
519
|
+
case BUFFERING:
|
|
520
|
+
return 1;
|
|
521
|
+
case PLAYING:
|
|
522
|
+
return 2;
|
|
523
|
+
case PAUSED:
|
|
524
|
+
return 3;
|
|
525
|
+
case COMPLETE:
|
|
526
|
+
return 4;
|
|
527
|
+
default:
|
|
528
|
+
return -1; // Unknown
|
|
525
529
|
}
|
|
526
530
|
}
|
|
527
|
-
|
|
528
531
|
// TODO: Implement other methods like loadPlaylist, getAudioTracks, setAudioTrack, getCaptions, setCaptions etc.
|
|
529
532
|
// These will require more complex communication with the PlayerActivity or direct player interaction.
|
|
530
533
|
}
|