我有一个基本上依赖于视频自动播放的应用,但如果他们随机选择在视频中首先注入广告,则YouTube API不会让您自动播放。
此外,我还有一个YouTube
个视频列表和YouTubePlayer
活动所有视频自动播放。它运作良好。但现在当我在视频开始时添加AdMob
插页式广告时会出现问题。广告显示但是当我在暂停视频后关闭广告时,即使我在广告关闭方法中编写播放视频的代码。
所以基本上我想在广告关闭后自动播放视频而无需用户点击它。
private YouTubePlayer player;
youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_player_view);
youTubePlayerView.initialize(YOUTUBE_API_KEY, this);
mInterstitialAd = new InterstitialAd(context);
mInterstitialAd.setAdUnitId(getString(R.string.interstitial_ad_id));
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
requestNewInterstitial();
player.play();
// player.loadVideo(VIDEO_ID);
}
});
@Override
public void onInitializationSuccess(Provider provider, final YouTubePlayer player, boolean wasRestored) {
if (null == player) return;
this.player = player;
// Start buffering
if (!wasRestored) {
player.loadVideo(VIDEO_ID);
}
// Add listeners to YouTubePlayer instance
player.setPlayerStateChangeListener(new PlayerStateChangeListener() {
@Override
public void onAdStarted() {
}
@Override
public void onError(ErrorReason arg0) {
}
@Override
public void onLoaded(String arg0) {
}
@Override
public void onLoading() {
}
@Override
public void onVideoEnded() {
}
}
@Override
public void onVideoStarted() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
});
player.setPlaybackEventListener(new PlaybackEventListener() {
@Override
public void onBuffering(boolean arg0) {
}
@Override
public void onPaused() {
}
@Override
public void onPlaying() {
}
@Override
public void onSeekTo(int arg0) {
}
@Override
public void onStopped() {
}
});
}