Chromecast Android Sender RemoteMediaPlayer producing No current media session

前端 未结 2 585
礼貌的吻别
礼貌的吻别 2021-01-28 15:26

I have been able to successfully cast video to a Chromecast and have the option let the video play when disconnecting and it all works great. However, if I choose to quit the ap

2条回答
  •  爱一瞬间的悲伤
    2021-01-28 15:28

    As user3408864 pointed out, requestStatus() after rejoining the session works. Here is how i managed to solve it in my case and it should work in yours.

         if(MAIN_ACTIVITY.isConnected()){
    
                if(MAIN_ACTIVITY.mRemoteMediaPlayer == null){
                    MAIN_ACTIVITY.setRemoteMediaPlayer();
                }
    
                MAIN_ACTIVITY.mRemoteMediaPlayer.requestStatus(MAIN_ACTIVITY.mApiClient).setResultCallback( new ResultCallback() {
                    @Override 
                    public void onResult(RemoteMediaPlayer.MediaChannelResult mediaChannelResult) {
                        if(playToggle ==0){
    
                            try {
                                MAIN_ACTIVITY.mRemoteMediaPlayer.pause(MAIN_ACTIVITY.mApiClient);
                                playToggle =1;
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }else{
    
                            try {
                                MAIN_ACTIVITY.mRemoteMediaPlayer.play(MAIN_ACTIVITY.mApiClient);
                                playToggle =0;
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
    
                    }
                });
    
            }
    

    Ignore, MAIN_ACTIVITY, it is just a static reference to my activity since i run this piece of code from a Service. Also, setRemoteMediaPlayer() is a method where i create a new RemoteMediaPlayer() and attach the corresponding Listeners.

    Hopefully this helps. Also, sorry if any mistake, it is my first post to StackOverFlow.

提交回复
热议问题