ExoPlayer รองรับ SmoothStreaming ในรูปแบบคอนเทนเนอร์ FMP4 สตรีมสื่อ ต้องถูกแยกออกจากกัน ซึ่งหมายความว่าวิดีโอ เสียง และข้อความต้องได้รับการกำหนดแยกกัน องค์ประกอบ StreamIndex ในไฟล์ Manifest SmoothStreaming เสียงที่มีการควบคุมและ รูปแบบวิดีโอตัวอย่างต้องได้รับการสนับสนุนด้วย (ดู รูปแบบตัวอย่างเพื่อดูรายละเอียด)
ฟีเจอร์ | รองรับ | ความคิดเห็น |
---|---|---|
คอนเทนเนอร์ | ||
FMP4 | ใช่ | สตรีมที่ถอดรหัสเท่านั้น |
คำบรรยายแทนเสียง/คำบรรยาย | ||
TTML | ใช่ | ฝังอยู่ใน FMP4 |
การปกป้องเนื้อหา | ||
PlayReady SL2000 | ใช่ | Android TV เท่านั้น |
การเล่นแบบสด | ||
การเล่นแบบสดปกติ | ใช่ | |
ข้อมูลไคลเอ็นต์สื่อทั่วไป (CMCD) | ใช่ | คู่มือการผสานรวม |
การใช้ MediaItem
ในการเล่นสตรีม SmoothStreaming คุณต้องใช้ SmoothStreaming
Kotlin
implementation("androidx.media3:media3-exoplayer-smoothstreaming:1.4.1")
ดึงดูด
implementation "androidx.media3:media3-exoplayer-smoothstreaming:1.4.1"
จากนั้นคุณสามารถสร้าง MediaItem
สำหรับ URI ของไฟล์ Manifest แบบ SmoothStreaming และส่งต่อ
ในโปรแกรมเล่น
Kotlin
// Create a player instance. val player = ExoPlayer.Builder(context).build() // Set the media item to be played. player.setMediaItem(MediaItem.fromUri(ssUri)) // Prepare the player. player.prepare()
Java
// Create a player instance. ExoPlayer player = new ExoPlayer.Builder(context).build(); // Set the media item to be played. player.setMediaItem(MediaItem.fromUri(ssUri)); // Prepare the player. player.prepare();
หาก URI ไม่ได้ลงท้ายด้วย .ism/Manifest
คุณข้ามได้
MimeTypes.APPLICATION_SS
ถึง setMimeType
จาก MediaItem.Builder
ถึงอย่างชัดเจน
ระบุประเภทของเนื้อหา
ExoPlayer จะปรับตามตัวแทนที่กำหนดไว้ใน ไฟล์ Manifest โดยพิจารณาจากทั้งความสามารถของแบนด์วิดท์และของอุปกรณ์ที่มีอยู่
การใช้ SsMediaSource
หากต้องการตัวเลือกการปรับแต่งเพิ่มเติม คุณสามารถสร้าง SsMediaSource
และส่งต่อ
ไปยังโปรแกรมเล่นโดยตรง แทนที่จะเป็น MediaItem
Kotlin
// Create a data source factory. val dataSourceFactory: DataSource.Factory = DefaultHttpDataSource.Factory() // Create a SmoothStreaming media source pointing to a manifest uri. val mediaSource: MediaSource = SsMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(ssUri)) // Create a player instance. val player = ExoPlayer.Builder(context).build() // Set the media source to be played. player.setMediaSource(mediaSource) // Prepare the player. player.prepare()
Java
// Create a data source factory. DataSource.Factory dataSourceFactory = new DefaultHttpDataSource.Factory(); // Create a SmoothStreaming media source pointing to a manifest uri. MediaSource mediaSource = new SsMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(ssUri)); // Create a player instance. ExoPlayer player = new ExoPlayer.Builder(context).build(); // Set the media source to be played. player.setMediaSource(mediaSource); // Prepare the player. player.prepare();
การเข้าถึงไฟล์ Manifest
คุณสามารถเรียกไฟล์ Manifest ปัจจุบันโดยเรียก Player.getCurrentManifest
สำหรับ SmoothStreaming คุณควรแคสต์วัตถุที่แสดงผลไปยัง SsManifest
จะมีการเรียก Callback onTimelineChanged
ของ Player.Listener
เมื่อใดก็ตามที่
ระบบจะโหลดไฟล์ Manifest กรณีนี้จะเกิดขึ้นครั้งเดียวสำหรับเนื้อหาแบบออนดีมานด์และ
อาจหลายต่อหลายครั้งสำหรับเนื้อหาสด ข้อมูลโค้ดต่อไปนี้จะแสดงวิธีที่แอป
ทำอะไรบางอย่างได้ทุกครั้งที่ไฟล์ Manifest โหลดขึ้นมา
Kotlin
player.addListener( object : Player.Listener { override fun onTimelineChanged(timeline: Timeline, @TimelineChangeReason reason: Int) { val manifest = player.currentManifest if (manifest is SsManifest) { // Do something with the manifest. } } } )
Java
player.addListener( new Player.Listener() { @Override public void onTimelineChanged( Timeline timeline, @Player.TimelineChangeReason int reason) { Object manifest = player.getCurrentManifest(); if (manifest != null) { SsManifest ssManifest = (SsManifest) manifest; // Do something with the manifest. } } });
การปรับแต่งการเล่น
ExoPlayer มอบวิธีที่หลากหลายเพื่อให้คุณได้ปรับแต่งประสบการณ์การเล่นให้ตรงกับ ความต้องการของแอปได้ ดูตัวอย่างในหน้าการปรับแต่ง