import 'dart:convert';
|
|
import 'package:flutter/services.dart';
|
|
import '../../utils/share_preference.dart';
|
import '../../utils/string_util.dart';
|
|
MethodChannel adMethodChannel = const MethodChannel('com.yeshi.video/ad');
|
|
enum AdType { csj, gdt }
|
|
enum AdPosition {
|
//推荐
|
other,
|
//搜索
|
videoSearch,
|
//全屏视频
|
videoDetailFullVideo,
|
videoPlayPre
|
}
|
|
class CSJADConstant {
|
//推荐首页大图
|
static const String PID_RECOMMEND_BIG_PICTURE = "948067685";
|
//搜索页广告
|
static const String PID_VIDEO_SEARCH = "948119448";
|
//全屏视频广告
|
static const String PID_VIDEO_DETAIL_FULLSCREEN = "948119553";
|
}
|
|
class GDTADConstant {
|
//推荐首页大图
|
static const String PID_RECOMMEND_BIG_PICTURE = "5033406516973331";
|
|
//搜索页广告
|
static const String PID_VIDEO_SEARCH = "4033805974201049";
|
|
//全屏视频广告
|
static const String PID_VIDEO_DETAIL_FULLSCREEN = "6053800914701167";
|
}
|
|
class AdUtil {
|
static void loadFullScreenAd(AdType adType, String pid) {
|
if (adType == AdType.csj) {
|
adMethodChannel.invokeMethod("loadCSJFullScreenAd", {"pid": pid});
|
} else {
|
adMethodChannel.invokeMethod("loadGDTFullScreenAd", {"pid": pid});
|
}
|
}
|
|
//获取广告配置信息
|
static Future<Map<String, dynamic>?> _getAdConfig() async {
|
String result = await dataMethodChannel.invokeMethod("getAdConfig");
|
print("广告配置:$result");
|
if (StringUtil.isNullOrEmpty(result)) {
|
return null;
|
}
|
return jsonDecode(result);
|
}
|
|
static Future<AdType?> getAdType(AdPosition position) async {
|
String key = "";
|
if (position == AdPosition.other) {
|
key = "other";
|
} else if (position == AdPosition.videoSearch) {
|
key = "videoSearch";
|
} else if (position == AdPosition.videoDetailFullVideo) {
|
key = "videoDetailFullVideo";
|
} else if (position == AdPosition.videoPlayPre) {
|
key = "videoPlayPre";
|
}
|
|
Map<String, dynamic>? config = await _getAdConfig();
|
if (config == null) {
|
return null;
|
}
|
|
print("广告key:$key 类型${config[key]}");
|
if (config[key] == null) {
|
return null;
|
}
|
if (config[key]["type"] == "csj") {
|
return AdType.csj;
|
}
|
|
if (config[key]["type"] == "gdt") {
|
return AdType.gdt;
|
}
|
|
return null;
|
}
|
}
|