Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update custom looper to work on latest ios/xcode #3

Open
wants to merge 20 commits into
base: disable-ima-and-custom-looper-v4
Choose a base branch
from
Open
10 changes: 8 additions & 2 deletions Video.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const styles = StyleSheet.create({
},
});

const { VideoDecoderProperties } = NativeModules
export { TextTrackType, FilterType, DRMType, VideoDecoderProperties }
const { VideoDecoderProperties, VideoModule } = NativeModules;
export { TextTrackType, FilterType, DRMType, VideoDecoderProperties };

export default class Video extends Component {

Expand Down Expand Up @@ -77,6 +77,12 @@ export default class Video extends Component {
this.setNativeProps({ fullscreen: false });
};

forceRefreshPlayer = () => {
if (Platform.OS === 'android') {
VideoModule.forceRefreshPlayer();
}
}

save = async (options?) => {
return await NativeModules.VideoManager.save(options, findNodeHandle(this._root));
}
Expand Down
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ repositories {

dependencies {
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
implementation('com.google.android.exoplayer:exoplayer:2.18.6') {
implementation('com.google.android.exoplayer:exoplayer:2.19.1') {
exclude group: 'com.android.support'
}

Expand All @@ -67,12 +67,12 @@ dependencies {
implementation "androidx.media:media:1.1.0"
implementation "androidx.activity:activity:1.4.0"

implementation('com.google.android.exoplayer:extension-okhttp:2.18.6') {
implementation('com.google.android.exoplayer:extension-okhttp:2.19.1') {
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}

if (useExoplayerIMA) {
implementation 'com.google.android.exoplayer:extension-ima:2.18.6'
implementation 'com.google.android.exoplayer:extension-ima:2.19.1'
}
implementation "com.squareup.okhttp3:okhttp:" + '$OKHTTP_VERSION'
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
import java.lang.Integer;

@SuppressLint("ViewConstructor")
class ReactExoplayerView extends FrameLayout implements
public class ReactExoplayerView extends FrameLayout implements
LifecycleEventListener,
Player.Listener,
BandwidthMeter.EventListener,
Expand Down Expand Up @@ -342,6 +342,18 @@ public void cleanUpResources() {
stopPlayback();
}

public void forceRefreshPlayer() {
test();
}

private void test() {
isInBackground = true;
if (playInBackground) {
return;
}
setPlayWhenReady(false);
}

//BandwidthMeter.EventListener implementation
@Override
public void onBandwidthSample(int elapsedMs, long bytes, long bitrate) {
Expand Down Expand Up @@ -733,7 +745,7 @@ private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, S
return buildDrmSessionManager(uuid, licenseUrl, keyRequestPropertiesArray, 0);
}

private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, String[] keyRequestPropertiesArray, int retryCount) throws UnsupportedDrmException {
private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, String[] keyRequestPropertiesArray, int retryCount) {
if (Util.SDK_INT < 18) {
return null;
}
Expand All @@ -745,26 +757,22 @@ private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, S
drmCallback.setKeyRequestProperty(keyRequestPropertiesArray[i], keyRequestPropertiesArray[i + 1]);
}
}
FrameworkMediaDrm mediaDrm = FrameworkMediaDrm.newInstance(uuid);
if (hasDrmFailed) {
// When DRM fails using L1 we want to switch to L3
mediaDrm.setPropertyString("securityLevel", "L3");
}
return new DefaultDrmSessionManager(uuid, mediaDrm, drmCallback, null, false, 3);
} catch(UnsupportedDrmException ex) {
// Unsupported DRM exceptions are handled by the calling method
throw ex;

DrmSessionManagerProvider drmProvider = new DefaultDrmSessionManagerProvider();
return drmProvider.get(null); // Since we don't have MediaItem in this context, passing null. Adjust if necessary.

} catch (Exception ex) {
if (retryCount < 3) {
// Attempt retry 3 times in case where the OS Media DRM Framework fails for whatever reason
return buildDrmSessionManager(uuid, licenseUrl, keyRequestPropertiesArray, ++retryCount);
}
// Handle the unknow exception and emit to JS
// Handle the unknown exception and emit to JS
eventEmitter.error(ex.toString(), ex, "3006");
return null;
}
}


private MediaSource buildMediaSource(Uri uri, String overrideExtension, DrmSessionManager drmSessionManager) {
if (uri == null) {
throw new IllegalStateException("Invalid video uri");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.brentvatne.exoplayer;

import com.brentvatne.react.VideoModule;

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
Expand Down Expand Up @@ -96,7 +98,11 @@ public String getName() {

@Override
protected ReactExoplayerView createViewInstance(ThemedReactContext themedReactContext) {
return new ReactExoplayerView(themedReactContext, config);
ReactExoplayerView view = new ReactExoplayerView(themedReactContext, config);

VideoModule.setVideoView(view);

return view;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.util.Collections;
import java.util.List;
import java.util.ArrayList;

public class ReactVideoPackage implements ReactPackage {

Expand All @@ -25,9 +26,12 @@ public ReactVideoPackage(ReactExoplayerConfig config) {

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Collections.singletonList(
new VideoDecoderPropertiesModule(reactContext)
);
List<NativeModule> modules = new ArrayList<>();

modules.add(new VideoDecoderPropertiesModule(reactContext));
modules.add(new VideoModule(reactContext));

return modules;
}

// Deprecated RN 0.47
Expand Down
34 changes: 34 additions & 0 deletions android/src/main/java/com/brentvatne/react/VideoModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.brentvatne.react;

import com.brentvatne.exoplayer.ReactExoplayerView;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

public class VideoModule extends ReactContextBaseJavaModule {

private static ReactExoplayerView videoView;
private final ReactApplicationContext reactContext;

public static void setVideoView(ReactExoplayerView view) {
videoView = view;
}

public VideoModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}

@Override
public String getName() {
return "VideoModule";
}

@ReactMethod
public void forceRefreshPlayer() {
if (videoView != null) {
videoView.forceRefreshPlayer();
}
}
}
5 changes: 4 additions & 1 deletion ios/Video/RCTVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
}
}

// setUpPlayerItemIos10
func setUpPlayerItemIos10() {
if #available(iOS 10.0, *) {
guard
Expand Down Expand Up @@ -351,7 +352,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH

@objc
func setSrc(_ source:NSDictionary!) {
DispatchQueue.global(qos: .default).async {
let dispatchClosure = {
self._source = VideoSource(source)
if (self._source?.uri == nil || self._source?.uri == "") {
self._player?.replaceCurrentItem(with: nil)
Expand Down Expand Up @@ -438,6 +439,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
}.catch{_ in }
self._videoLoadStarted = true
}

DispatchQueue.global(qos: .default).async(execute: dispatchClosure)
}

@objc
Expand Down