# เพลย์ลิสต์ (Playlist & Queue)
ByteArk Player SDK for Android รองรับการเล่นวิดีโอต่อเนื่องในรูปแบบ Playlist (รายการที่กำหนดล่วงหน้า) และ Queue (รายการที่เพิ่ม/ลบได้ขณะเล่น)
# Playlist
สร้าง Playlist ผ่าน ByteArkPlaylistBuilder
val item1 = ByteArkPlayerItemBuilder.Builder()
.withMediaId("1")
.withTitle("Episode 1")
.withUrl("https://example.com/ep1/playlist.m3u8")
.build()
val item2 = ByteArkPlayerItemBuilder.Builder()
.withMediaId("2")
.withTitle("Episode 2")
.withUrl("https://example.com/ep2/playlist.m3u8")
.build()
val playlist = ByteArkPlaylistBuilder.Builder()
.withMediaId("playlist-1")
.withTitle("Season 1")
.withContentList(listOf(item1, item2))
.build()
mPlayerFragment.openPlaylist(playlist)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# ควบคุม Playlist
mPlayerFragment.next() // ไปยังวิดีโอถัดไป
mPlayerFragment.previous() // ย้อนกลับไปวิดีโอก่อนหน้า
val currentPlaylist = mPlayerFragment.getPlaylist()
1
2
3
4
2
3
4
# Queue
Queue ใช้สำหรับเพิ่ม/ลบวิดีโอขณะเล่น
mPlayerFragment.addItemToQueue(item)
mPlayerFragment.removeQueueItem(item)
mPlayerFragment.selectQueueItem(item)
val queue: List<ByteArkPlayerItem> = mPlayerFragment.getCurrentQueue()
1
2
3
4
5
2
3
4
5
# รับ Event เมื่อเปลี่ยนวิดีโอ
override fun onPlayerItemChange(
updatePlayerItem: ByteArkPlayerItem,
isPlaylist: Boolean,
isQueue: Boolean,
index: Int
) {
// เปลี่ยนเป็นวิดีโอใหม่
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8