Unable to play live stream on chromecast from andr

2019-07-11 21:29发布

问题:

I am using CastCompanionLibrary-android in my app and following CastVideos-android to play live streams on chromecast. Now the streaming of video works fine on my local player but when it comes to cast that video, it wont play. Rather it just show me my registered receiver app name and on sender app the VideoCastControllerActivity opens with only a loader which wont end. I have registered both my receiver app (Styled Media Receiver) and the device on Google chrome cast console. Also, I tried to debug the receiver app, it show nothing on the debugger or in console.

Here is the code snippet of my sender app:

private void initMediaRouter() {
    BaseCastManager.checkGooglePlayServices(this);
    mCastManager = VideoCastManager.getInstance();
    MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); //also tried MediaMetadata.MEDIA_TYPE_GENERIC
    mediaMetadata.putString(MediaMetadata.KEY_TITLE, channel.getChannelName());
    mediaMetadata.putString(MediaMetadata.KEY_SUBTITLE, channel.getCatName());
    info = new MediaInfo.Builder(channel.getHttpStream())
            .setMetadata(mediaMetadata)
            .setContentType("Video/*")
            .setStreamType(MediaInfo.STREAM_TYPE_LIVE)
            .build();
    castConsumer = new CastConsumer();

    mCastManager.addVideoCastConsumer(castConsumer);
}

this function is called on the player activity's OnCreate() function.

The Listener (I'm getting true value for wasLaunched param)

private class CastConsumer extends VideoCastConsumerImpl {
    @Override
    public void onApplicationConnected(ApplicationMetadata appMetadata, String sessionId, boolean wasLaunched) {
        mCastManager.startVideoCastControllerActivity(PlayerActivity.this, info, 0, true);
    }

}

And in the onCreate() function of Application:

String applicationId = getString(R.string.cast_app_id);
    CastConfiguration options = new CastConfiguration.Builder(applicationId)
            .enableAutoReconnect()
            .enableCaptionManagement()
            .enableDebug()
            .enableLockScreen()
            .enableNotification()
            .enableWifiReconnection()
            .setCastControllerImmersive(true)
            .setLaunchOptions(false, Locale.getDefault())
            .addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_PLAY_PAUSE, true)
            .addNotificationAction(CastConfiguration.NOTIFICATION_ACTION_DISCONNECT, true)
            .build();
    VideoCastManager.initialize(this, options);

can you please tell me where i am going wrong? Thanks.

回答1:

The content type might be an issue. Try properly setting it to something like video/mp4 if that's the case.