Skip to content

Commit

Permalink
Updates samples to v3.34.0.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 650622337
  • Loading branch information
google-ima-devrel-bot authored and IMA Developer Relations committed Jul 9, 2024
1 parent ca94fea commit d67b737
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 46 deletions.
6 changes: 3 additions & 3 deletions AdvancedExample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {

defaultConfig {
applicationId "com.google.ads.interactivemedia.v3.samples.videoplayerapp"
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 34
multiDexEnabled true
versionCode 1
Expand All @@ -35,10 +35,10 @@ repositories {
dependencies {
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.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.33.0'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.34.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ public void onAdEvent(AdEvent adEvent) {
AdsRenderingSettings adsRenderingSettings =
ImaSdkFactory.getInstance().createAdsRenderingSettings();
adsRenderingSettings.setPlayAdsAfterTime(playAdsAfterTime);
// Add any ads rendering settings here.
// This init() only loads the UI rendering settings locally.
adsManager.init(adsRenderingSettings);
seek(playAdsAfterTime);
videoStarted = true;
Expand Down
3 changes: 1 addition & 2 deletions AdvancedExample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#Mon Jan 14 17:00:49 PST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip

3 changes: 1 addition & 2 deletions ExoPlayerExample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Wed Dec 12 10:57:27 PST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
6 changes: 3 additions & 3 deletions audioplayerexample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ repositories {

dependencies {
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.appcompat:appcompat:1.7.0'
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.33.0'
implementation 'com.google.guava:guava:32.1.3-android'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.34.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
import androidx.media3.datasource.DefaultDataSource;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.exoplayer.analytics.AnalyticsListener;
import androidx.media3.exoplayer.source.ConcatenatingMediaSource;
import androidx.media3.exoplayer.source.MediaSource;
import androidx.media3.exoplayer.source.ProgressiveMediaSource;
import androidx.media3.exoplayer.source.ShuffleOrder;
import androidx.media3.session.MediaSession;
import androidx.media3.ui.PlayerNotificationManager;
import androidx.media3.ui.PlayerNotificationManager.BitmapCallback;
Expand All @@ -34,6 +32,8 @@
import com.google.ads.interactivemedia.v3.api.CompanionAdSlot;
import com.google.ads.interactivemedia.v3.api.ImaSdkFactory;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;

/**
* Allows audio playback with hooks for advertisements. This is meant to run as a Foreground Service
Expand All @@ -45,11 +45,9 @@ public class AudioPlayerService extends Service {

private boolean isAdPlaying;
private ExoPlayer player;
private List<MediaSource> contentMediaSources;
private MediaSession mediaSession;
private PlayerNotificationManager playerNotificationManager;
private ConcatenatingMediaSource contentMediaSource;
private ImaService imaService;

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

@Override
Expand All @@ -62,19 +60,15 @@ public void onCreate() {

DefaultDataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(context);

contentMediaSource =
new ConcatenatingMediaSource(
/* isAtomic= */ false,
/* useLazyPreparation= */ true,
new ShuffleOrder.DefaultShuffleOrder(/* length= */ 0));
contentMediaSources = new ArrayList<>();
for (Samples.Sample sample : sampleList) {
MediaItem mediaItem = new MediaItem.Builder().setUri(sample.uri).build();
MediaSource mediaSource =
new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItem);
contentMediaSource.addMediaSource(mediaSource);
contentMediaSources.add(mediaSource);
}

player.setMediaSource(contentMediaSource);
player.addMediaSources(contentMediaSources);
player.prepare();
player.setPlayWhenReady(true);

Expand Down Expand Up @@ -117,7 +111,7 @@ public Bitmap getCurrentLargeIcon(Player player, BitmapCallback callback) {
}
};

playerNotificationManager =
PlayerNotificationManager playerNotificationManager =
new PlayerNotificationManager.Builder(
context,
/* notificationId= */ PLAYBACK_NOTIFICATION_ID,
Expand All @@ -127,7 +121,8 @@ public Bitmap getCurrentLargeIcon(Player player, BitmapCallback callback) {
.setChannelDescriptionResourceId(R.string.playback_channel_description)
.setNotificationListener(
new NotificationListener() {
public void onNotificationStarted(
@Override
public void onNotificationPosted(
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.
Expand Down Expand Up @@ -183,16 +178,18 @@ public void claim() {
player.setPlayWhenReady(false);
}

@androidx.media3.common.util.UnstableApi
public void release() {
if (isAdPlaying) {
isAdPlaying = false;
player.setMediaSource(contentMediaSource);
player.addMediaSources(contentMediaSources);
player.prepare();
player.setPlayWhenReady(true);
// TODO: Seek to where you left off the stream, if needed.
}
}

@androidx.media3.common.util.UnstableApi
public void prepare(MediaSource mediaSource) {
player.setMediaSource(mediaSource);
player.prepare();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ public boolean handleMessage(Message msg) {
messageHandler.removeMessages(UPDATE);
break;
case UPDATE:
// Intentional fallthrough. START message is introduced as a way to differentiate the
// beginning (the START of progress event) and progress itself (UPDATE events). Handling
// for both the messages are same.
// Intentional fallthrough. START message is introduced as a way to differentiate the
// beginning (the START of progress event) and progress itself (UPDATE events). Handling
// for both the messages are same.
case START:
player.sendProgressUpdate();
messageHandler.removeMessages(UPDATE);
Expand Down
3 changes: 1 addition & 2 deletions audioplayerexample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Sat Apr 14 08:02:51 BST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
4 changes: 2 additions & 2 deletions basicexample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ repositories {

dependencies {
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.appcompat:appcompat:1.7.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.ads.interactivemedia.v3:interactivemedia:3.34.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
package com.google.ads.interactivemedia.v3.samples.videoplayerapp;

import android.content.Context;
import android.content.res.Configuration;
import android.media.AudioManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.VideoView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.ads.interactivemedia.v3.api.AdDisplayContainer;
import com.google.ads.interactivemedia.v3.api.AdErrorEvent;
Expand Down Expand Up @@ -72,14 +73,14 @@ protected void onCreate(Bundle savedInstanceState) {
videoPlayer.setMediaController(mediaController);

// Create an ad display container that uses a ViewGroup to listen to taps.
ViewGroup videoPlayerContainer = findViewById(R.id.videoPlayerContainer);
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
videoAdPlayerAdapter = new VideoAdPlayerAdapter(videoPlayer, audioManager);

sdkFactory = ImaSdkFactory.getInstance();

AdDisplayContainer adDisplayContainer =
ImaSdkFactory.createAdDisplayContainer(videoPlayerContainer, videoAdPlayerAdapter);
ImaSdkFactory.createAdDisplayContainer(
findViewById(R.id.videoPlayerContainer), videoAdPlayerAdapter);

// Create an AdsLoader.
ImaSdkSettings settings = sdkFactory.createImaSdkSettings();
Expand Down Expand Up @@ -174,6 +175,8 @@ public void onAdEvent(AdEvent adEvent) {
});
AdsRenderingSettings adsRenderingSettings =
ImaSdkFactory.getInstance().createAdsRenderingSettings();
// Add any ads rendering settings here.
// This init() only loads the UI rendering settings locally.
adsManager.init(adsRenderingSettings);
}
});
Expand All @@ -186,6 +189,23 @@ public void onAdEvent(AdEvent adEvent) {
requestAds(SAMPLE_VAST_TAG_URL);
view.setVisibility(View.GONE);
});
updateVideoDescriptionVisibility();
}

@Override
public void onConfigurationChanged(@NonNull Configuration configuration) {
super.onConfigurationChanged(configuration);
// Hide the extra content when in landscape so the video is as large as possible.
updateVideoDescriptionVisibility();
}

private void updateVideoDescriptionVisibility() {
int orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
findViewById(R.id.videoDescription).setVisibility(View.GONE);
} else {
findViewById(R.id.videoDescription).setVisibility(View.VISIBLE);
}
}

private void pauseContentForAds() {
Expand Down Expand Up @@ -213,7 +233,7 @@ private void resumeContent() {
mediaPlayer -> videoAdPlayerAdapter.notifyImaOnContentCompleted());
}

private void requestAds(String adTagUrl) {
private void requestAds(@NonNull String adTagUrl) {
// Create the ads request.
AdsRequest request = sdkFactory.createAdsRequest();
request.setAdTagUrl(adTagUrl);
Expand Down
2 changes: 2 additions & 0 deletions basicexample/app/src/main/res/layout/activity_my.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
tools:ignore="MergeRootFrame">

<RelativeLayout
android:background="#000000"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
Expand Down Expand Up @@ -42,6 +43,7 @@
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingVertical="@dimen/font_size"
android:textSize="@dimen/font_size" />
</FrameLayout>

Expand Down
3 changes: 1 addition & 2 deletions basicexample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Wed Dec 12 10:57:27 PST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
4 changes: 2 additions & 2 deletions umpexample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ repositories {

dependencies {
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.appcompat:appcompat:1.7.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.ads.interactivemedia.v3:interactivemedia:3.34.0'
implementation 'com.google.android.ump:user-messaging-platform:2.2.0'
}
2 changes: 1 addition & 1 deletion umpexample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:label="@string/app_name"
android:taskAffinity="">
<!-- The Application ID for the IMA example app. The UMP requires an app ID. -->
<!-- See this guide for more details: https://developers.google.com/interactive-media-ads/ump/android/quick-start#add_app_id_to -->
<!-- See this guide for more details: https://developers.google.com/interactive-media-ads/docs/sdks/android/client-side/privacy#create_a_message_type -->
<!-- Sample IMA App ID: ca-app-pub-9939518381636264~8191772326 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.ads.interactivemedia.v3.api.AdDisplayContainer;
import com.google.ads.interactivemedia.v3.api.AdErrorEvent;
Expand Down Expand Up @@ -61,7 +62,6 @@ public class MyActivity extends AppCompatActivity {
private VideoView videoPlayer;
private ViewGroup videoPlayerContainer;
private MediaController mediaController;
private View playButton;
private VideoAdPlayerAdapter videoAdPlayerAdapter;
private ConsentManager consentManager;

Expand Down Expand Up @@ -224,14 +224,16 @@ public void onAdEvent(AdEvent adEvent) {
});
AdsRenderingSettings adsRenderingSettings =
ImaSdkFactory.getInstance().createAdsRenderingSettings();
// Add any ads rendering settings here.
// This init() only loads the UI rendering settings locally.
adsManager.init(adsRenderingSettings);
}
});
}

private void setUpPlayButton() {
// When the play button is clicked, request ads and hide the button.
playButton = findViewById(R.id.playButton);
View playButton = findViewById(R.id.playButton);
playButton.setOnClickListener(
view -> {
videoPlayer.setVideoPath(SAMPLE_VIDEO_URL);
Expand Down Expand Up @@ -265,7 +267,7 @@ private void resumeContent() {
mediaPlayer -> videoAdPlayerAdapter.notifyImaOnContentCompleted());
}

private void requestAds(String adTagUrl) {
private void requestAds(@NonNull String adTagUrl) {
// Create the ads request.
AdsRequest request = sdkFactory.createAdsRequest();
request.setAdTagUrl(adTagUrl);
Expand Down
2 changes: 2 additions & 0 deletions umpexample/app/src/main/res/layout/activity_my.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
tools:ignore="MergeRootFrame">

<RelativeLayout
android:background="#000000"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
Expand Down Expand Up @@ -42,6 +43,7 @@
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingVertical="@dimen/font_size"
android:textSize="@dimen/font_size" />
</FrameLayout>

Expand Down
3 changes: 1 addition & 2 deletions umpexample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Wed Dec 12 10:57:27 PST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip

0 comments on commit d67b737

Please sign in to comment.