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

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

機能 サポート対象 コメント
コンテナ
FMP4 デマルチプレックスされたストリームのみ
字幕
TTML FMP4 に埋め込まれている
コンテンツの保護
PlayReady SL2000 Android TV のみ
ライブ再生
通常のライブ再生
共通メディア クライアント データ(CMCD) 統合ガイド

MediaItem の使用

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

Kotlin

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

Groovy

implementation "androidx.media3:media3-exoplayer-smoothstreaming:1.7.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 で終わっていない場合は、MediaItem.BuildersetMimeTypeMimeTypes.APPLICATION_SS を渡して、コンテンツのタイプを明示的に示すことができます。

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.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 には、アプリのニーズに合わせて再生エクスペリエンスを調整するための複数の方法が用意されています。例については、カスタマイズ ページをご覧ください。