트랙

Android TV 앱이 서로 다른 오디오/텍스트 트랙을 여러 개 지원할 수 있습니다. 웹 수신기와 동일한 방식으로 언어 및 서라운드 사운드 설정을 지원합니다. 있습니다. 여러 트랙을 지원하고 트랙을 선택하려면 Android TV 앱에서 다음을 구현합니다.

트랙 정보 및 상태 제공

최상위 수준 MediaInfo님, 사용 가능한 MediaTracks 사용 MediaInfoModifier:

Kotlin
val mediaInfoModifier = CastReceiverContext.getInstance()
            .mediaManager.mediaStatusModifier.mediaInfoModifier

mediaInfoModifier.setMediaTracks(Arrays.asList(
    new MediaTrack.Builder(1, MediaTrack.TYPE_AUDIO)
        .setName("English")
        ...
        build(),
    new MediaTrack.Builder(2, MediaTrack.TYPE_AUDIO)
        .setName("Spanish")
        ...
        .build()
  ))
드림
<ph type="x-smartling-placeholder">
</ph>
자바
MediaInfoModifier mediaInfoModifier = CastReceiverContext.getInstance()
    .getMediaManager().getMediaStatusModifier().getMediaInfoModifier();

mediaInfoModifier.setMediaTracks(Arrays.asList(
    new MediaTrack.Builder(1, MediaTrack.TYPE_AUDIO)
        .setName("English")
        ...
        build(),
    new MediaTrack.Builder(2, MediaTrack.TYPE_AUDIO)
        .setName("Spanish")
        ...
        .build()
  ));

사용 MediaTracksModifier 드림 를 사용하여 현재 선택한 트랙을 반영합니다.

Kotlin
val mediaStatusModifier: MediaTracksModifier =
      CastReceiverContext.getInstance()
          .mediaManager.mediaStatusModifier.getMediaTracksModifer()

MediaTracksModifier.setActiveTrackIds(longArrayOf(1))
드림
<ph type="x-smartling-placeholder">
</ph>
자바
MediaTracksModifier mediaStatusModifier =
  CastReceiverContext.getInstance()
    .getMediaManager().getMediaStatusModifier().getMediaTracksModifer();

MediaTracksModifier.setActiveTrackIds(new long[]{1});

위 단계를 따르면 발신자 트랙 선택 대화상자에 올바른 상태가 됩니다

트랙 선택 처리

트랙 선택을 지원하려면 먼저 MediaStatus.COMMAND_EDIT_TRACKS 드림 지원되는 미디어 명령어로 MediaStatusModifier:

Kotlin
CastReceiverContext
    .getInstance()
    .getMediaManager()
    .getMediaStatusModifier()
    .setMediaCommandSupported(MediaStatus.COMMAND_EDIT_TRACKS, true)
드림
<ph type="x-smartling-placeholder">
</ph>
자바
CastReceiverContext
    .getInstance()
    .getMediaManager()
    .getMediaStatusModifier()
    .setMediaCommandSupported(MediaStatus.COMMAND_EDIT_TRACKS, true);

사용자가 발신자 측의 트랙 선택 대화상자에서 트랙을 선택하면 Android TV 앱이 선택된 트랙을 변경하라는 콜백을 수신합니다. 다음을 재정의하여 명령어 처리 MediaCommandCallback:

Kotlin
class MyMediaCommandCallback : MediaCommandCallback() {
  /** Text selection callback scoped to individual track types.  */
  override fun onSelectTracksByType(
        senderId: String?, type: Int, tracks: List
    ): Task {
    return Tasks.call {
        // Update the track selection in your app.
        if (type == MediaTrack.TYPE_TEXT) {
             mySelectTextTracks(tracks)
        } else if (type == MediaTrack.TYPE_AUDIO) {
             mySelectAudioTracks(tracks)
        }
        // Update the track selection in the modifier to be used in MediaStatus.
        // This is also scoped to the given track type.
        mediaStatusModifier.getMediaTracksModifier().setActiveTracksByType(
            type, tracks
        )
        null
    }
  }

  /** Callback for setting the text track style.  */
  override fun onSetTextTrackStyle(
        senderId: String?, textTrackStyle: TextTrackStyle
    ): Task {
    return Tasks.call {
        // Update the track style in your app.
        mySetTextTrackStyle(textTrackStyle)
        // Update the track style in the modifier.
        mediaStatusModifier.setTextTrackStyle(textTrackStyle)
        null
    }
  }

  // Override the following callback in case you want to handle the original
  // request. This is strongly not recommended.
  //
  // The default implementation automatically translates into
  // onSelectTracksByType() and onSetTextTrackStyle().
  override fun onEditTracksInfo(
    senderId: String?, editTracksInfoData: EditTracksInfoData
    ): Task {
       ...
  }

  // Override the following callback in case you want to handle the original
  // request. This is strongly not recommended.
  override fun onEditAudioTracks(
      senderId: String?, editAudioTracksData: EditAudioTracksData
    ): Task {
        ...
  }
}
드림
<ph type="x-smartling-placeholder">
</ph>
자바
public class MyMediaCommandCallback extends MediaCommandCallback {
  /** Text selection callback scoped to individual track types. */
  @Override
  public Task onSelectTracksByType(
    String senderId, int type, List tracks) {
    return Tasks.call(() -> {
      // Update the track selection in your app.
      if (type == MediaTrack.TYPE_TEXT) {
        mySelectTextTracks(tracks);
      } else if (type == MediaTrack.TYPE_AUDIO) {
        mySelectAudioTracks(tracks);
      }
      // Update the track selection in the modifier to be used in MediaStatus.
      // This is also scoped to the given track type.
      mediaStatusModifier.getMediaTracksModifier().setActiveTracksByType(
        type, tracks);
      return null;
    });
  }

  /** Callback for setting the text track style. */
  @Override
  public Task onSetTextTrackStyle(
    String senderId, TextTrackStyle textTrackStyle) {
    return Tasks.call(() -> {
      // Update the track style in your app.
      mySetTextTrackStyle(textTrackStyle);
      // Update the track style in the modifier.
      mediaStatusModifier.setTextTrackStyle(textTrackStyle);
      return null;
    });
  }

  // Override the following callback in case you want to handle the original
  // request. This is strongly not recommended.
  //
  // The default implementation automatically translates into
  // onSelectTracksByType() and onSetTextTrackStyle().
  @Override
  public Task onEditTracksInfo(
    String senderId, EditTracksInfoData editTracksInfoData) {
    ...
  }

  // Override the following callback in case you want to handle the original
  // request. This is strongly not recommended.
  @Override
  public Task onEditAudioTracks(
    String senderId, EditAudioTracksData editAudioTracksData) {
    ...
  }
}