Skip to content

Commit

Permalink
Updates the samples for IMA v3.33.0.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 623923910
  • Loading branch information
google-ima-devrel-bot authored and IMA Developer Relations committed Apr 11, 2024
1 parent e76eca1 commit 2bf5fdc
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 36 deletions.
4 changes: 2 additions & 2 deletions AdvancedExample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.mediarouter:mediarouter:1.6.0'
implementation 'androidx.mediarouter:mediarouter:1.7.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.31.0'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.33.0'
}
2 changes: 1 addition & 1 deletion AdvancedExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.1.2'
classpath 'com.android.tools.build:gradle:8.3.2'
}
}
2 changes: 1 addition & 1 deletion AdvancedExample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip

2 changes: 1 addition & 1 deletion ExoPlayerExample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ repositories {
}

dependencies {
def media3_version = "1.1.1"
def media3_version = "1.3.1"
implementation "androidx.media3:media3-ui:$media3_version"
implementation "androidx.media3:media3-exoplayer:$media3_version"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.google.ads.interactivemedia.v3.samples.exoplayerexample;

import static android.os.Build.VERSION.SDK_INT;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.widget.TextView;
import androidx.media3.common.MediaItem;
import androidx.media3.common.util.Util;
import androidx.media3.datasource.DataSource;
import androidx.media3.datasource.DefaultDataSource;
import androidx.media3.exoplayer.ExoPlayer;
Expand All @@ -19,6 +21,8 @@
import com.google.ads.interactivemedia.v3.api.AdEvent;

/** Main Activity. */
@SuppressLint("UnsafeOptInUsageError")
/* @SuppressLint is needed for new media3 APIs. */
public class MyActivity extends Activity {

private static final String SAMPLE_VIDEO_URL =
Expand Down Expand Up @@ -72,7 +76,7 @@ public AdEvent.AdEventListener buildAdEventListener() {
@Override
public void onStart() {
super.onStart();
if (Util.SDK_INT > 23) {
if (SDK_INT > 23) {
initializePlayer();
if (playerView != null) {
playerView.onResume();
Expand All @@ -83,7 +87,7 @@ public void onStart() {
@Override
public void onResume() {
super.onResume();
if (Util.SDK_INT <= 23 || player == null) {
if (SDK_INT <= 23 || player == null) {
initializePlayer();
if (playerView != null) {
playerView.onResume();
Expand All @@ -94,7 +98,7 @@ public void onResume() {
@Override
public void onPause() {
super.onPause();
if (Util.SDK_INT <= 23) {
if (SDK_INT <= 23) {
if (playerView != null) {
playerView.onPause();
}
Expand All @@ -105,7 +109,7 @@ public void onPause() {
@Override
public void onStop() {
super.onStop();
if (Util.SDK_INT > 23) {
if (SDK_INT > 23) {
if (playerView != null) {
playerView.onPause();
}
Expand Down
2 changes: 1 addition & 1 deletion ExoPlayerExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.1.2'
classpath 'com.android.tools.build:gradle:8.3.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion ExoPlayerExample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
8 changes: 4 additions & 4 deletions audioplayerexample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
}
defaultConfig {
applicationId "com.google.ads.interactivemedia.v3.samples.audioplayerexample"
minSdkVersion 21
minSdkVersion 29
targetSdkVersion 34
versionCode 1
versionName "1.0"
Expand All @@ -43,12 +43,12 @@ repositories {
dependencies {
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.media:media:1.6.0'
def media3_version = "1.1.1"
implementation 'androidx.media:media:1.7.0'
def media3_version = "1.3.1"
implementation "androidx.media3:media3-ui:$media3_version"
implementation "androidx.media3:media3-exoplayer:$media3_version"
implementation "androidx.media3:media3-session:$media3_version"

implementation 'com.google.guava:guava:28.1-android'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.31.0'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.33.0'
}
4 changes: 3 additions & 1 deletion audioplayerexample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<!-- Required for background audio playback. -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/>

<!-- Required by ExoPlayer when targeting Android 13+ to be able to post notifications. -->
<!-- See https://github.com/google/ExoPlayer/issues/10884 for more info. -->
Expand All @@ -38,6 +39,7 @@
</intent-filter>
</activity>
<service android:name=".AudioPlayerService"
android:exported="false"/>
android:exported="false"
android:foregroundServiceType="mediaPlayback"/>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import static com.google.ads.interactivemedia.v3.samples.audioplayerexample.Constants.PLAYBACK_CHANNEL_ID;
import static com.google.ads.interactivemedia.v3.samples.audioplayerexample.Constants.PLAYBACK_NOTIFICATION_ID;

import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ServiceInfo;
import android.graphics.Bitmap;
import android.os.Binder;
import android.os.IBinder;
Expand Down Expand Up @@ -37,18 +39,20 @@
* Allows audio playback with hooks for advertisements. This is meant to run as a Foreground Service
* to enable playback to continue even if the app is minimized or cleaned up.
*/
@SuppressLint("UnsafeOptInUsageError")
/* @SuppressLint is needed for new media3 APIs. */
public class AudioPlayerService extends Service {

private boolean isAdPlaying;
private ExoPlayer player;
private PlayerNotificationManager playerNotificationManager;
private MediaSession mediaSession;
private ImaService imaService;
private PlayerNotificationManager playerNotificationManager;
private ConcatenatingMediaSource contentMediaSource;
private ImaService imaService;

private final Samples.Sample[] sampleList = Samples.getSamples();

@Override
@androidx.media3.common.util.UnstableApi
public void onCreate() {
super.onCreate();
final Context context = this;
Expand Down Expand Up @@ -127,7 +131,10 @@ public void onNotificationStarted(
int notificationId, Notification notification, boolean ongoing) {
// This must be called within 5 seconds of the notification being displayed and
// before the main app has been killed.
startForeground(notificationId, notification);
startForeground(
notificationId,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK);
}

@Override
Expand Down Expand Up @@ -176,7 +183,6 @@ public void claim() {
player.setPlayWhenReady(false);
}

@androidx.media3.common.util.UnstableApi
public void release() {
if (isAdPlaying) {
isAdPlaying = false;
Expand All @@ -187,7 +193,6 @@ public void release() {
}
}

@androidx.media3.common.util.UnstableApi
public void prepare(MediaSource mediaSource) {
player.setMediaSource(mediaSource);
player.prepare();
Expand Down
2 changes: 1 addition & 1 deletion audioplayerexample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.1.2'
classpath 'com.android.tools.build:gradle:8.3.2'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
6 changes: 3 additions & 3 deletions basicexample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ repositories {
dependencies {
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.browser:browser:1.6.0'
implementation 'androidx.media:media:1.6.0'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.31.0'
implementation 'androidx.browser:browser:1.8.0'
implementation 'androidx.media:media:1.7.0'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.33.0'
}
2 changes: 1 addition & 1 deletion basicexample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.1.2'
classpath 'com.android.tools.build:gradle:8.3.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion basicexample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
8 changes: 4 additions & 4 deletions umpexample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ repositories {
dependencies {
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.browser:browser:1.6.0'
implementation 'androidx.media:media:1.6.0'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.31.0'
implementation 'com.google.android.ump:user-messaging-platform:2.1.0'
implementation 'androidx.browser:browser:1.8.0'
implementation 'androidx.media:media:1.7.0'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.33.0'
implementation 'com.google.android.ump:user-messaging-platform:2.2.0'
}
2 changes: 1 addition & 1 deletion umpexample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.1.2'
classpath 'com.android.tools.build:gradle:8.3.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion umpexample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip

0 comments on commit 2bf5fdc

Please sign in to comment.