Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

android - How to Make A Custom Cast MediaRouter Dialog

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

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"/>

and

if (mCastManager != null) {
    mediaRouteMenuItem = mCastManager.addMediaRouterButton(menu, R.id.media_route_menu_item);
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...