循序式掃描

採用下列容器格式的串流可直接由 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 程式庫擷取器。

使用 MediaItem

如要播放漸進式串流,請使用媒體 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

如需更多自訂選項,請建立 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 提供多種功能,您可以配合個人 對應用程式的需求而言如需示例,請參閱「自訂」頁面