Skip to content

Commit

Permalink
Updates samples for IMA v3.26.0
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 421855927
  • Loading branch information
google-ima-devrel-bot authored and IMA Developer Relations committed Jan 14, 2022
1 parent fa9e491 commit afc2e28
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 43 deletions.
8 changes: 4 additions & 4 deletions AdvancedExample/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30
compileSdkVersion 31

// Java 11 required by Gradle 7.0.2
compileOptions {
Expand All @@ -12,7 +12,7 @@ android {
defaultConfig {
applicationId "com.google.ads.interactivemedia.v3.samples.videoplayerapp"
minSdkVersion 16
targetSdkVersion 30
targetSdkVersion 31
versionCode 1
versionName "1.0"
}
Expand All @@ -31,8 +31,8 @@ repositories {
}

dependencies {
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.25.1'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.26.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.mediarouter:mediarouter:1.2.5'
Expand Down
3 changes: 2 additions & 1 deletion AdvancedExample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<activity
android:name=".MyActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize">
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
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:7.0.3'
classpath 'com.android.tools.build:gradle:7.0.4'
}
}
12 changes: 6 additions & 6 deletions BasicExample/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30
compileSdkVersion 31

// Java 11 required by Gradle 7.0.2
compileOptions {
Expand All @@ -12,7 +12,7 @@ android {
defaultConfig {
applicationId "com.google.ads.interactivemedia.v3.samples.videoplayerapp"
minSdkVersion 16
targetSdkVersion 30
targetSdkVersion 31
multiDexEnabled true
versionCode 1
versionName "1.0"
Expand All @@ -32,10 +32,10 @@ repositories {

dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.exoplayer:exoplayer-core:2.15.1'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.15.1'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.exoplayer:exoplayer-core:2.16.1'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.16.1'

// The library adds the IMA ExoPlayer integration for ads.
implementation 'com.google.android.exoplayer:extension-ima:2.15.1'
implementation 'com.google.android.exoplayer:extension-ima:2.16.1'
}
3 changes: 2 additions & 1 deletion BasicExample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<activity
android:name=".MyActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize">
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
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:7.0.3'
classpath 'com.android.tools.build:gradle:7.0.4'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
14 changes: 7 additions & 7 deletions audioplayerexample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30
compileSdkVersion 31
compileOptions {
targetCompatibility JavaVersion.VERSION_11
}
defaultConfig {
applicationId "com.google.ads.interactivemedia.v3.samples.audioplayerexample.app"
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 31
versionCode 1
versionName "1.0"
}
Expand All @@ -40,12 +40,12 @@ repositories {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.media:media:1.4.3'
implementation 'com.google.android.exoplayer:exoplayer-core:2.15.1'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.15.1'
implementation 'com.google.android.exoplayer:extension-mediasession:2.15.1'
implementation 'com.google.android.exoplayer:exoplayer-core:2.16.1'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.16.1'
implementation 'com.google.android.exoplayer:extension-mediasession:2.16.1'
implementation 'com.google.guava:guava:28.1-android'

implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.25.1'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.26.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.analytics.AnalyticsListener;
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
import com.google.android.exoplayer2.ext.mediasession.TimelineQueueNavigator;
Expand All @@ -35,8 +34,7 @@
import com.google.android.exoplayer2.ui.PlayerNotificationManager.BitmapCallback;
import com.google.android.exoplayer2.ui.PlayerNotificationManager.MediaDescriptionAdapter;
import com.google.android.exoplayer2.ui.PlayerNotificationManager.NotificationListener;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.upstream.DefaultDataSource;
import com.google.common.collect.ImmutableList;

/**
Expand All @@ -46,7 +44,7 @@
public class AudioPlayerService extends Service {

private boolean isAdPlaying;
private SimpleExoPlayer player;
private ExoPlayer player;
private PlayerNotificationManager playerNotificationManager;
private MediaSessionCompat mediaSession;
private MediaSessionConnector mediaSessionConnector;
Expand All @@ -60,11 +58,9 @@ public void onCreate() {
final Context context = this;
isAdPlaying = false;

player = new SimpleExoPlayer.Builder(context).build();
player = new ExoPlayer.Builder(context).build();

DefaultDataSourceFactory dataSourceFactory =
new DefaultDataSourceFactory(
context, Util.getUserAgent(context, getString(R.string.application_name)));
DefaultDataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(context);

contentMediaSource =
new ConcatenatingMediaSource(
Expand All @@ -89,7 +85,7 @@ public String getCurrentContentTitle(Player player) {
if (isAdPlaying) {
return getString(R.string.ad_content_title);
}
return sampleList[player.getCurrentWindowIndex()].title;
return sampleList[player.getCurrentMediaItemIndex()].title;
}

@Nullable
Expand All @@ -105,7 +101,7 @@ public String getCurrentContentText(Player player) {
// Null will remove the extra line for description.
return null;
}
return sampleList[player.getCurrentWindowIndex()].description;
return sampleList[player.getCurrentMediaItemIndex()].description;
}

@Nullable
Expand All @@ -117,16 +113,16 @@ public Bitmap getCurrentLargeIcon(Player player, BitmapCallback callback) {
return null;
}
return Samples.getBitmap(
context, sampleList[player.getCurrentWindowIndex()].bitmapResource);
context, sampleList[player.getCurrentMediaItemIndex()].bitmapResource);
}
};

playerNotificationManager =
new PlayerNotificationManager.Builder(
context,
/* notificationId= */ PLAYBACK_NOTIFICATION_ID,
/* channelId= */ PLAYBACK_CHANNEL_ID,
descriptionAdapter)
/* channelId= */ PLAYBACK_CHANNEL_ID)
.setMediaDescriptionAdapter(descriptionAdapter)
.setChannelNameResourceId(R.string.playback_channel_name)
.setChannelDescriptionResourceId(R.string.playback_channel_description)
.setNotificationListener(
Expand Down Expand Up @@ -192,7 +188,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {

/**
* A limited API for the ImaService which provides a minimal surface of control over playback on
* the shared SimpleExoPlayer instance.
* the shared ExoPlayer instance.
*/
class SharedAudioPlayer {
public void claim() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.google.ads.interactivemedia.v3.samples.audioplayerexample;

import android.content.Context;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
Expand All @@ -25,7 +26,7 @@
import com.google.android.exoplayer2.analytics.AnalyticsListener;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultDataSource;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -48,13 +49,13 @@ public final class ImaService
private final List<VideoAdPlayerCallback> callbacks;
private final ImaSdkFactory sdkFactory;
private final ImaSdkSettings imaSdkSettings;
private final DefaultDataSourceFactory dataSourceFactory;
private final DefaultDataSource.Factory dataSourceFactory;

public ImaVideoAdPlayer imaVideoAdPlayer = new ImaVideoAdPlayer();

ImaService(
Context context,
DefaultDataSourceFactory dataSourceFactory,
DefaultDataSource.Factory dataSourceFactory,
AudioPlayerService.SharedAudioPlayer sharedAudioPlayer) {
this.context = context;
this.sharedAudioPlayer = sharedAudioPlayer;
Expand Down Expand Up @@ -154,9 +155,9 @@ public void playAd(AdMediaInfo adMediaInfo) {
for (VideoAdPlayerCallback callback : callbacks) {
callback.onPlay(adMediaInfo);
}
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(url)).build();
MediaSource mediaSource =
new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(MediaItem.fromUri(url));
new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItem);
sharedAudioPlayer.prepare(mediaSource);
}
exoPlayer.setPlayWhenReady(true);
Expand Down Expand Up @@ -210,10 +211,10 @@ void sendProgressUpdate() {

@Override
public int getVolume() {
if (exoPlayer.getAudioComponent() == null) {
if (exoPlayer == null) {
return -1;
} else {
return (int) (100 * exoPlayer.getAudioComponent().getVolume());
return (int) (100 * exoPlayer.getVolume());
}
}
}
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:7.0.3'
classpath 'com.android.tools.build:gradle:7.0.4'
}
}

0 comments on commit afc2e28

Please sign in to comment.