I have an Android cordova app which has Exoplayer Media Session enabled, the player was not resuming after seeking on AndroidTV using Google Assistant.
So I tried to save the playWhenReady on the dispatchSetPlayWhenReady(which is called when Google Assistant is opened) in a local property wasPlaying, to check if it should resume after seeking (if it was playing before).
private class MyControlDispatcher implements ControlDispatcher {
private boolean wasPlaying = false;
@Override
public boolean dispatchSetPlayWhenReady(Player player, boolean playWhenReady) {
this.wasPlaying = player.getPlayWhenReady();
player.setPlayWhenReady(playWhenReady);
return true;
}
@Override
public boolean dispatchSeekTo(Player player, int windowIndex, long positionMs) {
if (this.wasPlaying) {
player.setPlayWhenReady(true);
}
player.seekTo(windowIndex, positionMs);
return true;
}
...
}
MyControlDispatcher myControlDispatcher = new MyControlDispatcher();
MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(mediaSession);
mediaSessionConnector.setControlDispatcher(myControlDispatcher);
That solved the initial problem, but then I have a problem when user pauses and then seeks, both using Google Assistant. It will save wasPlaying as true when user calls PAUSE command (on the dispatchSetPlayWhenReady when assistant is opened) and resume after seeking when it shouldn't.
So basically I need to somehow get the PAUSE command callback from google assistant so I can differentiate from the dispatchSetPlayWhenReady which is called when assistant is opened. And guarantee that wasPlaying is set to false when user calls PAUSE command and prevent it from resuming after seeking.