Skip to content

Commit

Permalink
Merge branch 'master' into feat/rn-bump-up-fabric-example-android
Browse files Browse the repository at this point in the history
  • Loading branch information
yungblud committed Jul 1, 2024
2 parents 62ec8d7 + 3f11894 commit 64b4e5c
Show file tree
Hide file tree
Showing 65 changed files with 1,932 additions and 1,058 deletions.
85 changes: 65 additions & 20 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def ExoplayerDependenciesList = [
"useExoplayerHls",
"useExoplayerRtsp",
]
def media3_buildFromSource = safeExtGet('buildFromMedia3Source').toBoolean() ?: false

def ExoplayerDependencies = ExoplayerDependenciesList.collectEntries { property ->
[(property): safeExtGet(property)?.toBoolean() ?: false]
Expand All @@ -52,14 +53,17 @@ ExoplayerDependenciesList.each { propertyName ->
def propertyValue = ExoplayerDependencies[propertyName]
println "$propertyName: $propertyValue"
}
println "buildFromSource: $media3_buildFromSource"

// This string is used to define build path.
// As react native build output directory is react-native path of the module.
// We need to force a new path on each configuration change.
// If you add a new build parameter, please add the new value in this string
def configStringPath = ExoplayerDependencies.collect { property, value ->
property + value
}.join('').md5()
def configStringPath = ExoplayerDependencies
.collect { property, value -> property + value}
.join('')
.concat("buildFromSource:$media3_buildFromSource")
.md5()

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
Expand Down Expand Up @@ -189,46 +193,87 @@ dependencies {
implementation "androidx.activity:activity-ktx:$androidxActivity_version"

// For media playback using ExoPlayer
implementation "androidx.media3:media3-exoplayer:$media3_version"
if (media3_buildFromSource) {
implementation(project(":media-lib-exoplayer"))
} else {
implementation "androidx.media3:media3-exoplayer:$media3_version"
}

if (ExoplayerDependencies["useExoplayerSmoothStreaming"]) {
// For Smooth Streaming playback support with ExoPlayer
implementation "androidx.media3:media3-exoplayer-smoothstreaming:$media3_version"
if (media3_buildFromSource) {
implementation(project(":media-lib-exoplayer-smoothstreaming"))
} else {
implementation "androidx.media3:media3-exoplayer-smoothstreaming:$media3_version"
}
}

if (ExoplayerDependencies["useExoplayerDash"]) {
// For DASH playback support with ExoPlayer
implementation "androidx.media3:media3-exoplayer-dash:$media3_version"
if (media3_buildFromSource) {
implementation(project(":media-lib-exoplayer-dash"))
} else {
implementation "androidx.media3:media3-exoplayer-dash:$media3_version"
}
}

if (ExoplayerDependencies["useExoplayerHls"]) {
// For HLS playback support with ExoPlayer
implementation "androidx.media3:media3-exoplayer-hls:$media3_version"
// For HLS playback support with ExoPlayer
if (media3_buildFromSource) {
implementation(project(":media-lib-exoplayer-hls"))
} else {
implementation "androidx.media3:media3-exoplayer-hls:$media3_version"
}
}

// For RTSP playback support with ExoPlayer
if (ExoplayerDependencies["useExoplayerRtsp"]) {
implementation "androidx.media3:media3-exoplayer-rtsp:$media3_version"
if (media3_buildFromSource) {
implementation(project(":media-lib-exoplayer-rtsp"))
} else {
implementation "androidx.media3:media3-exoplayer-rtsp:$media3_version"
}
}

// For ad insertion using the Interactive Media Ads SDK with ExoPlayer
if (ExoplayerDependencies["useExoplayerIMA"]) {
implementation "androidx.media3:media3-exoplayer-ima:$media3_version"
if (media3_buildFromSource) {
implementation(project(":media-lib-exoplayer-ima"))
} else {
implementation "androidx.media3:media3-exoplayer-ima:$media3_version"
}
}

// For loading data using the OkHttp network stack
implementation "androidx.media3:media3-datasource-okhttp:$media3_version"
if (media3_buildFromSource) {
// For loading data using the OkHttp network stack
implementation(project(":media-lib-datasource-okhttp"))

// For building media playback UIs
implementation "androidx.media3:media3-ui:$media3_version"
// For building media playback UIs
implementation(project(":media-lib-ui"))

// For exposing and controlling media sessions
implementation "androidx.media3:media3-session:$media3_version"
// For exposing and controlling media sessions
implementation(project(":media-lib-session"))

// Common functionality for loading data
implementation "androidx.media3:media3-datasource:$media3_version"
// Common functionality used across multiple media libraries
implementation "androidx.media3:media3-common:$media3_version"
// Common functionality for loading data
implementation(project(":media-lib-datasource"))

// Common functionality used across multiple media libraries
implementation(project(":media-lib-common"))
} else {
// For loading data using the OkHttp network stack
implementation "androidx.media3:media3-datasource-okhttp:$media3_version"

// For building media playback UIs
implementation "androidx.media3:media3-ui:$media3_version"

// For exposing and controlling media sessions
implementation "androidx.media3:media3-session:$media3_version"

// Common functionality for loading data
implementation "androidx.media3:media3-datasource:$media3_version"

// Common functionality used across multiple media libraries
implementation "androidx.media3:media3-common:$media3_version"
}
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
1 change: 1 addition & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ RNVideo_useExoplayerDash=true
RNVideo_useExoplayerHls=true
RNVideo_androidxCoreVersion=1.9.0
RNVideo_androidxActivityVersion=1.7.0
RNVideo_buildFromMedia3Source=false
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,9 @@ public int[] getSupportedTypes() {
public MediaSource createMediaSource(MediaItem mediaItem) {
return null;
}

public Factory setAllowChunklessPreparation(boolean allowChunklessPreparation) {
return this;
}
}
}
19 changes: 19 additions & 0 deletions android/src/main/java/com/brentvatne/common/api/ViewType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.brentvatne.common.api

internal object ViewType {
/**
* View used will be a TextureView.
*/
const val VIEW_TYPE_TEXTURE = 0

/**
* View used will be a SurfaceView.
*/
const val VIEW_TYPE_SURFACE = 1

/**
* View used will be a SurfaceView with secure flag set.
*/
const val VIEW_TYPE_SURFACE_SECURE = 2
annotation class ViewType
}
65 changes: 30 additions & 35 deletions android/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@

import com.brentvatne.common.api.ResizeMode;
import com.brentvatne.common.api.SubtitleStyle;
import com.brentvatne.common.api.ViewType;
import com.brentvatne.common.toolbox.DebugLog;
import com.google.common.collect.ImmutableList;

import java.util.List;

public final class ExoPlayerView extends FrameLayout implements AdViewProvider {

private final static String TAG = "ExoPlayerView";
private View surfaceView;
private final View shutterView;
private final SubtitleView subtitleLayout;
Expand All @@ -42,8 +44,7 @@ public final class ExoPlayerView extends FrameLayout implements AdViewProvider {
private final ViewGroup.LayoutParams layoutParams;
private final FrameLayout adOverlayFrameLayout;

private boolean useTextureView = true;
private boolean useSecureView = false;
private @ViewType.ViewType int viewType = ViewType.VIEW_TYPE_SURFACE;
private boolean hideShutterView = false;

public ExoPlayerView(Context context) {
Expand Down Expand Up @@ -81,7 +82,7 @@ public ExoPlayerView(Context context, AttributeSet attrs, int defStyleAttr) {
subtitleLayout.setUserDefaultStyle();
subtitleLayout.setUserDefaultTextSize();

updateSurfaceView();
updateSurfaceView(viewType);

adOverlayFrameLayout = new FrameLayout(context);

Expand Down Expand Up @@ -134,28 +135,36 @@ public void setShutterColor(Integer color) {
shutterView.setBackgroundColor(color);
}

private void updateSurfaceView() {
View view;
if (!useTextureView || useSecureView) {
view = new SurfaceView(context);
if (useSecureView) {
((SurfaceView)view).setSecure(true);
public void updateSurfaceView(@ViewType.ViewType int viewType) {
this.viewType = viewType;
boolean viewNeedRefresh = false;
if (viewType == ViewType.VIEW_TYPE_SURFACE || viewType == ViewType.VIEW_TYPE_SURFACE_SECURE) {
if (!(surfaceView instanceof SurfaceView)) {
surfaceView = new SurfaceView(context);
viewNeedRefresh = true;
}
((SurfaceView)surfaceView).setSecure(viewType == ViewType.VIEW_TYPE_SURFACE_SECURE);
} else if (viewType == ViewType.VIEW_TYPE_TEXTURE) {
if (!(surfaceView instanceof TextureView)) {
surfaceView = new TextureView(context);
viewNeedRefresh = true;
}
} else {
view = new TextureView(context);
// Support opacity properly:
((TextureView) view).setOpaque(false);
((TextureView) surfaceView).setOpaque(false);
} else {
DebugLog.wtf(TAG, "wtf is this texture " + viewType);
}
view.setLayoutParams(layoutParams);
if (viewNeedRefresh) {
surfaceView.setLayoutParams(layoutParams);

surfaceView = view;
if (layout.getChildAt(0) != null) {
layout.removeViewAt(0);
}
layout.addView(surfaceView, 0, layoutParams);
if (layout.getChildAt(0) != null) {
layout.removeViewAt(0);
}
layout.addView(surfaceView, 0, layoutParams);

if (this.player != null) {
setVideoView();
if (this.player != null) {
setVideoView();
}
}
}

Expand Down Expand Up @@ -211,20 +220,6 @@ public void setResizeMode(@ResizeMode.Mode int resizeMode) {
}
}

public void setUseTextureView(boolean useTextureView) {
if (useTextureView != this.useTextureView) {
this.useTextureView = useTextureView;
updateSurfaceView();
}
}

public void useSecureView(boolean useSecureView) {
if (useSecureView != this.useSecureView) {
this.useSecureView = useSecureView;
updateSurfaceView();
}
}

public void setHideShutterView(boolean hideShutterView) {
this.hideShutterView = hideShutterView;
updateShutterViewVisibility();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
import com.brentvatne.common.toolbox.DebugLog;
import com.brentvatne.react.BuildConfig;
import com.brentvatne.react.R;
import com.brentvatne.react.ReactNativeVideoManager;
import com.brentvatne.receiver.AudioBecomingNoisyReceiver;
import com.brentvatne.receiver.BecomingNoisyListener;
import com.facebook.react.bridge.LifecycleEventListener;
Expand Down Expand Up @@ -258,6 +259,9 @@ public class ReactExoplayerView extends FrameLayout implements
private long lastDuration = -1;

private boolean viewHasDropped = false;

private String instanceId = String.valueOf(UUID.randomUUID());

private void updateProgress() {
if (player != null) {
if (playerControlView != null && isPlayingAd() && controls) {
Expand Down Expand Up @@ -585,6 +589,10 @@ private void refreshDebugState() {
}
}

public void setViewType(int viewType) {
exoPlayerView.updateSurfaceView(viewType);
}

private class RNVLoadControl extends DefaultLoadControl {
private final int availableHeapInBytes;
private final Runtime runtime;
Expand Down Expand Up @@ -756,6 +764,7 @@ private void initializePlayerCore(ReactExoplayerView self) {
.setLoadControl(loadControl)
.setMediaSourceFactory(mediaSourceFactory)
.build();
ReactNativeVideoManager.Companion.getInstance().onInstanceCreated(instanceId, player);
refreshDebugState();
player.addListener(self);
player.setVolume(muted ? 0.f : audioVolume * 1);
Expand Down Expand Up @@ -1150,6 +1159,7 @@ private void releasePlayer() {
player.removeListener(this);
trackSelector = null;

ReactNativeVideoManager.Companion.getInstance().onInstanceRemoved(instanceId, player);
player = null;
}

Expand Down Expand Up @@ -2237,15 +2247,6 @@ public void setFullscreen(boolean fullscreen) {
updateFullScreenButtonVisibility();
}

public void setUseTextureView(boolean useTextureView) {
boolean finallyUseTextureView = useTextureView && drmProps == null;
exoPlayerView.setUseTextureView(finallyUseTextureView);
}

public void useSecureView(boolean useSecureView) {
exoPlayerView.useSecureView(useSecureView);
}

public void setHideShutterView(boolean hideShutterView) {
exoPlayerView.setHideShutterView(hideShutterView);
}
Expand Down
Loading

0 comments on commit 64b4e5c

Please sign in to comment.