สตรีมมิงแบบราบรื่น
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ExoPlayer รองรับ SmoothStreaming ด้วยรูปแบบคอนเทนเนอร์ FMP4 ต้องแยกสตรีมสื่อออก ซึ่งหมายความว่าต้องกำหนดวิดีโอ เสียง และข้อความในองค์ประกอบ StreamIndex ที่แตกต่างกันในไฟล์ Manifest ของ SmoothStreaming นอกจากนี้ ระบบยังต้องรองรับรูปแบบตัวอย่างเสียงและวิดีโอที่อยู่ในไฟล์ด้วย (ดูรายละเอียดในส่วนรูปแบบตัวอย่าง)
ฟีเจอร์ |
รองรับ |
ความคิดเห็น |
คอนเทนเนอร์ |
|
|
FMP4 |
ใช่ |
สตรีมที่แยกแล้วเท่านั้น |
คำบรรยาย/คำบรรยายแทนเสียง |
|
|
TTML |
ใช่ |
ฝังใน FMP4 |
การปกป้องเนื้อหา |
|
|
PlayReady SL2000 |
ใช่ |
Android TV เท่านั้น |
การเล่นสด |
|
|
การเล่นไลฟ์สดปกติ |
ใช่ |
|
ข้อมูลไคลเอ็นต์สื่อทั่วไป (CMCD) |
ใช่ |
คู่มือการผสานรวม |
หากต้องการเล่นสตรีม SmoothStreaming คุณต้องใช้โมดูล SmoothStreaming
Kotlin
implementation("androidx.media3:media3-exoplayer-smoothstreaming:1.8.0")
Groovy
implementation "androidx.media3:media3-exoplayer-smoothstreaming:1.8.0"
จากนั้นคุณจะสร้าง 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
และส่งไปยังเพลเยอร์โดยตรงแทน 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
ระบบจะเรียกใช้
onTimelineChanged
Callback ของ Player.Listener
ทุกครั้งที่โหลด
ไฟล์ Manifest การดำเนินการนี้จะเกิดขึ้น 1 ครั้งสำหรับเนื้อหาออนดีมานด์ และอาจเกิดขึ้นหลายครั้งสำหรับเนื้อหาแบบสด ข้อมูลโค้ดต่อไปนี้แสดงวิธีที่แอป
สามารถทำบางอย่างได้ทุกครั้งที่โหลดไฟล์ 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 มีหลายวิธีให้คุณปรับแต่งประสบการณ์การเล่นให้ตรงกับความต้องการของแอป
ดูตัวอย่างได้ที่หน้าการปรับแต่ง
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-27 UTC
[null,null,["อัปเดตล่าสุด 2025-08-27 UTC"],[],[],null,["# SmoothStreaming\n\nExoPlayer supports SmoothStreaming with the FMP4 container format. Media streams\nmust be demuxed, meaning that video, audio, and text must be defined in distinct\nStreamIndex elements in the SmoothStreaming manifest. The contained audio and\nvideo sample formats must also be supported (see the\n[sample formats](/media/media3/exoplayer/supported-formats#sample-formats) section for details).\n\n| Feature | Supported | Comments |\n|-------------------------------------|-----------|---------------------------------------------------------|\n| **Containers** | | |\n| FMP4 | YES | Demuxed streams only |\n| **Closed captions/subtitles** | | |\n| TTML | YES | Embedded in FMP4 |\n| **Content protection** | | |\n| PlayReady SL2000 | YES | Android TV only |\n| **Live playback** | | |\n| Regular live playback | YES | |\n| **Common Media Client Data (CMCD)** | YES | [Integration Guide](/guide/topics/media/exoplayer/cmcd) |\n\nUsing MediaItem\n---------------\n\nTo play a SmoothStreaming stream, you need to depend on the SmoothStreaming\nmodule. \n\n### Kotlin\n\n```kotlin\nimplementation(\"androidx.media3:media3-exoplayer-smoothstreaming:1.8.0\")\n```\n\n### Groovy\n\n```groovy\nimplementation \"androidx.media3:media3-exoplayer-smoothstreaming:1.8.0\"\n```\n\nYou can then create a `MediaItem` for a SmoothStreaming manifest URI and pass it\nto the player. \n\n### Kotlin\n\n```kotlin\n// Create a player instance.\nval player = ExoPlayer.Builder(context).build()\n// Set the media item to be played.\nplayer.setMediaItem(MediaItem.fromUri(ssUri))\n// Prepare the player.\nplayer.prepare()\n```\n\n### Java\n\n```java\n// Create a player instance.\nExoPlayer player = new ExoPlayer.Builder(context).build();\n// Set the media item to be played.\nplayer.setMediaItem(MediaItem.fromUri(ssUri));\n// Prepare the player.\nplayer.prepare();\n```\n\n\u003cbr /\u003e\n\nIf your URI doesn't end with `.ism/Manifest`, you can pass\n`MimeTypes.APPLICATION_SS` to `setMimeType` of `MediaItem.Builder` to explicitly\nindicate the type of the content.\n\nExoPlayer will automatically adapt between representations defined in the\nmanifest, taking into account both available bandwidth and device capabilities.\n\nUsing SsMediaSource\n-------------------\n\nFor more customization options, you can create a `SsMediaSource` and pass it\ndirectly to the player instead of a `MediaItem`. \n\n### Kotlin\n\n```kotlin\n// Create a data source factory.\nval dataSourceFactory: DataSource.Factory = DefaultHttpDataSource.Factory()\n// Create a SmoothStreaming media source pointing to a manifest uri.\nval mediaSource: MediaSource =\n SsMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(ssUri))\n// Create a player instance.\nval player = ExoPlayer.Builder(context).build()\n// Set the media source to be played.\nplayer.setMediaSource(mediaSource)\n// Prepare the player.\nplayer.prepare()\n```\n\n### Java\n\n```java\n// Create a data source factory.\nDataSource.Factory dataSourceFactory = new DefaultHttpDataSource.Factory();\n// Create a SmoothStreaming media source pointing to a manifest uri.\nMediaSource mediaSource =\n new SsMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(ssUri));\n// Create a player instance.\nExoPlayer player = new ExoPlayer.Builder(context).build();\n// Set the media source to be played.\nplayer.setMediaSource(mediaSource);\n// Prepare the player.\nplayer.prepare();\n```\n\n\u003cbr /\u003e\n\nAccessing the manifest\n----------------------\n\nYou can retrieve the current manifest by calling `Player.getCurrentManifest`.\nFor SmoothStreaming, you should cast the returned object to `SsManifest`. The\n`onTimelineChanged` callback of `Player.Listener` is also called whenever\nthe manifest is loaded. This will happen once for on-demand content and\npossibly many times for live content. The following code snippet shows how an app\ncan do something whenever the manifest is loaded. \n\n### Kotlin\n\n```kotlin\nplayer.addListener(\n object : Player.Listener {\n override fun onTimelineChanged(timeline: Timeline, @TimelineChangeReason reason: Int) {\n val manifest = player.currentManifest\n if (manifest is SsManifest) {\n // Do something with the manifest.\n }\n }\n }\n)\n```\n\n### Java\n\n```java\nplayer.addListener(\n new Player.Listener() {\n @Override\n public void onTimelineChanged(\n Timeline timeline, @Player.TimelineChangeReason int reason) {\n Object manifest = player.getCurrentManifest();\n if (manifest != null) {\n SsManifest ssManifest = (SsManifest) manifest;\n // Do something with the manifest.\n }\n }\n });\n```\n\n\u003cbr /\u003e\n\nCustomizing playback\n--------------------\n\nExoPlayer provides multiple ways for you to tailor playback experience to your\napp's needs. See the [Customization page](/guide/topics/media/exoplayer/customization) for examples."]]