uamp icon indicating copy to clipboard operation
uamp copied to clipboard

"Playback stream current position (Stop casting)" question

Open pinicius opened this issue 11 years ago • 6 comments

Hi, can someone explain in which part or parts of the code the current position of the playback is updated? Because when change the playback (from remote to local), playback (CastPlayback) is not connected and returns the last known position, that is, the position that was received in the change from local playback to remote (assuming no pause action has been taken during remote playback)

I've revised the source code a lot but I don't understand why when the user stops casting, mPlayback.getCurrentStreamPosition() in switchToPlayback method, CastManager is connected. If method has been executed onDisconnected(), should not returns that CastManager is disconnected?

Thanks in advance.

pinicius avatar Nov 23 '15 17:11 pinicius

MusicService#switchToPlayer() first calls getCurrentStreamPosition() on the underlying playback CastPlayback in this case when switching to LocalPlayback before calling Playback#stop(). This position is then set on the new playback to switch to i.e LocalPlayback.

nageshs avatar Nov 23 '15 19:11 nageshs

Hi nageshs, I'm agree, but the point is that MusicService#switchToPlayer() method is called when castplayback is disconnected ( VideoCastConsumerImpl#onDisconnected() ), how can the CastManager is still connected?

Thanks

pinicius avatar Nov 23 '15 19:11 pinicius

Valid question! The isConnected() on VideoCastManager only indicates that it's connected to GooglePlayServices. So as long as the remoteMediaPlayer has not been removed it returns the position. Also the onDisconnected() callback is called before the api client is disconnected.

nageshs avatar Nov 23 '15 20:11 nageshs

Thanks for the explanation, nageshs. But I have one more question, in MusicService#onStartCommand() when has been received a stop casting command and castManager executes disconnect(), the Google Play Services connection does not break inmediately? Connection breaks when CastManager#removeVideoCastConsumer(CastConsumer) executes?

pinicius avatar Nov 23 '15 20:11 pinicius

The connection to Google Play Services only breaks/is disconnected when the underlying VideoCastManager calls mApiClient.disconnect(). The version of Cast Companion Library that is shipped with uAmp should work but thanks to your question, we were able to test it with the latest version of CCL.

The latest Cast Companion Library has been updated to disconnect the google api client and also the RemoteMediaPlayer (set to null) before the listeners receive a call to onDisconnected. Thanks to Ali (author of Cast Companion library), we have a better way to address this. In MusicService#mCastConsumer we add another method that is responsible for updating the current position.

    @Override
    public void onDisconnectionReason(int reason) {
        LogHelper.d(TAG, "onDisconnectedWithReason");
        // This is our final chance to update CastPlayback#setCurrentPosition(..)
        // In onDisconnected(), the underlying CastPlayback#mVideoCastConsumer
        // is disconnected and hence we update the mCurrentPosition to the latest position
        mPlayback.setCurrentStreamPosition(mPlayback.getCurrentStreamPosition());
    }

I will be updating the code with the latest CCL and the fix shortly.

-- Nagesh

nageshs avatar Nov 24 '15 05:11 nageshs

Your welcome, happy to contribute to your great work.

pinicius avatar Nov 24 '15 11:11 pinicius