循序式掃描
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
採用下列容器格式的串流可直接由 ExoPlayer 播放。
此外,您也必須支援內含的音訊和影片樣本格式 (請參閱
範例格式一節)。
如需映像檔容器和格式支援,請參閱
圖片。
容器格式 |
支援 |
留言 |
MP4 |
是 |
|
M4A |
是 |
|
FMP4 |
是 |
|
WebM |
是 |
|
馬特羅斯卡 |
是 |
|
MP3 |
是 |
部分直播只能透過固定位元率跳轉播放** |
蛋 |
是 |
包含 Vorbis、Opus 和 FLAC |
WAV |
是 |
|
MPEG-TS |
是 |
|
MPEG-PS |
是 |
|
FLV |
是 |
無法搜尋* |
ADTS (AAC) |
是 |
只能透過固定位元率跳轉** |
FLAC |
是 |
使用 FLAC 程式庫或 ExoPlayer 程式庫中的 FLAC 擷取器*** |
AMR |
是 |
只能透過固定位元率跳轉** |
* 容器不提供中繼資料,因此無法搜尋。例如,
範例索引),方便媒體播放器有效率地執行跳轉。
如果需要跳轉,建議您採用更適當的容器格式。
** 這些擷取工具有 FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
標記
使用固定位元率假設啟用近似跳轉功能。這個
這項功能會預設為停用,以最簡單的方式啟用
功能,適用於支援此功能的擷取工具
DefaultExtractorsFactory.setConstantBitrateSeekingEnabled
,如上所述
這裡。
*** FLAC 程式庫的擷取器會輸出可處理的原始音訊
依據所有 API 級別的架構ExoPlayer 程式庫 FLAC 擷取器輸出內容
FLAC 音訊影格,因此必須使用 FLAC 解碼器,例如 MediaCodec
處理 FLAC 的解碼器 (須自 API 級別 27 起取得),或
FFmpeg 程式庫啟用 FLAC)。DefaultExtractorsFactory
會使用
擷取器 (如果應用程式使用 FLAC 程式庫建立)。
否則會使用 ExoPlayer 程式庫擷取器。
如要播放漸進式串流,請使用媒體 URI 建立 MediaItem
,然後傳遞
傳遞到播放器中
Kotlin
// Create a player instance.
val player = ExoPlayer.Builder(context).build()
// Set the media item to be played.
player.setMediaItem(MediaItem.fromUri(progressiveUri))
// 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(progressiveUri));
// Prepare the player.
player.prepare();
如需更多自訂選項,您可以建立 ProgressiveMediaSource
和
然後直接傳遞給播放器,而不是 MediaItem
。
Kotlin
// Create a data source factory.
val dataSourceFactory: DataSource.Factory = DefaultHttpDataSource.Factory()
// Create a progressive media source pointing to a stream uri.
val mediaSource: MediaSource =
ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(MediaItem.fromUri(progressiveUri))
// 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 progressive media source pointing to a stream uri.
MediaSource mediaSource =
new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(MediaItem.fromUri(progressiveUri));
// 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();
自訂播放方式
ExoPlayer 提供多種功能,您可以配合個人
對應用程式的需求而言如需示例,請參閱「自訂」頁面。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Progressive\n\nStreams in the following container formats can be played directly by ExoPlayer.\nThe contained audio and video sample formats must also be supported (see the\n[Sample formats](/media/media3/exoplayer/supported-formats#sample-formats) section for details).\nFor image container and format support, see\n[Images](/media/media3/exoplayer/images).\n\n| Container format | Supported | Comments |\n|------------------|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| MP4 | YES | |\n| M4A | YES | |\n| FMP4 | YES | |\n| WebM | YES | |\n| Matroska | YES | |\n| MP3 | YES | Some streams only seekable using constant bitrate seeking\\*\\* |\n| Ogg | YES | Containing Vorbis, Opus and FLAC |\n| WAV | YES | |\n| MPEG-TS | YES | |\n| MPEG-PS | YES | |\n| FLV | YES | Not seekable\\* |\n| ADTS (AAC) | YES | Only seekable using constant bitrate seeking\\*\\* |\n| FLAC | YES | Using the [FLAC library](https://github.com/androidx/media/tree/release/libraries/decoder_flac) or the FLAC extractor in the [ExoPlayer library](https://github.com/androidx/media/tree/release/libraries/exoplayer)\\*\\*\\* |\n| AMR | YES | Only seekable using constant bitrate seeking\\*\\* |\n\n\\* Seeking is unsupported because the container does not provide metadata (for example,\na sample index) to allow a media player to perform a seek in an efficient way.\nIf seeking is required, we suggest using a more appropriate container format.\n\n\\*\\* These extractors have `FLAG_ENABLE_CONSTANT_BITRATE_SEEKING` flags for\nenabling approximate seeking using a constant bitrate assumption. This\nfunctionality is not enabled by default. The simplest way to enable this\nfunctionality for all extractors that support it is to use\n`DefaultExtractorsFactory.setConstantBitrateSeekingEnabled`, as described\n[here](/media/media3/exoplayer/customization#enabling-constant-bitrate-seeking).\n\n\\*\\*\\* The [FLAC library](https://github.com/androidx/media/tree/release/libraries/decoder_flac) extractor outputs raw audio, which can be handled\nby the framework on all API levels. The [ExoPlayer library](https://github.com/androidx/media/tree/release/libraries/exoplayer) FLAC extractor outputs\nFLAC audio frames and so relies on having a FLAC decoder (for example, a `MediaCodec`\ndecoder that handles FLAC (required from API level 27), or the\n[FFmpeg library](https://github.com/androidx/media/tree/release/libraries/decoder_ffmpeg) with FLAC enabled). The `DefaultExtractorsFactory` uses the\nextension extractor if the application was built with the [FLAC library](https://github.com/androidx/media/tree/release/libraries/decoder_flac).\nOtherwise, it uses the [ExoPlayer library](https://github.com/androidx/media/tree/release/libraries/exoplayer) extractor.\n\nUsing MediaItem\n---------------\n\nTo play a progressive stream, create a `MediaItem` with the media URI and pass\nit to 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(progressiveUri))\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(progressiveUri));\n// Prepare the player.\nplayer.prepare();\n```\n\n\u003cbr /\u003e\n\nUsing ProgressiveMediaSource\n----------------------------\n\nFor more customization options, you can create a `ProgressiveMediaSource` and\npass it directly 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 progressive media source pointing to a stream uri.\nval mediaSource: MediaSource =\nProgressiveMediaSource.Factory(dataSourceFactory)\n .createMediaSource(MediaItem.fromUri(progressiveUri))\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 progressive media source pointing to a stream uri.\nMediaSource mediaSource =\n new ProgressiveMediaSource.Factory(dataSourceFactory)\n .createMediaSource(MediaItem.fromUri(progressiveUri));\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\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."]]