package com.weikou.beibeivideo.util.ad;
|
|
import android.app.Activity;
|
import android.content.Context;
|
import android.widget.Toast;
|
|
import com.bytedance.sdk.openadsdk.AdSlot;
|
import com.bytedance.sdk.openadsdk.TTAdConstant;
|
import com.bytedance.sdk.openadsdk.TTAdManager;
|
import com.bytedance.sdk.openadsdk.TTAdNative;
|
import com.bytedance.sdk.openadsdk.TTFullScreenVideoAd;
|
import com.weikou.beibeivideo.util.DimenUtils;
|
|
public class FullVideoAdManager {
|
|
private TTAdNative mTTAdNative = null;
|
|
private TTFullScreenVideoAd mttFullVideoAd;
|
|
private static FullVideoAdManager fullVideoAdManager;
|
|
public static FullVideoAdManager getInstance() {
|
if (fullVideoAdManager == null)
|
fullVideoAdManager = new FullVideoAdManager();
|
return fullVideoAdManager;
|
}
|
|
public void loadAd(final Context context, final IFullVideoAdListener adListener) {
|
int w = DimenUtils.getScreenWidth(context);
|
int h = DimenUtils.getScreenHeight(context);
|
AdSlot adSlot = new AdSlot.Builder()
|
.setCodeId("945393854")
|
.setSupportDeepLink(true)
|
.setExpressViewAcceptedSize(w,h)
|
.setOrientation(TTAdConstant.VERTICAL)
|
.build();
|
TTAdManager ttAdManager = TTAdManagerHolder.get();
|
mTTAdNative = ttAdManager.createAdNative(context);
|
//加载全屏视频
|
mTTAdNative.loadFullScreenVideoAd(adSlot, new TTAdNative.FullScreenVideoAdListener() {
|
@Override
|
public void onError(int code, String message) {
|
}
|
|
@Override
|
public void onFullScreenVideoAdLoad(TTFullScreenVideoAd ad) {
|
mttFullVideoAd = ad;
|
mttFullVideoAd.setFullScreenVideoAdInteractionListener(new TTFullScreenVideoAd.FullScreenVideoAdInteractionListener() {
|
|
@Override
|
public void onAdShow() {
|
}
|
|
@Override
|
public void onAdVideoBarClick() {
|
}
|
|
@Override
|
public void onAdClose() {
|
}
|
|
@Override
|
public void onVideoComplete() {
|
}
|
|
@Override
|
public void onSkippedVideo() {
|
|
}
|
|
});
|
|
if (ad != null && adListener != null)
|
adListener.onSuccess();
|
}
|
|
@Override
|
public void onFullScreenVideoCached() {
|
}
|
});
|
}
|
|
|
/**
|
* 展示广告
|
*
|
* @param activity
|
*/
|
public void showAd(Activity activity) {
|
if (mttFullVideoAd != null) {
|
mttFullVideoAd.showFullScreenVideoAd(activity);
|
mttFullVideoAd = null;
|
}
|
}
|
|
/**
|
* 是否已经缓存了广告
|
*
|
* @return
|
*/
|
public boolean isCacahed() {
|
return mttFullVideoAd != null;
|
}
|
|
interface IFullVideoAdListener {
|
public void onSuccess();
|
}
|
|
}
|