Reattach player to ads loader on resume
When pausing and resuming a playback using an AdsLoader it is necessary to call setPlayer again. This fixes an issue where playback was stuck in the buffering state when pausing and resuming an ad playback in the demo app. PiperOrigin-RevId: 308582143
This commit is contained in:
parent
a7c301cb23
commit
008d38d832
@ -448,7 +448,7 @@ public class PlayerActivity extends AppCompatActivity
|
|||||||
* otherwise.
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private AdsLoader createAdsLoader(Uri adTagUri) {
|
private AdsLoader maybeCreateAdsLoader(Uri adTagUri) {
|
||||||
// Load the extension source using reflection so the demo app doesn't have to depend on it.
|
// Load the extension source using reflection so the demo app doesn't have to depend on it.
|
||||||
try {
|
try {
|
||||||
Class<?> loaderClass = Class.forName("com.google.android.exoplayer2.ext.ima.ImaAdsLoader");
|
Class<?> loaderClass = Class.forName("com.google.android.exoplayer2.ext.ima.ImaAdsLoader");
|
||||||
@ -593,14 +593,14 @@ public class PlayerActivity extends AppCompatActivity
|
|||||||
releaseAdsLoader();
|
releaseAdsLoader();
|
||||||
loadedAdTagUri = adTagUri;
|
loadedAdTagUri = adTagUri;
|
||||||
}
|
}
|
||||||
|
// The ads loader is reused for multiple playbacks, so that ad playback can resume.
|
||||||
if (adsLoader == null) {
|
if (adsLoader == null) {
|
||||||
// The ads loader is reused for multiple playbacks, so that ad playback can resume.
|
adsLoader = maybeCreateAdsLoader(adTagUri);
|
||||||
adsLoader = createAdsLoader(adTagUri);
|
}
|
||||||
if (adsLoader != null) {
|
if (adsLoader != null) {
|
||||||
adsLoader.setPlayer(player);
|
adsLoader.setPlayer(player);
|
||||||
} else {
|
} else {
|
||||||
showToast(R.string.ima_not_loaded);
|
showToast(R.string.ima_not_loaded);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return adsLoader;
|
return adsLoader;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user