Skip to content

Commit

Permalink
Updates samples to v3.35.1.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 681911924
  • Loading branch information
google-ima-devrel-bot authored and IMA Developer Relations committed Oct 8, 2024
1 parent 618c65b commit 3fa1a4f
Show file tree
Hide file tree
Showing 50 changed files with 216 additions and 267 deletions.
4 changes: 2 additions & 2 deletions AdvancedExample/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.3.1"
def media3_version = "1.4.1"
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
Expand All @@ -42,5 +42,5 @@ dependencies {
implementation "androidx.media3:media3-exoplayer-dash:$media3_version"
implementation 'androidx.mediarouter:mediarouter:1.7.0'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.34.0'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.35.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ public interface SampleVideoPlayerCallback extends VideoStreamPlayer.VideoStream
private ExoPlayer player;
private final PlayerView playerView;
private SampleVideoPlayerCallback playerCallback;

@C.ContentType private int currentlyPlayingStreamType = C.CONTENT_TYPE_OTHER;

private String streamUrl;
private Boolean streamRequested;
private boolean canSeek;
Expand Down Expand Up @@ -121,10 +118,9 @@ public void play() {

DataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(context);
MediaSource mediaSource;
currentlyPlayingStreamType = Util.inferContentType(Uri.parse(streamUrl));
Uri streamUri = Uri.parse(streamUrl);
MediaItem mediaItem = new MediaItem.Builder().setUri(streamUri).build();
switch (currentlyPlayingStreamType) {
switch (Util.inferContentType(Uri.parse(streamUrl))) {
case C.CONTENT_TYPE_HLS:
mediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItem);
break;
Expand All @@ -148,16 +144,14 @@ public void play() {
public void onMetadata(Metadata metadata) {
for (int i = 0; i < metadata.length(); i++) {
Metadata.Entry entry = metadata.get(i);
if (entry instanceof TextInformationFrame) {
TextInformationFrame textFrame = (TextInformationFrame) entry;
if (entry instanceof TextInformationFrame textFrame) {
if ("TXXX".equals(textFrame.id)) {
Log.d(LOG_TAG, "Received user text: " + textFrame.value);
Log.d(LOG_TAG, "Received user text: " + textFrame.values.get(0));
if (playerCallback != null) {
playerCallback.onUserTextReceived(textFrame.value);
playerCallback.onUserTextReceived(textFrame.values.get(0));
}
}
} else if (entry instanceof EventMessage) {
EventMessage eventMessage = (EventMessage) entry;
} else if (entry instanceof EventMessage eventMessage) {
String eventMessageValue = new String(eventMessage.messageData);
Log.d(LOG_TAG, "Received user text: " + eventMessageValue);
if (playerCallback != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public class MyActivity extends AppCompatActivity {
private static final String VIDEO_FRAGMENT_TAG = "video_example_fragment_tag";

private static final String FALLBACK_STREAM_URL =
"https://storage.googleapis.com/testtopbox-public/video_content/bbb/master.m3u8";
"https://storage.googleapis.com/interactive-media-ads/media/bbb.m3u8";
private static final String APP_LOG_TAG = "ImaDaiExample";

private SampleVideoPlayer videoPlayer;
private SampleAdsWrapper sampleAdsWrapper;
private ImageButton playButton;

private HashMap<String, Long> bookmarks = new HashMap<>();
private final HashMap<String, Long> bookmarks = new HashMap<>();
private VideoListFragment.VideoListItem videoListItem;
private boolean contentHasStarted = false;

Expand Down Expand Up @@ -132,9 +132,8 @@ public void onResume() {
}

public void hidePlayButton() {
ImageButton button = (ImageButton) findViewById(R.id.playButton);
if (button != null) {
button.setVisibility(View.INVISIBLE);
if (playButton != null) {
playButton.setVisibility(View.INVISIBLE);
}
}

Expand All @@ -158,23 +157,21 @@ public void onVideoSelected(VideoListFragment.VideoListItem videoItem) {
}
};

private VideoFragmentListener mVideoFragmentListener =
private final VideoFragmentListener mVideoFragmentListener =
new VideoFragmentListener() {
@Override
public void onVideoFragmentCreated(View rootView) {
// Boolean 'contentHasStarted' is set to false by default, but it also needs
// to be set to false here, in the case where multiple test cases are watched in
// single session.
contentHasStarted = false;
playButton = (ImageButton) rootView.findViewById(R.id.playButton);
playButton = rootView.findViewById(R.id.playButton);
videoPlayer =
new SampleVideoPlayer(rootView.getContext(), rootView.findViewById(R.id.videoView));
videoPlayer.enableControls(false);
sampleAdsWrapper =
new SampleAdsWrapper(
rootView.getContext(),
videoPlayer,
(ViewGroup) rootView.findViewById(R.id.adUiContainer));
rootView.getContext(), videoPlayer, rootView.findViewById(R.id.adUiContainer));
sampleAdsWrapper.setFallbackUrl(FALLBACK_STREAM_URL);

final TextView descTextView = rootView.findViewById(R.id.playerDescription);
Expand All @@ -198,35 +195,29 @@ public void onVideoFragmentCreated(View rootView) {
forceHeight.applyTo(constraintLayout);

sampleAdsWrapper.setLogger(
new SampleAdsWrapper.Logger() {
@Override
public void log(String logMessage) {
Log.i(APP_LOG_TAG, logMessage);
if (logTextView != null) {
logTextView.append(logMessage);
}
logMessage -> {
Log.i(APP_LOG_TAG, logMessage);
if (logTextView != null) {
logTextView.append(logMessage);
}
});

// Set up play button listener to play video then hide play button.
playButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
hidePlayButton();
if (contentHasStarted) {
videoPlayer.play();
return;
}
contentHasStarted = true;
long bookMarkTime = 0;
if (bookmarks.containsKey(videoListItem.getId())) {
bookMarkTime = bookmarks.get(videoListItem.getId());
}
videoPlayer.enableControls(true);
videoPlayer.setCanSeek(true);
sampleAdsWrapper.requestAndPlayAds(videoListItem, bookMarkTime);
view -> {
hidePlayButton();
if (contentHasStarted) {
videoPlayer.play();
return;
}
contentHasStarted = true;
long bookMarkTime = 0;
if (bookmarks.containsKey(videoListItem.getId())) {
bookMarkTime = bookmarks.get(videoListItem.getId());
}
videoPlayer.enableControls(true);
videoPlayer.setCanSeek(true);
sampleAdsWrapper.requestAndPlayAds(videoListItem, bookMarkTime);
});

orientVideoDescription(getResources().getConfiguration().orientation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.content.Context;
import android.util.Log;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import com.google.ads.interactivemedia.v3.api.AdErrorEvent;
import com.google.ads.interactivemedia.v3.api.AdEvent;
import com.google.ads.interactivemedia.v3.api.AdsLoader;
Expand Down Expand Up @@ -89,7 +88,7 @@ private void createAdsLoader() {
videoPlayer.setSampleVideoPlayerCallback(
new SampleVideoPlayer.SampleVideoPlayerCallback() {
@Override
public void onUserTextReceived(@NonNull String userText) {
public void onUserTextReceived(String userText) {
for (VideoStreamPlayer.VideoStreamPlayerCallback callback : playerCallbacks) {
callback.onUserTextReceived(userText);
}
Expand Down Expand Up @@ -185,7 +184,7 @@ private StreamRequest buildStreamRequest(VideoListFragment.VideoListItem videoLi
private VideoStreamPlayer createVideoStreamPlayer() {
return new VideoStreamPlayer() {
@Override
public void loadUrl(@NonNull String url, @NonNull List<HashMap<String, String>> subtitles) {
public void loadUrl(String url, List<HashMap<String, String>> subtitles) {
videoPlayer.setStreamUrl(url);
videoPlayer.play();

Expand Down Expand Up @@ -215,12 +214,12 @@ public int getVolume() {
}

@Override
public void addCallback(@NonNull VideoStreamPlayerCallback videoStreamPlayerCallback) {
public void addCallback(VideoStreamPlayerCallback videoStreamPlayerCallback) {
playerCallbacks.add(videoStreamPlayerCallback);
}

@Override
public void removeCallback(@NonNull VideoStreamPlayerCallback videoStreamPlayerCallback) {
public void removeCallback(VideoStreamPlayerCallback videoStreamPlayerCallback) {
playerCallbacks.remove(videoStreamPlayerCallback);
}

Expand Down Expand Up @@ -264,7 +263,6 @@ public void seek(long timeMs) {
videoPlayer.seekTo(timeMs);
}

@NonNull
@Override
public VideoProgressUpdate getContentProgress() {
if (videoPlayer == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
Expand Down Expand Up @@ -162,19 +161,16 @@ public View onCreateView(
LayoutInflater layoutInflater, final ViewGroup viewGroup, Bundle bundle) {
View rootView = layoutInflater.inflate(R.layout.fragment_video_list, viewGroup, false);

final ListView listView = (ListView) rootView.findViewById(R.id.videoListView);
final ListView listView = rootView.findViewById(R.id.videoListView);
VideoListAdapter videoListAdapter =
new VideoListAdapter(rootView.getContext(), R.layout.video_item, getVideoListItems());
listView.setAdapter(videoListAdapter);

listView.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
VideoListItem item = (VideoListItem) listView.getItemAtPosition(position);
if (listener != null && item != null) {
listener.onVideoSelected(item);
}
(parent, view, position, id) -> {
VideoListItem item = (VideoListItem) listView.getItemAtPosition(position);
if (listener != null && item != null) {
listener.onVideoSelected(item);
}
});

Expand All @@ -197,7 +193,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.video_item, parent, false);
}
// Lookup view for data population
TextView titleText = (TextView) convertView.findViewById(R.id.videoItemText);
TextView titleText = convertView.findViewById(R.id.videoItemText);

// Populate the data into the template view using the data object
titleText.setText(videoListItem.title);
Expand Down
10 changes: 6 additions & 4 deletions AdvancedExample/app/src/main/res/layout/fragment_video.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
android:layout_height="match_parent" />
<ImageButton
android:id="@+id/playButton"
android:contentDescription="Play Button"
android:contentDescription="@string/play_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_action_play_over_video"
Expand Down Expand Up @@ -76,15 +76,17 @@
android:layout_gravity="center">
<TextView
android:id="@+id/time_start"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/time_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="10dp" />
android:layout_alignParentEnd="true"
android:paddingStart="10dp"
android:paddingEnd="10dp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
android:layout_margin="5dp"
android:numColumns="1"
android:verticalSpacing="10dp"
android:layout_centerHorizontal="true"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth" />

Expand Down
9 changes: 5 additions & 4 deletions AdvancedExample/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">IMA Sample Video Player</string>
<string name="action_settings">Settings</string>
<string name="video_description">Sample Video Stream</string>
<string name="suggested_videos">Sample Videos</string>
<string name="app_id">8EE292C4</string>
<string name="media_route_menu_title">Menu</string>
<string name="app_name">IMA Sample Video Player</string>
<color name="black">#000000</color>
<string name="media_route_menu_title">Menu</string>
<string name="play_button">Play button</string>
<string name="suggested_videos">Sample Videos</string>
<string name="video_description">Sample Video Stream</string>

</resources>
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.3.2'
classpath 'com.android.tools.build:gradle:8.7.0'
}
}
3 changes: 2 additions & 1 deletion AdvancedExample/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
android.enableJetifier=true
android.useAndroidX=true
android.useAndroidX=true
org.gradle.jvmargs=-Xms1024m -Xmx4096m
2 changes: 1 addition & 1 deletion AdvancedExample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
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 @@ -32,13 +32,13 @@ repositories {
}

dependencies {
def media3_version = "1.3.1"
def media3_version = "1.4.1"
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation "androidx.media3:media3-ui:$media3_version"
implementation "androidx.media3:media3-exoplayer:$media3_version"
implementation "androidx.media3:media3-exoplayer-hls:$media3_version"
implementation "androidx.media3:media3-exoplayer-dash:$media3_version"
implementation 'androidx.mediarouter:mediarouter:1.7.0'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.34.0'
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.35.1'
}
Loading

0 comments on commit 3fa1a4f

Please sign in to comment.