Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -1,9 +1,35 @@
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
buildscript {
|
||||
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['RNSAC_kotlinVersion']
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
|
||||
}
|
||||
}
|
||||
|
||||
def safeExtGet(prop, fallback) {
|
||||
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
||||
}
|
||||
|
||||
def getExtOrDefault(name, defaultValue) {
|
||||
return rootProject.ext.has(name) ? rootProject.ext.get(name) : defaultValue
|
||||
}
|
||||
|
||||
def isNewArchitectureEnabled() {
|
||||
// To opt-in for the New Architecture, you can either:
|
||||
// - Set `newArchEnabled` to true inside the `gradle.properties` file
|
||||
// - Invoke gradle with `-newArchEnabled=true`
|
||||
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
|
||||
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
|
||||
}
|
||||
|
||||
def useExoplayerIMA = safeExtGet("RNVUseExoplayerIMA", false)
|
||||
|
||||
println "useExoplayerIMA:" + useExoplayerIMA
|
||||
@@ -16,6 +42,10 @@ def configStringPath = (
|
||||
'useExoplayerIMA' + useExoplayerIMA \
|
||||
).md5()
|
||||
|
||||
if (isNewArchitectureEnabled()) {
|
||||
apply plugin: "com.facebook.react"
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'com.brentvatne.react'
|
||||
compileSdkVersion safeExtGet('compileSdkVersion', 31)
|
||||
@@ -31,6 +61,15 @@ android {
|
||||
targetSdkVersion safeExtGet('targetSdkVersion', 28)
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
||||
|
||||
ndk {
|
||||
abiFilters(*reactNativeArchitectures())
|
||||
}
|
||||
}
|
||||
|
||||
packagingOptions {
|
||||
exclude "**/libreact_render*.so"
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
@@ -50,12 +89,39 @@ android {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets.main {
|
||||
java {
|
||||
if (isNewArchitectureEnabled()) {
|
||||
srcDirs += [
|
||||
"src/fabric/java",
|
||||
"${project.buildDir}/generated/source/codegen/java"
|
||||
]
|
||||
} else {
|
||||
srcDirs += [
|
||||
"src/oldarch/java"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def reactNativeArchitectures() {
|
||||
def value = project.getProperties().get("reactNativeArchitectures")
|
||||
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
||||
}
|
||||
|
||||
repositories {
|
||||
google()
|
||||
maven {
|
||||
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
|
||||
url "$rootDir/../node_modules/react-native/android"
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
def kotlin_version = getExtOrDefault('kotlinVersion', project.properties['RNSAC_kotlinVersion'])
|
||||
|
||||
dependencies {
|
||||
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
|
||||
implementation('com.google.android.exoplayer:exoplayer:2.18.1') {
|
||||
@@ -76,4 +142,5 @@ dependencies {
|
||||
implementation 'com.google.android.exoplayer:extension-ima:2.18.1'
|
||||
}
|
||||
implementation "com.squareup.okhttp3:okhttp:" + '$OKHTTP_VERSION'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
|
@@ -116,6 +116,10 @@ public final class ExoPlayerView extends FrameLayout implements AdViewProvider {
|
||||
subtitleLayout.setPadding(style.getPaddingLeft(), style.getPaddingTop(), style.getPaddingRight(), style.getPaddingBottom());
|
||||
}
|
||||
|
||||
public void setShutterColor(Integer color) {
|
||||
shutterView.setBackgroundColor(color);
|
||||
}
|
||||
|
||||
private void updateSurfaceView() {
|
||||
View view;
|
||||
if (!useTextureView || useSecureView) {
|
||||
|
@@ -120,7 +120,6 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
Player.Listener,
|
||||
BandwidthMeter.EventListener,
|
||||
BecomingNoisyListener,
|
||||
AudioManager.OnAudioFocusChangeListener,
|
||||
DrmSessionEventListener,
|
||||
AdEvent.AdEventListener {
|
||||
|
||||
@@ -244,6 +243,7 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
private final ThemedReactContext themedReactContext;
|
||||
private final AudioManager audioManager;
|
||||
private final AudioBecomingNoisyReceiver audioBecomingNoisyReceiver;
|
||||
private final AudioManager.OnAudioFocusChangeListener audioFocusChangeListener;
|
||||
|
||||
// store last progress event values to avoid sending unnecessary messages
|
||||
private long lastPos = -1;
|
||||
@@ -300,6 +300,7 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
themedReactContext.addLifecycleEventListener(this);
|
||||
audioBecomingNoisyReceiver = new AudioBecomingNoisyReceiver(themedReactContext);
|
||||
audioFocusChangeListener = new OnAudioFocusChangedListener(this);
|
||||
}
|
||||
|
||||
private boolean isPlayingAd() {
|
||||
@@ -951,11 +952,54 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
bandwidthMeter.removeEventListener(this);
|
||||
}
|
||||
|
||||
private static class OnAudioFocusChangedListener implements AudioManager.OnAudioFocusChangeListener {
|
||||
private final ReactExoplayerView view;
|
||||
|
||||
private OnAudioFocusChangedListener(ReactExoplayerView view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAudioFocusChange(int focusChange) {
|
||||
switch (focusChange) {
|
||||
case AudioManager.AUDIOFOCUS_LOSS:
|
||||
view.hasAudioFocus = false;
|
||||
view.eventEmitter.audioFocusChanged(false);
|
||||
view.pausePlayback();
|
||||
view.audioManager.abandonAudioFocus(this);
|
||||
break;
|
||||
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
|
||||
view.eventEmitter.audioFocusChanged(false);
|
||||
break;
|
||||
case AudioManager.AUDIOFOCUS_GAIN:
|
||||
view.hasAudioFocus = true;
|
||||
view.eventEmitter.audioFocusChanged(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (view.player != null) {
|
||||
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
|
||||
// Lower the volume
|
||||
if (!view.muted) {
|
||||
view.player.setVolume(view.audioVolume * 0.8f);
|
||||
}
|
||||
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
|
||||
// Raise it back to normal
|
||||
if (!view.muted) {
|
||||
view.player.setVolume(view.audioVolume * 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean requestAudioFocus() {
|
||||
if (disableFocus || srcUri == null || this.hasAudioFocus) {
|
||||
return true;
|
||||
}
|
||||
int result = audioManager.requestAudioFocus(this,
|
||||
int result = audioManager.requestAudioFocus(audioFocusChangeListener,
|
||||
AudioManager.STREAM_MUSIC,
|
||||
AudioManager.AUDIOFOCUS_GAIN);
|
||||
return result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
|
||||
@@ -1021,7 +1065,7 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
if (isFullscreen) {
|
||||
setFullscreen(false);
|
||||
}
|
||||
audioManager.abandonAudioFocus(this);
|
||||
audioManager.abandonAudioFocus(audioFocusChangeListener);
|
||||
}
|
||||
|
||||
private void updateResumePosition() {
|
||||
@@ -1061,43 +1105,6 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
useBandwidthMeter ? bandwidthMeter : null, requestHeaders);
|
||||
}
|
||||
|
||||
// AudioManager.OnAudioFocusChangeListener implementation
|
||||
|
||||
@Override
|
||||
public void onAudioFocusChange(int focusChange) {
|
||||
switch (focusChange) {
|
||||
case AudioManager.AUDIOFOCUS_LOSS:
|
||||
this.hasAudioFocus = false;
|
||||
eventEmitter.audioFocusChanged(false);
|
||||
pausePlayback();
|
||||
audioManager.abandonAudioFocus(this);
|
||||
break;
|
||||
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
|
||||
eventEmitter.audioFocusChanged(false);
|
||||
break;
|
||||
case AudioManager.AUDIOFOCUS_GAIN:
|
||||
this.hasAudioFocus = true;
|
||||
eventEmitter.audioFocusChanged(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
|
||||
// Lower the volume
|
||||
if (!muted) {
|
||||
player.setVolume(audioVolume * 0.8f);
|
||||
}
|
||||
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
|
||||
// Raise it back to normal
|
||||
if (!muted) {
|
||||
player.setVolume(audioVolume * 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AudioBecomingNoisyListener implementation
|
||||
|
||||
@Override
|
||||
@@ -2130,6 +2137,10 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
exoPlayerView.setSubtitleStyle(style);
|
||||
}
|
||||
|
||||
public void setShutterColor(Integer color) {
|
||||
exoPlayerView.setShutterColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdEvent(AdEvent adEvent) {
|
||||
eventEmitter.receiveAdEvent(adEvent.getType().name());
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package com.brentvatne.exoplayer;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.facebook.react.bridge.Dynamic;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
@@ -13,7 +13,6 @@ import com.facebook.react.common.MapBuilder;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
import com.facebook.react.uimanager.ViewGroupManager;
|
||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.google.android.exoplayer2.DefaultLoadControl;
|
||||
import com.google.android.exoplayer2.upstream.RawResourceDataSource;
|
||||
@@ -82,8 +81,8 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
||||
private static final String PROP_SELECTED_VIDEO_TRACK_VALUE = "value";
|
||||
private static final String PROP_HIDE_SHUTTER_VIEW = "hideShutterView";
|
||||
private static final String PROP_CONTROLS = "controls";
|
||||
|
||||
private static final String PROP_SUBTITLE_STYLE = "subtitleStyle";
|
||||
private static final String PROP_SHUTTER_COLOR = "shutterColor";
|
||||
|
||||
private ReactExoplayerConfig config;
|
||||
|
||||
@@ -387,6 +386,11 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
||||
videoView.setSubtitleStyle(SubtitleStyle.parse(src));
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_SHUTTER_COLOR, customType = "Color")
|
||||
public void setShutterColor(final ReactExoplayerView videoView, final Integer color) {
|
||||
videoView.setShutterColor(color == null ? Color.BLACK : color);
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_BUFFER_CONFIG)
|
||||
public void setBufferConfig(final ReactExoplayerView videoView, @Nullable ReadableMap bufferConfig) {
|
||||
int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS;
|
||||
|
Reference in New Issue
Block a user