スムーズなストリーミング

ExoPlayer は、FMP4 コンテナ形式の SmoothStreaming をサポートしています。メディア ストリームは分離する必要があります。つまり、動画、音声、テキストは、SmoothStreaming マニフェスト内の個別の StreamIndex 要素で定義する必要があります。含まれている音声と動画のサンプル形式もサポートされている必要があります(詳細については、サンプル形式のセクションをご覧ください)。

機能 対応 コメント
コンテナ
FMP4 はい 分離ストリームのみ
字幕
TTML はい FMP4 に埋め込み
コンテンツの保護
PlayReady SL2000 はい Android TV のみ
ライブ再生
通常のライブ再生 はい
共通メディア クライアント データ(CMCD) はい 統合ガイド

MediaItem の使用

SmoothStreaming ストリームを再生するには、SmoothStreaming モジュールに依存する必要があります。

Kotlin

implementation("androidx.media3:media3-exoplayer-smoothstreaming:1.3.1")

Groovy

implementation "androidx.media3:media3-exoplayer-smoothstreaming:1.3.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_SSMediaItem.BuildersetMimeType に渡して、コンテンツのタイプを明示的に示すことができます。

ExoPlayer は、利用可能な帯域幅とデバイス機能の両方を考慮して、マニフェストで定義された表現を自動的に適応させます。

SsMediaSource の使用

その他のカスタマイズ オプションについては、MediaItem ではなく、SsMediaSource を作成してプレーヤーに直接渡すことができます。

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.ListeneronTimelineChanged コールバックが呼び出されます。これはオンデマンド コンテンツで 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 には、アプリのニーズに合わせて再生エクスペリエンスをカスタマイズするための複数の方法が用意されています。例については、カスタマイズのページをご覧ください。