admin
2021-08-27 799b8662790850240bc6e7e6d16241c1a8869a3d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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(ad);
            }
 
            @Override
            public void onFullScreenVideoCached() {
            }
 
            @Override
            public void onFullScreenVideoCached(TTFullScreenVideoAd ttFullScreenVideoAd) {
 
            }
        });
    }
 
 
    /**
     * 展示广告
     *
     * @param activity
     */
    public void showAd(Activity activity) {
        if (mttFullVideoAd != null) {
            mttFullVideoAd.showFullScreenVideoAd(activity);
            mttFullVideoAd = null;
        }
    }
 
    /**
     * 是否已经缓存了广告
     *
     * @return
     */
    public boolean isCacahed() {
        return mttFullVideoAd != null;
    }
 
    public interface IFullVideoAdListener {
        public void onSuccess(TTFullScreenVideoAd ad);
    }
 
}