Android Chromecast Companion Library - 字幕切换按钮

时间:2016-02-11 13:50:50

标签: android streaming video-streaming chromecast castcompanionlibrary

我使用Companion library将视频从我的应用投射到Chromecast。 有没有办法我可以添加字幕/隐藏字幕切换按钮,以便用户可以打开和关闭它们?

我正在阅读他们可以看到的documentation,如何设置字幕网址

 MediaTrack englishSubtitle = new MediaTrack.Builder(1 /* ID */,
MediaTrack.TYPE_TEXT)
  .setName("English Subtitle")
  .setSubtype(MediaTrack.SUBTYPE_SUBTITLE)
  .setContentId("https://some-url/caption_en.vtt")
  /* language is required for subtitle type but optional otherwise */
  .setLanguage("en-US")
  .build();

但是没有关于我应该在哪里处理显示/隐藏动作的文字。

您对我如何添加切换按钮和处理显示/隐藏操作有任何建议吗?

我正在使用正在使用投放库中的VideoCastManager的{​​{1}}。

这是我的VideoCastControllerActivity

CastConfiguration

我正在创建// Build a CastConfiguration object and initialize VideoCastManager CastConfiguration options = new CastConfiguration.Builder(MyAppConfig.CHROMECAST_APP_ID) .enableAutoReconnect() .enableCaptionManagement() .enableDebug() .enableLockScreen() .enableNotification() .enableWifiReconnection() .setCastControllerImmersive(true) .setLaunchOptions(false, Locale.getDefault()) .setNextPrevVisibilityPolicy(CastConfiguration.NEXT_PREV_VISIBILITY_POLICY_DISABLED) .addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_REWIND, false) .addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_PLAY_PAUSE, true) .addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_DISCONNECT, true) .setForwardStep(10) .build(); // Google Chrome Cast initialization of the VideoCastManager that is a helper class from the CasCompanionLibrary // that helps us deal with the flow of communicating with chromecast VideoCastManager. initialize(this, options) .setVolumeStep(MyAppConfig.VOLUME_INCREMENT);

MediaInfo

1 个答案:

答案 0 :(得分:1)

您需要执行以下操作:

  1. 确保您的MediaInfo项目包含曲目信息。

  2. 确保在设置中启用了曲目,并在配置CastVideoManager时启用曲目支持。

  3. 在您的活动中注册一个OnTracksSelectedListener监听器,以便在跟踪发生变化时,可以通知您的活动。

  4. 4.在活动中添加一个按钮,点击按钮后,调用如下方法。

    private void showTracksChooserDialog()
            throws TransientNetworkDisconnectionException, NoConnectionException {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        Fragment prev = getSupportFragmentManager().findFragmentByTag(DIALOG_TAG);
        if (prev != null) {
            transaction.remove(prev);
        }
        transaction.addToBackStack(null);
    
        // Create and show the dialog.
        TracksChooserDialog dialogFragment = TracksChooserDialog
                .newInstance(mCastManager.getRemoteMediaInformation());
        dialogFragment.show(transaction, DIALOG_TAG);
    }
    

    这将打开一个(片段)对话框,显示当前的文本和音轨,并允许用户选择一个。如果选择了一个并且在该对话框中按了“确定”,则会调用您在上一步中注册的侦听器,然后您可以在侦听器中启用该轨道。

    1. 确保在离开活动时删除监听器。