渐进式
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
ExoPlayer 可以直接播放采用以下容器格式的视频流。
所包含的音频和视频样本格式也必须受支持(请参阅
示例格式部分)。
如需映像容器和格式支持,请参阅
图片。
容器格式 |
支持 |
评论 |
MP4 |
是 |
|
M4A |
是 |
|
FMP4 |
是 |
|
WebM |
是 |
|
马特罗斯卡 |
是 |
|
MP3 |
是 |
有些视频流只能使用恒定比特率搜寻功能** |
奥格 |
是 |
包含 Vorbis、Opus 和 FLAC |
轮流 |
是 |
|
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 中要求使用),或
启用了 FLAC 的 FFmpeg 库)。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 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):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."]]