fix(android): ads build and enable ads in android sample (#3376)
* fix: refactor androidx core version management * chore: fix missing import rework for media3 * fix: enable IMA in sample * chore: rename stub fie * chore: code review, fix variable name * chore: reorder imports * chore: fix linking in sample * chore: fix stub management * chore: few cleans and ensure we don't use ima is disabled --------- Co-authored-by: olivier <olivier.bouillet@ifeelsmart.com>
This commit is contained in:
parent
2648502b36
commit
fe89122524
@ -105,7 +105,7 @@ android {
|
||||
java {
|
||||
if (useExoplayerIMA) {
|
||||
exclude 'com/google/ads/interactivemedia/v3/api'
|
||||
exclude 'com/google/android/exoplayer2/ext/ima'
|
||||
exclude 'androidx/media3/exoplayer/ima'
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -143,6 +143,7 @@ repositories {
|
||||
|
||||
def media3_version = safeExtGet('media3Version')
|
||||
def kotlin_version = safeExtGet('kotlinVersion')
|
||||
def androidxCode_version = safeExtGet('androidxCoreVersion')
|
||||
|
||||
dependencies {
|
||||
// For < 0.71, this will be from the local maven repo
|
||||
@ -150,7 +151,7 @@ dependencies {
|
||||
//noinspection GradleDynamicVersion
|
||||
implementation "com.facebook.react:react-native:+"
|
||||
|
||||
implementation "androidx.core:core:1.9.0"
|
||||
implementation "androidx.core:core:$androidxCode_version"
|
||||
|
||||
// For media playback using ExoPlayer
|
||||
implementation "androidx.media3:media3-exoplayer:$media3_version"
|
||||
|
@ -5,4 +5,5 @@ RNVideo_compileSdkVersion=31
|
||||
RNVideo_ndkversion=21.4.7075529
|
||||
RNVideo_buildToolsVersion=30.0.2
|
||||
RNVideo_media3Version=1.1.1
|
||||
RNVideo_RNVUseExoplayerIMA=false
|
||||
RNVideo_RNVUseExoplayerIMA=false
|
||||
RNVideo_androidxCoreVersion=1.9.0
|
||||
|
@ -0,0 +1,61 @@
|
||||
package androidx.media3.exoplayer.ima;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.AdViewProvider;
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.media3.datasource.DataSpec;
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
import androidx.media3.exoplayer.source.ads.AdsLoader;
|
||||
import androidx.media3.exoplayer.source.ads.AdsMediaSource;
|
||||
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ImaAdsLoader implements AdsLoader {
|
||||
public void setPlayer(ExoPlayer ignoredPlayer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayer(@Nullable Player player) {
|
||||
}
|
||||
|
||||
public void release() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSupportedContentTypes(@NonNull int... ints) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(@NonNull AdsMediaSource adsMediaSource, @NonNull DataSpec dataSpec, @NonNull Object adsId, @NonNull AdViewProvider adViewProvider, @NonNull EventListener eventListener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(@NonNull AdsMediaSource adsMediaSource, @NonNull EventListener eventListener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePrepareComplete(@NonNull AdsMediaSource adsMediaSource, int i, int i1) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePrepareError(@NonNull AdsMediaSource adsMediaSource, int i, int i1, @NonNull IOException e) {
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
public Builder(Context ignoredThemedReactContext) {
|
||||
}
|
||||
|
||||
public Builder setAdEventListener(Object ignoredReactExoplayerView) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImaAdsLoader build() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -61,6 +61,7 @@ import androidx.media3.exoplayer.drm.FrameworkMediaDrm;
|
||||
import androidx.media3.exoplayer.drm.HttpMediaDrmCallback;
|
||||
import androidx.media3.exoplayer.drm.UnsupportedDrmException;
|
||||
import androidx.media3.exoplayer.hls.HlsMediaSource;
|
||||
import androidx.media3.exoplayer.ima.ImaAdsLoader;
|
||||
import androidx.media3.exoplayer.mediacodec.MediaCodecInfo;
|
||||
import androidx.media3.exoplayer.mediacodec.MediaCodecUtil;
|
||||
import androidx.media3.exoplayer.smoothstreaming.DefaultSsChunkSource;
|
||||
@ -103,7 +104,6 @@ import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
import com.google.ads.interactivemedia.v3.api.AdEvent;
|
||||
import com.google.android.exoplayer2.ext.ima.ImaAdsLoader;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.net.CookieHandler;
|
||||
@ -617,10 +617,14 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF);
|
||||
|
||||
// Create an AdsLoader.
|
||||
adsLoader = new ImaAdsLoader.Builder(themedReactContext).setAdEventListener(this).build();
|
||||
adsLoader = new ImaAdsLoader.Builder(themedReactContext)
|
||||
.setAdEventListener(this)
|
||||
.build();
|
||||
|
||||
MediaSource.Factory mediaSourceFactory = new DefaultMediaSourceFactory(mediaDataSourceFactory)
|
||||
.setLocalAdInsertionComponents(unusedAdTagUri -> adsLoader, exoPlayerView);
|
||||
DefaultMediaSourceFactory mediaSourceFactory = new DefaultMediaSourceFactory(mediaDataSourceFactory);
|
||||
if (adsLoader != null) {
|
||||
mediaSourceFactory.setLocalAdInsertionComponents(unusedAdTagUri -> adsLoader, exoPlayerView);
|
||||
}
|
||||
|
||||
player = new ExoPlayer.Builder(getContext(), renderersFactory)
|
||||
.setTrackSelector(self.trackSelector)
|
||||
@ -665,8 +669,8 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
ArrayList<MediaSource> mediaSourceList = buildTextSources();
|
||||
MediaSource videoSource = buildMediaSource(self.srcUri, self.extension, drmSessionManager, cropStartMs, cropEndMs);
|
||||
MediaSource mediaSourceWithAds = null;
|
||||
if (adTagUrl != null) {
|
||||
MediaSource.Factory mediaSourceFactory = new DefaultMediaSourceFactory(mediaDataSourceFactory)
|
||||
if (adTagUrl != null && adsLoader != null) {
|
||||
DefaultMediaSourceFactory mediaSourceFactory = new DefaultMediaSourceFactory(mediaDataSourceFactory)
|
||||
.setLocalAdInsertionComponents(unusedAdTagUri -> adsLoader, exoPlayerView);
|
||||
DataSpec adTagDataSpec = new DataSpec(adTagUrl);
|
||||
mediaSourceWithAds = new AdsMediaSource(videoSource, adTagDataSpec, ImmutableList.of(srcUri, adTagUrl), mediaSourceFactory, adsLoader, exoPlayerView);
|
||||
|
@ -1,65 +0,0 @@
|
||||
package com.google.android.exoplayer2.ext.ima;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.AdViewProvider;
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.media3.datasource.DataSpec;
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
import androidx.media3.exoplayer.source.ads.AdsLoader;
|
||||
import androidx.media3.exoplayer.source.ads.AdsMediaSource;
|
||||
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ImaAdsLoader implements AdsLoader {
|
||||
public void setPlayer(ExoPlayer player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayer(@Nullable Player player) {
|
||||
|
||||
}
|
||||
|
||||
public void release() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSupportedContentTypes(int... ints) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(AdsMediaSource adsMediaSource, DataSpec dataSpec, Object adsId, AdViewProvider adViewProvider, EventListener eventListener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(AdsMediaSource adsMediaSource, EventListener eventListener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePrepareComplete(AdsMediaSource adsMediaSource, int i, int i1) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePrepareError(AdsMediaSource adsMediaSource, int i, int i1, IOException e) {
|
||||
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
public Builder(ThemedReactContext themedReactContext) {
|
||||
|
||||
}
|
||||
|
||||
public Builder setAdEventListener(Object reactExoplayerView) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImaAdsLoader build() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -101,8 +101,12 @@ android {
|
||||
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
|
||||
}
|
||||
}
|
||||
configurations.all {
|
||||
resolutionStrategy { force 'androidx.core:core:1.9.0' }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
// The version of react-native is set by the React Native Gradle Plugin
|
||||
implementation("com.facebook.react:react-android")
|
||||
@ -120,6 +124,15 @@ dependencies {
|
||||
}
|
||||
|
||||
implementation project(':react-native-video')
|
||||
|
||||
constraints {
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
|
||||
because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
|
||||
}
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
|
||||
because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
|
||||
|
@ -30,7 +30,7 @@ public class MainApplication extends Application implements ReactApplication {
|
||||
@SuppressWarnings("UnnecessaryLocalVariable")
|
||||
List<ReactPackage> packages = new PackageList(this).getPackages();
|
||||
// Packages that cannot be autolinked yet can be added manually here, for example:
|
||||
// packages.add(new MyReactNativePackage());
|
||||
packages.add(new ReactVideoPackage());
|
||||
return packages;
|
||||
}
|
||||
|
||||
|
@ -6,10 +6,12 @@ buildscript {
|
||||
minSdkVersion = 21
|
||||
compileSdkVersion = 33
|
||||
targetSdkVersion = 33
|
||||
kotlinVersion = "1.6.20"
|
||||
kotlinVersion = "1.8.0"
|
||||
|
||||
// We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
|
||||
ndkVersion = "23.1.7779620"
|
||||
|
||||
RNVUseExoplayerIMA = true
|
||||
}
|
||||
repositories {
|
||||
google()
|
||||
|
@ -14,7 +14,6 @@
|
||||
"@react-native-picker/picker": "^1.9.11",
|
||||
"react": "18.2.0",
|
||||
"react-native": "0.72.5",
|
||||
"react-native-video": "../../",
|
||||
"react-native-windows": "0.63.41"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -715,7 +715,7 @@ class VideoPlayer extends Component {
|
||||
this.video = ref;
|
||||
}}
|
||||
source={this.srcList[this.state.srcListId]}
|
||||
//adTagUrl={this.srcList[this.state.srcListId]?.adTagUrl}
|
||||
adTagUrl={this.srcList[this.state.srcListId]?.adTagUrl}
|
||||
style={viewStyle}
|
||||
rate={this.state.rate}
|
||||
paused={this.state.paused}
|
||||
|
@ -6129,9 +6129,6 @@ react-is@^17.0.1:
|
||||
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
|
||||
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
|
||||
|
||||
react-native-video@../../:
|
||||
version "6.0.0-beta.0"
|
||||
|
||||
react-native-windows@0.63.41:
|
||||
version "0.63.41"
|
||||
resolved "https://registry.yarnpkg.com/react-native-windows/-/react-native-windows-0.63.41.tgz#96f59bc24749b6c167cb4f35fd74b66f78f4a4bb"
|
||||
|
Loading…
Reference in New Issue
Block a user