gpt4 book ai didi

Android Chromecast Companion Library - 字幕切换按钮

转载 作者:行者123 更新时间:2023-11-29 01:23:35 27 4
gpt4 key购买 nike

我正在使用 Companion library用于将视频从我的应用转换到 Chromecast。有什么办法可以添加字幕/隐藏式字幕切换按钮,以便用户能够打开和关闭它们吗?

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

 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,它正在使用来自转换库的 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

MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
mediaMetadata.addImage(new WebImage(Uri.parse(MyAppConfigBase.IMAGE_API_ENDPOINT + movieVideoItem.getImages().getKeyart())));
mediaMetadata.addImage(new WebImage(Uri.parse(MyAppConfigBase.IMAGE_API_ENDPOINT + movieVideoItem.getImages().getKeyart())));
mediaMetadata.putString(MediaMetadata.KEY_TITLE, movieVideoItem.getTitle());
mediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, movieVideoItem.getDescription());
mediaMetadata.putString("movie-urls", url);
mediaMetadata.putString("content-type", movieVideoItem.getContent().getHighRes().getType());

MediaTrack englishSubtitle = new MediaTrack.Builder(1 /* ID */, MediaTrack.TYPE_TEXT)
.setName("English Subtitle")
.setSubtype(MediaTrack.SUBTYPE_CAPTIONS)
.setContentId(closedCaptionsUrl)
/* language is required for subtitle type but optional otherwise */
.setLanguage("en-US")
.build();

List tracks = new ArrayList();
tracks.add(englishSubtitle);

MediaInfo mediaInfo = new MediaInfo.Builder(url)
.setStreamDuration(movieVideoItem.getDuration())
.setStreamType(MediaInfo.STREAM_TYPE_NONE)
.setContentType(type)
.setMetadata(mediaMetadata)
.setMediaTracks(tracks)
.setCustomData(customData)
.build();

最佳答案

您需要执行以下操作:

  1. 确保您的 MediaInfo 项具有轨道信息。

  2. 确保在设置中启用轨道,并在配置 CastVideoManager 时启用对轨道的支持。

  3. 在您的 Activity 中注册一个 OnTracksSelectedListener 监听器,以便在轨道发生变化时通知您的 Activity 。

4.向您的 Activity 添加一个按钮,并在单击该按钮时调用如下方法。

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);
}

这将打开一个( fragment )对话框,显示当前文本和音轨并允许用户选择一个。 When one is selected and Ok is pressed in that dialog, the listener that you had registered in the previous step is called and then you can enable the track in your listener.

  1. 确保在离开 Activity 时移除监听器。

关于Android Chromecast Companion Library - 字幕切换按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35341172/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com