使用 Presentation 将屏幕流式传输到 chromecast

stream screen to chromecast using Presentation

我正在使用 com.android.support:appcompat-v7:21.0.3 开发一个使用 chromecast 将屏幕流式传输到电视的应用程序。

问题是当我检索 presentationDisplay 时它是空的! 我使用的是默认接收器应用程序,Chromecast 似乎不支持

MediaControlIntent.CATEGORY_LIVE_VIDEO

这是代码:

private void updatePresentation() {

        Log.d(TAG, "updatePresentation()");

        MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute();
        Display presentationDisplay = route != null ? route.getPresentationDisplay() : null;

        Log.d(TAG, "MediaRouter.RouteIngo: " + route.getName());

        if (presentationDisplay != null)
            Log.d(TAG, "presentationDisplay " + presentationDisplay.getName());
        else if (presentationDisplay == null)
            Log.d(TAG, "presentationDisplay is null");

        // Dismiss the current presentation if the display has changed.
        if (mPresentation != null && mPresentation.getDisplay() != presentationDisplay) {
            Log.i(TAG, "Dismissing presentation because the current route no longer "
                    + "has a presentation display.");
            mPresentation.dismiss();
            mPresentation = null;
        }

        // Show a new presentation if needed.
        if (mPresentation == null && presentationDisplay != null) {
            Log.i(TAG, "Showing presentation on display: " + presentationDisplay);
            mPresentation = new DemoPresentation(this, presentationDisplay);
            mPresentation.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog)
                {
                    if (mPresentation != null) mPresentation.dismiss();
                }
            });
            try {
                Log.d("mPresentation", "showing");
                mPresentation.show();
            } catch (WindowManager.InvalidDisplayException ex) {
                Log.w(TAG, "Couldn't show presentation!  Display was removed in "
                        + "the meantime.", ex);
                mPresentation = null;
            }
        }
    }

on my own nexus 10 i used Chromecast App to setup the chromecast device and on my nexsus 4 all happened automatically.

不,我指的不仅仅是 Chromecast 应用程序。

Chromecast 原生支持 Cast SDK 和 RemotePlaybackClient。它还支持作为外接显示器,可用于Presentation。但是,用户 必须手动 进入“设置”>“显示”>“投射屏幕”并选择 Chromecast。然后,您将获得屏幕镜像,并且 Presentation 将起作用。