ExoPlayer は、FMP4 コンテナ形式の SmoothStreaming をサポートしています。メディア ストリームはデマルチプレックスする必要があります。つまり、動画、音声、テキストは、SmoothStreaming マニフェストの個別の StreamIndex 要素で定義する必要があります。含まれる音声と動画のサンプル形式もサポートされている必要があります(詳細については、サンプル形式のセクションをご覧ください)。
| 機能 | サポート対象 | コメント |
|---|---|---|
| コンテナ | ||
| FMP4 | はい | デマルチプレックスされたストリームのみ |
| 字幕 | ||
| TTML | はい | FMP4 に埋め込み |
| コンテンツの保護 | ||
| PlayReady SL2000 | はい | Android TV のみ |
| ライブ再生 | ||
| 通常のライブ再生 | はい | |
| 共通メディア クライアント データ(CMCD) | はい | 統合ガイド |
MediaItem の使用
SmoothStreaming ストリームを再生するには、SmoothStreaming モジュールに依存する必要があります。
Kotlin
implementation("androidx.media3:media3-exoplayer-smoothstreaming:1.11.1")
Groovy
implementation "androidx.media3:media3-exoplayer-smoothstreaming:1.11.1"
その後、SmoothStreaming マニフェスト URI の MediaItem を作成して、プレーヤーに渡すことができます。
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 を MediaItem.Builder の setMimeType に渡して、コンテンツのタイプを明示的に示すことができます。
ExoPlayer は、利用可能な帯域幅とデバイスの機能の両方を考慮して、マニフェストで定義された表現を自動的に適応させます。
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();
マニフェストへのアクセス
現在のマニフェストを取得するには、Player.getCurrentManifest を呼び出します。SmoothStreaming の場合は、返されたオブジェクトを SsManifest にキャストする必要があります。Player.Listener の onTimelineChanged コールバックは、マニフェストが読み込まれるたびに呼び出されます。これは、オンデマンド コンテンツの場合は 1 回、ライブ コンテンツの場合は複数回発生する可能性があります。次のコード スニペットは、マニフェストが読み込まれるたびにアプリがなんらかの処理を行う方法を示しています。
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 には、アプリのニーズに合わせて再生エクスペリエンスをカスタマイズする方法が複数用意されています。例については、カスタマイズ ページをご覧ください。