2
votes

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
To see what is going on, I suggest three things: (1) Please hard-code the url of your stream in CastVideos-android app and see if that works. (2) You need to enable logging in chrome debugger session to see the logs; that will tell you what is going wrong, so it is very important to do that; follow instructions here: developers.google.com/cast/docs/debugging and make sure you run cast.receiver.logger.setLevelValue(cast.receiver.LoggerLevel.DEBUG); and (3) Make sure CORS is set for your streamsAli Naddaf
for (1) my streams are correct as if i play it on MXPlayer and then cast it, it works. for (2) tried everything and followed all steps, still no result on debugger, i run the same command, nothing happens and for (3) what are CORS and where do i need to set it for my streams?awaistoor
For (1), you didn't really answer what I had suggested. For (2), I am not sure what you mean by "nothing happens". Do you mean you see no logging at all or you don't see any log related to your problem? CORS is a requirement and you can learn about that on our developer site, see developers.google.com/cast/docs/player. Can you hare a stream?Ali Naddaf
Thankyou @AliNaddaf for keep replying me, i WAS unable to see anything on the debugger, but i just saw the 'shield' button and able to load the unsafe scripts, my debugger is now on thanks to you. Also, can you please tell me more about CORS, should i set the header of my api responses?awaistoor
CORS is an industry standard so you can read about it on the net. CORS headers should be added to the streams by the server that is providing the content (say CDNs, etc); to see if it is set up or not, do a "curl -v your_stream_url" and look at the header in the response; if you don't see a header like "Access-Control-Allow-Origin: *", then your stream is not set up with CORS headers and chromecast won't play it. The chrome debugger og should show what the issue is.Ali Naddaf

1 Answers

0
votes

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