Cast对话框中的暂停按钮似乎无法正常工作。我注意到了与CastVideos-android示例应用程序相同的问题。有没有人解决这个问题?
答案 0 :(得分:2)
我遇到了完全相同的问题,我通过让classess扩展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);
}
简而言之,我将播放/暂停按钮绑定到UIMediaController。
答案 1 :(得分:0)
请更新您的Google Play服务。使用9.8.0时遇到同样的问题。更新到10.2.1,它已得到解决。