# การปรับตั้งค่า Options

การปรับแต่ง ByteArk Player ทำได้ผ่าน ByteArkPlayerConfig สำหรับตั้งค่าการทำงานของ Player และ ByteArkPlayerItem สำหรับกำหนดข้อมูลของวิดีโอที่จะเล่น โดยแต่ละ Item จะมี ByteArkPlayerSource ได้ตั้งแต่หนึ่งตัวขึ้นไป และตั้งค่า DRM แยกในแต่ละ Source

WARNING

หน้านี้อ้างอิงจาก README เวอร์ชัน 2.0.0 บน pub.dev (opens new window) ตำแหน่งของ Metadata ระดับ Item, รูปแบบค่าของ aspectRatio และการเลือก Source ตามแพลตฟอร์ม เป็นการอนุมานจากตัวอย่างใน README โปรดตรวจสอบกับ SDK ที่ติดตั้งจริงหากไม่แน่ใจ

# ByteArkPlayerConfig

final config = ByteArkPlayerConfig(
  licenseKey: ByteArkPlayerLicenseKey(
    android: "<ANDROID_LICENSE_KEY>",
    iOS: "<IOS_LICENSE_KEY>",
  ),
  playerItem: playerItem,
  aspectRatio: '16:9',
  autoPlay: true,
  control: true,
);
1
2
3
4
5
6
7
8
9
10
Property Type Default Description
licenseKey ByteArkPlayerLicenseKey required License key สำหรับ Android และ iOS
playerItem ByteArkPlayerItem required วิดีโอที่จะเล่น
aspectRatio String? - อัตราส่วนภาพในรูปแบบ 'width:height' (เช่น '16:9') ส่วนใหญ่ใช้ควบคุมขนาดบน Web
autoPlay bool? true เริ่มเล่นวิดีโออัตโนมัติ
control bool? true แสดงแถบควบคุม
seekButtons bool? true แสดงปุ่ม Seek เดินหน้า/ถอยหลัง
seekTime int? 30 ระยะเวลา Seek (วินาที)
fullScreenButton bool? true แสดงปุ่ม Full Screen
settingButton bool? true แสดงปุ่มตั้งค่า
secureSurface bool? false เปิด Secure Surface สำหรับเนื้อหา DRM
subtitleSize ByteArkPlayerSubtitleSize? medium ขนาดตัวอักษรซับไตเติ้ล คิดเป็นเปอร์เซ็นต์ของความสูงวิดีโอ: minimum (1%), extraTiny (2%), tiny (3%), extraSmall (4%), small (5%), medium (6%), large (7%), extraLarge (8%), maximum (9%)
subtitleBackgroundEnabled bool? true แสดงพื้นหลังตัวอักษรซับไตเติ้ล
subtitlePaddingBottomPercentage int? 10 ระยะห่างของซับไตเติ้ลจากขอบล่าง (%)
adsSettings ByteArkAdsSettings? - ตั้งค่าโฆษณา (ดู การเล่นโฆษณา)
lighthouseSetting ByteArkLighthouseSetting? - ตั้งค่า Lighthouse (ดู ByteArk Lighthouse)

# ByteArkPlayerLicenseKey

final licenseKey = ByteArkPlayerLicenseKey(
  android: "<ANDROID_LICENSE_KEY>",
  iOS: "<IOS_LICENSE_KEY>",
);
1
2
3
4
Property Type Description
android String License key สำหรับ Android
iOS String License key สำหรับ iOS

# ByteArkPlayerItem

final playerItem = ByteArkPlayerItem(
  sources: [
    ByteArkPlayerSource(url: "<MEDIA_URL>"),
  ],
  title: "Big Buck Bunny",
);
1
2
3
4
5
6
Property Type Required Description
sources List<ByteArkPlayerSource> Yes Source ที่เล่นได้ตั้งแต่หนึ่งตัวขึ้นไป (ต้องไม่เป็นลิสต์ว่าง) ระบุหลาย Source เพื่อรองรับแต่ละแพลตฟอร์ม/DRM ได้
mediaId String? No ID ของวิดีโอ (จำเป็นเมื่อเปิดใช้ Lighthouse)
title String? No ชื่อวิดีโอ
subtitle String? No คำอธิบาย/ตอน
posterImage String? No URL ของภาพปก
shareUrl String? No URL ที่จะใช้แชร์
lighthouseMetaData ByteArkPlayerLighthouseMetaData? No Metadata สำหรับ Lighthouse

# ByteArkPlayerSource

Source ที่เล่นได้หนึ่งตัว ใช้ Constructor ปกติสำหรับเนื้อหาทั่วไป หรือใช้ Factory ByteArkPlayerSource.drm เพื่อแนบ DRM

// Source ทั่วไป
final source = ByteArkPlayerSource(url: "<MEDIA_URL>");
// Source ที่มี DRM
final drmSource = ByteArkPlayerSource.drm(
  url: "<MEDIA_URL>",
  drm: WidevineDrm(licenseUrl: "<WIDEVINE_LICENSE_URL>"),
);
1
2
3
4
5
6
7
8
Property Type Required Description
url String Yes URL ของ Source (HLS .m3u8 หรือ DASH .mpd)
drm ByteArkDrm No การตั้งค่า DRM ระบุผ่าน Factory ByteArkPlayerSource.drm (ดู DRM)

# ByteArkAdsSettings

final adsSettings = ByteArkAdsSettings(
  adTagUrl: "<VAST_TAG_URL>",
);
1
2
3
Property Type Description
adTagUrl String? URL ของ VAST/VMAP ad tag
enableDefaultCompanionSlot bool? เปิดใช้ Companion Ad slot เริ่มต้น
defaultCompanionSize Pair<int, int>? ขนาดของ Companion Ad (width, height)

# ByteArkLighthouseSetting

final lighthouseSetting = ByteArkLighthouseSetting(
  projectId: "<PROJECT_ID>",
  debug: false,
);
1
2
3
4
Property Type Description
projectId String? Lighthouse Project ID
debug bool? เปิดใช้ Debug mode

# DRM

DRM จะถูกแนบในแต่ละ Source ผ่าน Factory ByteArkPlayerSource.drm โดย ByteArkDrm เป็น Sealed type ที่มีสองรูปแบบ ได้แก่ WidevineDrm (Android) และ FairPlayDrm (iOS) ให้ระบุ Source สำหรับ DRM ของแต่ละแพลตฟอร์ม แล้ว Player จะเลือก Source ที่รองรับขณะใช้งานเอง

final playerItem = ByteArkPlayerItem(
  sources: [
    ByteArkPlayerSource.drm(
      url: "<HLS_URL>",   // .m3u8 สำหรับ FairPlay (iOS)
      drm: FairPlayDrm(
        licenseUrl: "<FAIRPLAY_LICENSE_URL>",
        certificateUrl: "<FAIRPLAY_CERTIFICATE_URL>",
      ),
    ),
    ByteArkPlayerSource.drm(
      url: "<DASH_URL>",  // .mpd สำหรับ Widevine (Android)
      drm: WidevineDrm(
        licenseUrl: "<WIDEVINE_LICENSE_URL>",
      ),
    ),
  ],
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

ดูคุณสมบัติทั้งหมดของแต่ละชนิดได้ที่ Google Widevine และ Apple FairPlay