@jwplayer/jwplayer-react-native 1.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/.github/CODEOWNERS +2 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/ISSUE_TEMPLATE/question.md +11 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +15 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/LICENSE +21 -0
- package/README.md +425 -0
- package/RNJWPlayer.podspec +44 -0
- package/android/.gradle/8.1.1/checksums/checksums.lock +0 -0
- package/android/.gradle/8.1.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/8.1.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.1.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.1.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.1.1/gc.properties +0 -0
- package/android/.gradle/8.2/checksums/checksums.lock +0 -0
- package/android/.gradle/8.2/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/8.2/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.2/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.2/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/config.properties +2 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/gradle.xml +12 -0
- package/android/.idea/migrations.xml +10 -0
- package/android/.idea/misc.xml +10 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/.idea/workspace.xml +54 -0
- package/android/build.gradle +110 -0
- package/android/local.properties +8 -0
- package/android/src/main/AndroidManifest.xml +25 -0
- package/android/src/main/java/com/jwplayer/rnjwplayer/ArrayUtil.java +129 -0
- package/android/src/main/java/com/jwplayer/rnjwplayer/CastOptionsProvider.java +55 -0
- package/android/src/main/java/com/jwplayer/rnjwplayer/MapUtil.java +136 -0
- package/android/src/main/java/com/jwplayer/rnjwplayer/RNJWPlayer.java +76 -0
- package/android/src/main/java/com/jwplayer/rnjwplayer/RNJWPlayerAds.java +239 -0
- package/android/src/main/java/com/jwplayer/rnjwplayer/RNJWPlayerModule.java +526 -0
- package/android/src/main/java/com/jwplayer/rnjwplayer/RNJWPlayerPackage.java +30 -0
- package/android/src/main/java/com/jwplayer/rnjwplayer/RNJWPlayerView.java +1499 -0
- package/android/src/main/java/com/jwplayer/rnjwplayer/RNJWPlayerViewManager.java +171 -0
- package/android/src/main/java/com/jwplayer/rnjwplayer/Util.java +219 -0
- package/android/src/main/java/com/jwplayer/rnjwplayer/WidevineCallback.java +62 -0
- package/badges/license.svg +1 -0
- package/badges/version.svg +1 -0
- package/docs/legacy_readme.md +634 -0
- package/docs/props.md +43 -0
- package/docs/types.md +254 -0
- package/index.d.ts +564 -0
- package/index.js +699 -0
- package/ios/RNJWPlayer/RCTConvert+RNJWPlayer.swift +119 -0
- package/ios/RNJWPlayer/RNJWPlayer-Bridging-Header.h +5 -0
- package/ios/RNJWPlayer/RNJWPlayerAds.swift +260 -0
- package/ios/RNJWPlayer/RNJWPlayerModels.swift +149 -0
- package/ios/RNJWPlayer/RNJWPlayerView.swift +1837 -0
- package/ios/RNJWPlayer/RNJWPlayerViewController.swift +616 -0
- package/ios/RNJWPlayer/RNJWPlayerViewManager.m +132 -0
- package/ios/RNJWPlayer/RNJWPlayerViewManager.swift +500 -0
- package/ios/RNJWPlayer.xcodeproj/project.pbxproj +323 -0
- package/package.json +45 -0
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
|
|
2
|
+
package com.jwplayer.rnjwplayer;
|
|
3
|
+
|
|
4
|
+
import android.media.AudioManager;
|
|
5
|
+
|
|
6
|
+
import com.facebook.react.bridge.Arguments;
|
|
7
|
+
import com.facebook.react.bridge.Promise;
|
|
8
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
9
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
10
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
11
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
12
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
13
|
+
import com.facebook.react.bridge.WritableArray;
|
|
14
|
+
import com.facebook.react.bridge.WritableMap;
|
|
15
|
+
import com.facebook.react.uimanager.IllegalViewOperationException;
|
|
16
|
+
import com.facebook.react.uimanager.NativeViewHierarchyManager;
|
|
17
|
+
import com.facebook.react.uimanager.UIBlock;
|
|
18
|
+
import com.facebook.react.uimanager.UIManagerModule;
|
|
19
|
+
import com.jwplayer.pub.api.JWPlayer;
|
|
20
|
+
import com.jwplayer.pub.api.PlayerState;
|
|
21
|
+
import com.jwplayer.pub.api.media.adaptive.QualityLevel;
|
|
22
|
+
import com.jwplayer.pub.api.configuration.PlayerConfig;
|
|
23
|
+
import com.jwplayer.pub.api.media.audio.AudioTrack;
|
|
24
|
+
import com.jwplayer.pub.api.media.playlists.PlaylistItem;
|
|
25
|
+
|
|
26
|
+
import java.util.ArrayList;
|
|
27
|
+
import java.util.List;
|
|
28
|
+
|
|
29
|
+
public class RNJWPlayerModule extends ReactContextBaseJavaModule {
|
|
30
|
+
|
|
31
|
+
private final ReactApplicationContext mReactContext;
|
|
32
|
+
|
|
33
|
+
private static final String TAG = "RNJWPlayerModule";
|
|
34
|
+
|
|
35
|
+
public RNJWPlayerModule(ReactApplicationContext reactContext) {
|
|
36
|
+
super(reactContext);
|
|
37
|
+
|
|
38
|
+
mReactContext = reactContext;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Override
|
|
42
|
+
public String getName() {
|
|
43
|
+
return TAG;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@ReactMethod
|
|
47
|
+
public void loadPlaylist(final int reactTag, final ReadableArray playlistItems) {
|
|
48
|
+
try {
|
|
49
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
50
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
51
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
52
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
53
|
+
|
|
54
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
55
|
+
JWPlayer player = playerView.mPlayerView.getPlayer();
|
|
56
|
+
|
|
57
|
+
PlayerConfig oldConfig = player.getConfig();
|
|
58
|
+
PlayerConfig config = new PlayerConfig.Builder()
|
|
59
|
+
.autostart(oldConfig.getAutostart())
|
|
60
|
+
.nextUpOffset(oldConfig.getNextUpOffset())
|
|
61
|
+
.repeat(oldConfig.getRepeat())
|
|
62
|
+
.relatedConfig(oldConfig.getRelatedConfig())
|
|
63
|
+
.displayDescription(oldConfig.getDisplayDescription())
|
|
64
|
+
.displayTitle(oldConfig.getDisplayTitle())
|
|
65
|
+
.advertisingConfig(oldConfig.getAdvertisingConfig())
|
|
66
|
+
.stretching(oldConfig.getStretching())
|
|
67
|
+
.uiConfig(oldConfig.getUiConfig())
|
|
68
|
+
.playlist(Util.createPlaylist(playlistItems))
|
|
69
|
+
.allowCrossProtocolRedirects(oldConfig.getAllowCrossProtocolRedirects())
|
|
70
|
+
.preload(oldConfig.getPreload())
|
|
71
|
+
.useTextureView(oldConfig.useTextureView())
|
|
72
|
+
.thumbnailPreview(oldConfig.getThumbnailPreview())
|
|
73
|
+
.mute(oldConfig.getMute())
|
|
74
|
+
.build();
|
|
75
|
+
|
|
76
|
+
player.setup(config);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
} catch (IllegalViewOperationException e) {
|
|
81
|
+
throw e;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@ReactMethod
|
|
86
|
+
public void play(final int reactTag) {
|
|
87
|
+
try {
|
|
88
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
89
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
90
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
91
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
92
|
+
|
|
93
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
94
|
+
playerView.mPlayerView.getPlayer().play();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
} catch (IllegalViewOperationException e) {
|
|
99
|
+
throw e;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@ReactMethod
|
|
104
|
+
public void toggleSpeed(final int reactTag) {
|
|
105
|
+
try {
|
|
106
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
107
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
108
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
109
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
110
|
+
|
|
111
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
112
|
+
double rate = playerView.mPlayerView.getPlayer().getPlaybackRate();
|
|
113
|
+
if (rate < 2) {
|
|
114
|
+
playerView.mPlayerView.getPlayer().setPlaybackRate(rate += 0.5);
|
|
115
|
+
} else {
|
|
116
|
+
playerView.mPlayerView.getPlayer().setPlaybackRate((float) 0.5);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
} catch (IllegalViewOperationException e) {
|
|
122
|
+
throw e;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@ReactMethod
|
|
127
|
+
public void togglePIP(final int reactTag) {
|
|
128
|
+
try {
|
|
129
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
130
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
131
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
132
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
133
|
+
|
|
134
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
135
|
+
if (playerView.mPlayerView.getPlayer().isInPictureInPictureMode()) {
|
|
136
|
+
playerView.mPlayerView.getPlayer().exitPictureInPictureMode();
|
|
137
|
+
} else {
|
|
138
|
+
playerView.mPlayerView.getPlayer().enterPictureInPictureMode();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
} catch (IllegalViewOperationException e) {
|
|
144
|
+
throw e;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@ReactMethod
|
|
149
|
+
public void setSpeed(final int reactTag, final float speed) {
|
|
150
|
+
try {
|
|
151
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
152
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
153
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
154
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
155
|
+
|
|
156
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
157
|
+
playerView.mPlayerView.getPlayer().setPlaybackRate(speed);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
} catch (IllegalViewOperationException e) {
|
|
162
|
+
throw e;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@ReactMethod
|
|
168
|
+
public void getCurrentQuality(final int reactTag, final Promise promise) {
|
|
169
|
+
try {
|
|
170
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
171
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
172
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
173
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
174
|
+
|
|
175
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
176
|
+
int quality = playerView.mPlayerView.getPlayer().getCurrentQuality();
|
|
177
|
+
promise.resolve(quality);
|
|
178
|
+
} else {
|
|
179
|
+
promise.reject("RNJW Error", "getCurrentQuality() Player is null");
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
} catch (IllegalViewOperationException e) {
|
|
184
|
+
throw e;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
@ReactMethod
|
|
189
|
+
public void setCurrentQuality(final int reactTag, final int index) {
|
|
190
|
+
try {
|
|
191
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
192
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
193
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
194
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
195
|
+
|
|
196
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
197
|
+
playerView.mPlayerView.getPlayer().setCurrentQuality(index);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
} catch (IllegalViewOperationException e) {
|
|
202
|
+
throw e;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
@ReactMethod
|
|
208
|
+
public void getQualityLevels(final int reactTag, final Promise promise) {
|
|
209
|
+
try {
|
|
210
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
211
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
212
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
213
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
214
|
+
|
|
215
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
216
|
+
List<QualityLevel> qualityLevelsList = playerView.mPlayerView.getPlayer().getQualityLevels();
|
|
217
|
+
if (qualityLevelsList == null) { //if qualitylevels are null than pass empty array.
|
|
218
|
+
promise.resolve(null);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
WritableArray qualityLevels = Arguments.createArray();
|
|
222
|
+
for (int i = 0; i < qualityLevelsList.size(); i++) {
|
|
223
|
+
WritableMap qualityLevel = Arguments.createMap();
|
|
224
|
+
QualityLevel level = qualityLevelsList.get(i);
|
|
225
|
+
qualityLevel.putInt("playListPosition", level.getPlaylistPosition());
|
|
226
|
+
qualityLevel.putInt("bitRate", level.getBitrate());
|
|
227
|
+
qualityLevel.putString("label", level.getLabel());
|
|
228
|
+
qualityLevel.putInt("height", level.getHeight());
|
|
229
|
+
qualityLevel.putInt("width", level.getWidth());
|
|
230
|
+
qualityLevel.putInt("index", level.getTrackIndex());
|
|
231
|
+
qualityLevels.pushMap(qualityLevel);
|
|
232
|
+
}
|
|
233
|
+
promise.resolve(qualityLevels);
|
|
234
|
+
} else {
|
|
235
|
+
promise.reject("RNJW Error", "getQualityLevels() Player is null");
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
} catch (IllegalViewOperationException e) {
|
|
240
|
+
throw e;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
@ReactMethod
|
|
245
|
+
public void pause(final int reactTag) {
|
|
246
|
+
try {
|
|
247
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
248
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
249
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
250
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
251
|
+
|
|
252
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
253
|
+
playerView.mPlayerView.getPlayer().pause();
|
|
254
|
+
playerView.userPaused = true;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
} catch (IllegalViewOperationException e) {
|
|
259
|
+
throw e;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
@ReactMethod
|
|
264
|
+
public void stop(final int reactTag) {
|
|
265
|
+
try {
|
|
266
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
267
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
268
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
269
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
270
|
+
|
|
271
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
272
|
+
playerView.mPlayerView.getPlayer().stop();
|
|
273
|
+
playerView.userPaused = true;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
} catch (IllegalViewOperationException e) {
|
|
278
|
+
throw e;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
@ReactMethod
|
|
283
|
+
public void seekTo(final int reactTag, final double time) {
|
|
284
|
+
try {
|
|
285
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
286
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
287
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
288
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
289
|
+
|
|
290
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
291
|
+
playerView.mPlayerView.getPlayer().seek(time);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
} catch (IllegalViewOperationException e) {
|
|
296
|
+
throw e;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
@ReactMethod
|
|
301
|
+
public void setPlaylistIndex(final int reactTag, final int index) {
|
|
302
|
+
try {
|
|
303
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
304
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
305
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
306
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
307
|
+
|
|
308
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
309
|
+
playerView.mPlayerView.getPlayer().playlistItem(index);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
} catch (IllegalViewOperationException e) {
|
|
314
|
+
throw e;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
@ReactMethod
|
|
319
|
+
public void setControls(final int reactTag, final boolean show) {
|
|
320
|
+
try {
|
|
321
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
322
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
323
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
324
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
325
|
+
|
|
326
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
327
|
+
playerView.mPlayerView.getPlayer().setControls(show);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
} catch (IllegalViewOperationException e) {
|
|
332
|
+
throw e;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
@ReactMethod
|
|
337
|
+
public void position(final int reactTag, final Promise promise) {
|
|
338
|
+
try {
|
|
339
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
340
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
341
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
342
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
343
|
+
|
|
344
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
345
|
+
promise.resolve((Double.valueOf(playerView.mPlayerView.getPlayer().getPosition()).intValue()));
|
|
346
|
+
} else {
|
|
347
|
+
promise.reject("RNJW Error", "Player is null");
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
} catch (IllegalViewOperationException e) {
|
|
352
|
+
promise.reject("RNJW Error", e);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
@ReactMethod
|
|
357
|
+
public void state(final int reactTag, final Promise promise) {
|
|
358
|
+
try {
|
|
359
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
360
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
361
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
362
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
363
|
+
|
|
364
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
365
|
+
PlayerState playerState = playerView.mPlayerView.getPlayer().getState();
|
|
366
|
+
promise.resolve(stateToInt(playerState));
|
|
367
|
+
} else {
|
|
368
|
+
promise.reject("RNJW Error", "Player is null");
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
} catch (IllegalViewOperationException e) {
|
|
373
|
+
promise.reject("RNJW Error", e);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
@ReactMethod
|
|
378
|
+
public void setFullscreen(final int reactTag, final boolean fullscreen) {
|
|
379
|
+
try {
|
|
380
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
381
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
382
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
383
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
384
|
+
|
|
385
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
386
|
+
playerView.mPlayerView.getPlayer().setFullscreen(fullscreen, fullscreen);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
} catch (IllegalViewOperationException e) {
|
|
391
|
+
throw e;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
@ReactMethod
|
|
396
|
+
public void setVolume(final int reactTag, final int volume) {
|
|
397
|
+
try {
|
|
398
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
399
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
400
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
401
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
402
|
+
|
|
403
|
+
if (playerView != null && playerView.mPlayerView != null) {
|
|
404
|
+
int maxValue = playerView.audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
|
|
405
|
+
if (volume <= maxValue) {
|
|
406
|
+
playerView.audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
|
|
407
|
+
} else {
|
|
408
|
+
playerView.audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxValue, 0);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
} catch (IllegalViewOperationException e) {
|
|
414
|
+
throw e;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
@ReactMethod
|
|
419
|
+
public void getAudioTracks(final int reactTag, final Promise promise) {
|
|
420
|
+
try {
|
|
421
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
422
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
423
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
424
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
425
|
+
|
|
426
|
+
if (playerView != null && playerView.mPlayer != null) {
|
|
427
|
+
List<AudioTrack> audioTrackList = playerView.mPlayer.getAudioTracks();
|
|
428
|
+
WritableArray audioTracks = Arguments.createArray();
|
|
429
|
+
if (audioTrackList != null) {
|
|
430
|
+
for (int i = 0; i < audioTrackList.size(); i++) {
|
|
431
|
+
WritableMap audioTrack = Arguments.createMap();
|
|
432
|
+
AudioTrack track = audioTrackList.get(i);
|
|
433
|
+
audioTrack.putString("name", track.getName());
|
|
434
|
+
audioTrack.putString("language", track.getLanguage());
|
|
435
|
+
audioTrack.putString("groupId", track.getGroupId());
|
|
436
|
+
audioTrack.putBoolean("defaultTrack", track.isDefaultTrack());
|
|
437
|
+
audioTrack.putBoolean("autoSelect", track.isAutoSelect());
|
|
438
|
+
audioTracks.pushMap(audioTrack);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
promise.resolve(audioTracks);
|
|
442
|
+
} else {
|
|
443
|
+
promise.reject("RNJW Error", "Player is null");
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
} catch (IllegalViewOperationException e) {
|
|
448
|
+
promise.reject("RNJW Error", e);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
@ReactMethod
|
|
453
|
+
public void getCurrentAudioTrack(final int reactTag, final Promise promise) {
|
|
454
|
+
try {
|
|
455
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
456
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
457
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
458
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
459
|
+
|
|
460
|
+
if (playerView != null && playerView.mPlayer != null) {
|
|
461
|
+
promise.resolve(playerView.mPlayer.getCurrentAudioTrack());
|
|
462
|
+
} else {
|
|
463
|
+
promise.reject("RNJW Error", "Player is null");
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
} catch (IllegalViewOperationException e) {
|
|
468
|
+
promise.reject("RNJW Error", e);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
@ReactMethod
|
|
473
|
+
public void setCurrentAudioTrack(final int reactTag, final int index) {
|
|
474
|
+
try {
|
|
475
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
476
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
477
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
478
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
479
|
+
|
|
480
|
+
if (playerView != null && playerView.mPlayer != null) {
|
|
481
|
+
playerView.mPlayer.setCurrentAudioTrack(index);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
} catch (IllegalViewOperationException e) {
|
|
486
|
+
throw e;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
@ReactMethod
|
|
491
|
+
public void setCurrentCaptions(final int reactTag, final int index) {
|
|
492
|
+
try {
|
|
493
|
+
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
|
|
494
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
495
|
+
public void execute (NativeViewHierarchyManager nvhm) {
|
|
496
|
+
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);
|
|
497
|
+
|
|
498
|
+
if (playerView != null && playerView.mPlayer != null) {
|
|
499
|
+
playerView.mPlayer.setCurrentCaptions(index);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
} catch (IllegalViewOperationException e) {
|
|
504
|
+
throw e;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
private int stateToInt(PlayerState playerState) {
|
|
509
|
+
switch (playerState) {
|
|
510
|
+
case IDLE:
|
|
511
|
+
return 0;
|
|
512
|
+
case BUFFERING:
|
|
513
|
+
return 1;
|
|
514
|
+
case PLAYING:
|
|
515
|
+
return 2;
|
|
516
|
+
case PAUSED:
|
|
517
|
+
return 3;
|
|
518
|
+
case COMPLETE:
|
|
519
|
+
return 4;
|
|
520
|
+
case ERROR:
|
|
521
|
+
return 5;
|
|
522
|
+
default:
|
|
523
|
+
return -1;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
package com.jwplayer.rnjwplayer;
|
|
3
|
+
|
|
4
|
+
import com.facebook.react.ReactPackage;
|
|
5
|
+
import com.facebook.react.bridge.JavaScriptModule;
|
|
6
|
+
import com.facebook.react.bridge.NativeModule;
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
9
|
+
|
|
10
|
+
import java.util.Arrays;
|
|
11
|
+
import java.util.Collections;
|
|
12
|
+
import java.util.List;
|
|
13
|
+
|
|
14
|
+
public class RNJWPlayerPackage implements ReactPackage {
|
|
15
|
+
|
|
16
|
+
@Override
|
|
17
|
+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
18
|
+
return Arrays.<NativeModule>asList(new RNJWPlayerModule(reactContext));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Backwards compatability for RN < 0.47
|
|
22
|
+
public List<Class<? extends JavaScriptModule>> createJSModules() {
|
|
23
|
+
return Collections.emptyList();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Override
|
|
27
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
28
|
+
return Arrays.<ViewManager>asList(new RNJWPlayerViewManager(reactContext));
|
|
29
|
+
}
|
|
30
|
+
}
|