Ibrahim Iqbal Ibrahim Iqbal - 1 month ago 10
Android Question

Receiver application not getting closed when user click cast button to disconnect in android sender app

I've a custom receiver which works fine except one problem that is when user clicks "STOP CASTING" button on android sender application.

I've implemented Cast SDK v3.

The sender seems to be disconnected because next time when cast button is clicked it asks for the chromecast device to connect.

The problem is that the receiver doesn't stop playing video on TV, as if it has no idea about the sender been disconnected.

The documentation https://developers.google.com/cast/docs/android_sender_integrate#app_flow says that


  • When the user clicks on the Cast button to disconnect from the Cast
    device, the framework will disconnect the sender app from the
    receiver.



But this doesn't seem to work in my case.

Can anyone tell me what to do or what the solution might be for this issue?

Answer Source

I solved this issue by adding the following method to my custom receiver:

window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
        castReceiverManager.onSenderDisconnected = function(event) {
    console.log('Received Sender Disconnected event: ' + event.data);
    if (window.castReceiverManager.getSenders().length == 0) {
           window.close();
    }
};