Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -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