# การเล่นโฆษณา (Advertisement)
ByteArk Player SDK for Flutter รองรับการแสดงโฆษณาผ่าน Google IMA SDK ตามมาตรฐาน Video Ad Serving Template (VAST) (opens new window) และ VMAP โดยกำหนดผ่าน adsSettings ของ ByteArkPlayerConfig
# การเปิดใช้งาน
final config = ByteArkPlayerConfig(
licenseKey: licenseKey,
playerItem: playerItem,
adsSettings: ByteArkAdsSettings(
adTagUrl: "<VAST_TAG_URL>",
),
);
1
2
3
4
5
6
7
2
3
4
5
6
7
| Property | Type | Description |
|---|---|---|
adTagUrl | String? | URL ของ VAST/VMAP ad tag |
enableDefaultCompanionSlot | bool? | เปิดใช้ Companion Ad slot เริ่มต้น |
defaultCompanionSize | Pair<int, int>? | ขนาดของ Companion Ad (width, height) |
# รับ Event ของโฆษณา
final listener = ByteArkPlayerListener(
onAdsRequest: () => debugPrint("Ad requested"),
onAdsBreakStart: () => debugPrint("Ad break started"),
onAdsStart: (data) => debugPrint("Ad started: ${data.toMap()}"),
onAdsImpressed: (data) => debugPrint("Ad impression"),
onAdsFirstQuartile: (data) => debugPrint("Ad first quartile"),
onAdsMidPoint: (data) => debugPrint("Ad midpoint"),
onAdsThirdQuartile: (data) => debugPrint("Ad third quartile"),
onAdsCompleted: (data) => debugPrint("Ad completed"),
onAdsClicked: (data) => debugPrint("Ad clicked"),
onAdsSkipped: (data) => debugPrint("Ad skipped"),
onAdsBreakEnd: () => debugPrint("Ad break ended"),
onAllAdsCompleted: () => debugPrint("All ads completed"),
onAdsError: (error) => debugPrint("Ads error: ${error.msg}"),
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# ByteArkPlayerAdsData
Callback ของวงจรโฆษณา (onAdsStart, Callback กลุ่มควอไทล์, onAdsCompleted, onAdsClicked, onAdsSkipped, onAdsImpressed) จะได้รับ Object ByteArkPlayerAdsData
| Field | Type | Description |
|---|---|---|
adId | String? | รหัสเฉพาะของชิ้นงานโฆษณา |
adSystem | String? | ระบบที่ให้บริการโฆษณา (เช่น GoogleAds) |
advertiserName | String? | ชื่อผู้ลงโฆษณา |
creativeAdId | String? | รหัสของ Creative variant ภายในแคมเปญ |
creativeId | String? | รหัสของ Creative asset |
title | String? | ชื่อโฆษณา |
ส่วน onAdsError จะได้รับ ByteArkPlayerAdsErrorData ที่มีฟิลด์ code และ msg (ดู Errors Reference)