暂停按钮在 Android 投射对话框中不起作用

Pause button not working in Android cast dialog

投射对话框中的暂停按钮似乎不起作用。我注意到 CastVideos-android 示例应用程序存在同样的问题。有人解决过这个问题吗?

我遇到了完全相同的问题,我通过制作扩展 MediaRouteDialogFactory、MediaRouteControllerDialogFragment 和 MediaRouteControllerDialog 的类来解决。


public class MyMediaRouteDialogFactory extends MediaRouteDialogFactory {
        @NonNull @Override
        public MediaRouteControllerDialogFragment onCreateControllerDialogFragment() {
           return new MyMediaControllerDialogFragment();
        }
    }

public class MyMediaControllerDialogFragment extends MediaRouteControllerDialogFragment {
    @Override public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(STYLE_NO_FRAME, android.R.style.Theme_NoTitleBar_Fullscreen);
    }

    @Override
    public MediaRouteControllerDialog onCreateControllerDialog(Context context, Bundle savedInstanceState) {
        return new MyMediaRouteControllerDialog(context);
    }
}

public class MyMediaRouteControllerDialog extends MediaRouteControllerDialog {
    public MyMediaRouteControllerDialog(Context context) {
        super(context);
    }

    public MyMediaRouteControllerDialog(Context context, int theme) {
        super(context, theme);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        if (window != null) {
            window.getAttributes().dimAmount = 0.5f;
            window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        }

        View playPause = findById(this, R.id.mr_control_play_pause);
        if (playPause != null && playPause instanceof ImageView && getOwnerActivity() != null) {
            UIMediaController mediaController = new UIMediaController(getOwnerActivity());
            mediaController.bindImageViewToPlayPauseToggle((ImageView) playPause, mPlayArrowDrawable, mPauseDrawable, mStopDrawable, null, false);
        }
    }

}


{
    // On initializing MediaRouteButton
    ((MediaRouteButton) mCastButton).setDialogFactory(new MyMediaRouteDialogFactory());
    CastButtonFactory.setUpMediaRouteButton(getActivity(), mCastButton);
}

简而言之,我将 play/pause 按钮绑定到 UIMediaController。

请更新您的 google 使用 9.8.0 播放 services.Faced 同样的问题。更新到10.2.1,已解决