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