使用Presentation将屏幕流转换为chromecast

时间:2015-04-27 12:03:09

标签: android chromecast

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

问题是当我检索presentationDisplay时它是null! 我正在使用默认接收器应用程序,似乎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;
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

  

在我自己的nexus 10上,我使用Chromecast App来设置chromecast设备,在我的nexsus 4上,所有内容都自动发生。

不,我不是指Chromecast应用。

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