Search code examples
androidchromecast

Chromecast mRemoteMediaClient throwing java.lang.IllegalStateException: No connection


I am working on Chrome-cast in android, I have migrate my Chrome-cast from SDKV2 to SDKV3. RemoteMediaClient Throwing 'java.lang.IllegalStateException: No connection' when I am loading queue.

-Exception raised in this line

mRemoteMediaClient.queueLoad(mediaQueueItem,     PlayerConstants.SONG_NUMBER, MediaStatus.REPEAT_MODE_REPEAT_OFF, null)
                    .setResultCallback(resultCallback);

Here is the condition when this exception raised:-
Connect to Chrome-cast and after connecting load mediaQueueItem in the queue and it will work smoothly first time, Now Stop casting (disconnect Chrome-cast from device) and then I again connecting to the cast it will connected without any issue but after connecting load the mediaQueueItem for casting then it raised this Exception.

Please help.


Solution

  • I Caught my mistake that I was doing in onSessionEnded() method.

    @Override
    public void onSessionEnded(CastSession session, int error)
    {
         mRemoteMediaClient = null;
         mCastSession = null;
    }
    

    I was assigning null to mRemoteMediaClient and mCastSession in onSessionEnded(). remove these two lines.

    mRemoteMediaClient = null;
    mCastSession = null;
    

    There should not assign null when session is ended or session is suspended.

    Hope it will help others.