当应用程序发送到后台时,ChromeCast通知不可见

时间:2017-02-28 12:56:45

标签: android chromecast google-cast

我想从我的应用中显示chromecast通知和锁定屏幕。目前我正在使用CastCampaignLibrary-android。根据示例应用在应用类中初始化CastConfigurationVideoCastManager

String applicationId = getString(R.string.app_id);
CastConfiguration options = new CastConfiguration.Builder(applicationId)
            .enableAutoReconnect()
            .enableDebug()
            .enableLockScreen()
            .enableNotification()
            .enableWifiReconnection()
            .setCastControllerImmersive(true)
            .setLaunchOptions(false, Locale.getDefault())
            .addNamespace(NAMESPACE)
            .setNextPrevVisibilityPolicy(CastConfiguration.NEXT_PREV_VISIBILITY_POLICY_DISABLED)
            .addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_PLAY_PAUSE, true)
            .addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_DISCONNECT, true)
            .build();

VideoCastManager.initialize(this, options);

AndroidManifest.xml

中添加了以下几行
    <receiver android:name="com.google.android.libraries.cast.companionlibrary.remotecontrol.VideoIntentReceiver" />

    <service android:name="com.google.android.libraries.cast.companionlibrary.notification.VideoCastNotificationService" />

    <service android:name="com.google.android.libraries.cast.companionlibrary.cast.reconnection.ReconnectionService" />

当应用程序发送到后台时未显示远程控制通知。不知道我的代码有什么问题。帮我解决这个问题。

MediaInfo初始化如下

MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);

    movieMetadata.putString(MediaMetadata.KEY_TITLE, mEpisode.getmName());
    movieMetadata.addImage(new WebImage(Uri.parse(mEpisode.getmBannerImageUrl())));
    movieMetadata.addImage(new WebImage(Uri.parse(mEpisode.getmBannerSmallImageUrl())));

    try {
        MediaInfo mediaInfo = new MediaInfo.Builder(mEpisode.getmName() + ":" + mEpisode.getId())
                .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
                .setContentType("video/mp4")
                .setMetadata(movieMetadata)
                .setCustomData(new JSONObject(customMessage))
                .build();

        mVideoManager.loadMedia(mediaInfo, false, 0);
    } catch (Exception e) {
        e.printStackTrace();
    }

注意:我正在使用CustomReceiver进行投射。

0 个答案:

没有答案