本文介绍了如何制作自定义Cast MediaRouter对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在我的项目中使用CastCompanionLibrary.它运行良好,但是我需要自定义投射"按钮的行为.

I am currently using the CastCompanionLibrary in my project. It is working well, however I need to customize the behaviour of the Cast button.

当前,正在显示一个包含Cast设备的对话框按钮(这是预期的行为).同样,在投射时,会显示元数据和停止/开始按钮.我需要对此进行自定义.我不想显示停止/开始按钮.我该如何实现?

Currently, a dialog button containing the Cast devices is being shown (which is the expected behaviour). Also, when casting, the metadata and a stop/start button is shown. I need to customize this. I don't want to show the stop/start buttons. How can I achieve that?

这是我的代码的相关部分:

Here are the related parts of my code:

<item
    android:id="@+id/media_route_menu_item"
    android:title="Google Cast"
    compat:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
    compat:showAsAction="always"/>

if (mCastManager != null) {
    mediaRouteMenuItem = mCastManager.addMediaRouterButton(menu, R.id.media_route_menu_item);
}

推荐答案

您有两个选择.首先,请注意,在投射时,您可以以某种方式构建应用程序,以使当时停止投射的行为会导致本地播放,因此停止投射"按钮就足够了.如果只隐藏CCL提供的现有对话框的内容"区域,可以将布局文件"custom_media_route_controller_controls_dialog.xml"复制到您自己的项目中,然后隐藏所需的区域(不要删除任何组件)但将内容区域包装在简单的布局中并隐藏该布局).如果您希望拥有自己的,请遵循CCL的操作;通过覆盖onCreateControllerDialogFragment()扩展MediaRouteDialogFactory,并定义您自己的MediaRouteControllerDialog扩展(请参阅CCL中的com.google.android.libraries.cast.companionlibrary.cast.dialog.video包),最后扩展VideoCastManager并在那里覆盖getMediaRouteDialogFactory()返回自己的工厂.

You have a couple of options. First, you should note that when you are casting, you can build your app in a way that the act of stopping cast at that time would result in local playback so "stop casting" button should suffice. If you are fine with just hiding the "content" area of the existing dialog provided by CCL, you can copy the layout file "custom_media_route_controller_controls_dialog.xml" into your own project and just hide the area that you want (don't remove any components but wrap the content area in a simple layout and hide that layout). If you prefer to have your own, follow what CCL does; extend MediaRouteDialogFactory by overriding onCreateControllerDialogFragment(), and define your own extension of MediaRouteControllerDialog (see the package com.google.android.libraries.cast.companionlibrary.cast.dialog.video in CCL) and finally, extends VideoCastManager and override getMediaRouteDialogFactory() there to return your own factory.

这篇关于如何制作自定义Cast MediaRouter对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 18:11