More tweaks to PIP mode restore.

This commit is contained in:
Akinwale Ariwodola 2020-05-24 20:29:11 +01:00
parent a051a73c2b
commit 65f5626aba
2 changed files with 30 additions and 12 deletions

View file

@ -2450,11 +2450,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
!startingFilePickerActivity && !startingFilePickerActivity &&
!startingSignInFlowActivity) { !startingSignInFlowActivity) {
enteringPIPMode = true; enteringPIPMode = true;
getSupportActionBar().hide();
findViewById(R.id.global_now_playing_card).setVisibility(View.GONE);
findViewById(R.id.pip_player).setVisibility(View.VISIBLE);
PictureInPictureParams params = new PictureInPictureParams.Builder().build(); PictureInPictureParams params = new PictureInPictureParams.Builder().build();
enterPictureInPictureMode(params); enterPictureInPictureMode(params);
return true; return true;

View file

@ -42,6 +42,7 @@ import androidx.webkit.WebViewFeature;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.github.chrisbanes.photoview.PhotoView; import com.github.chrisbanes.photoview.PhotoView;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.DefaultControlDispatcher;
import com.google.android.exoplayer2.ParserException; import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
@ -154,6 +155,7 @@ public class FileViewFragment extends BaseFragment implements
private boolean downloadInProgress; private boolean downloadInProgress;
private boolean downloadRequested; private boolean downloadRequested;
private boolean loadFilePending; private boolean loadFilePending;
private boolean isPlaying;
private boolean resolving; private boolean resolving;
private boolean initialFileLoadDone; private boolean initialFileLoadDone;
private Claim claim; private Claim claim;
@ -200,6 +202,7 @@ public class FileViewFragment extends BaseFragment implements
if (!playbackStarted) { if (!playbackStarted) {
logPlay(currentUrl, startTimeMillis); logPlay(currentUrl, startTimeMillis);
playbackStarted = true; playbackStarted = true;
isPlaying = true;
} }
renderTotalDuration(); renderTotalDuration();
scheduleElapsedPlayback(); scheduleElapsedPlayback();
@ -859,6 +862,14 @@ public class FileViewFragment extends BaseFragment implements
TextView textPlaybackSpeed = playerView.findViewById(R.id.player_playback_speed_label); TextView textPlaybackSpeed = playerView.findViewById(R.id.player_playback_speed_label);
textPlaybackSpeed.setText(DEFAULT_PLAYBACK_SPEED); textPlaybackSpeed.setText(DEFAULT_PLAYBACK_SPEED);
playerView.setControlDispatcher(new DefaultControlDispatcher() {
@Override
public boolean dispatchSetPlayWhenReady(Player player, boolean playWhenReady) {
isPlaying = playWhenReady;
return super.dispatchSetPlayWhenReady(player, playWhenReady);
}
});
playbackSpeedContainer.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { playbackSpeedContainer.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
@Override @Override
public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) { public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
@ -1119,7 +1130,7 @@ public class FileViewFragment extends BaseFragment implements
} }
if (claim.isPlayable() && MainActivity.appPlayer != null) { if (claim.isPlayable() && MainActivity.appPlayer != null) {
MainActivity.appPlayer.setPlayWhenReady(true); MainActivity.appPlayer.setPlayWhenReady(isPlaying);
} }
Helper.setViewVisibility(layoutLoadingState, View.GONE); Helper.setViewVisibility(layoutLoadingState, View.GONE);
@ -1887,8 +1898,10 @@ public class FileViewFragment extends BaseFragment implements
playbackStarted = false; playbackStarted = false;
startTimeMillis = 0; startTimeMillis = 0;
isPlaying = false;
if (MainActivity.appPlayer != null) { if (MainActivity.appPlayer != null) {
MainActivity.appPlayer.stop(true);
MainActivity.appPlayer.removeListener(fileViewPlayerListener); MainActivity.appPlayer.removeListener(fileViewPlayerListener);
PlaybackParameters params = new PlaybackParameters(1.0f); PlaybackParameters params = new PlaybackParameters(1.0f);
MainActivity.appPlayer.setPlaybackParameters(params); MainActivity.appPlayer.setPlaybackParameters(params);
@ -1896,16 +1909,26 @@ public class FileViewFragment extends BaseFragment implements
} }
private void showBuffering() { private void showBuffering() {
View view = getView(); View root = getView();
if (view != null) { if (root != null) {
view.findViewById(R.id.player_buffering_progress).setVisibility(View.VISIBLE); root.findViewById(R.id.player_buffering_progress).setVisibility(View.VISIBLE);
PlayerView playerView = root.findViewById(R.id.file_view_exoplayer_view);
playerView.findViewById(R.id.player_play_pause).setVisibility(View.INVISIBLE);
playerView.findViewById(R.id.player_skip_back_10).setVisibility(View.INVISIBLE);
playerView.findViewById(R.id.player_skip_forward_10).setVisibility(View.INVISIBLE);
} }
} }
private void hideBuffering() { private void hideBuffering() {
View view = getView(); View root = getView();
if (view != null) { if (root != null) {
view.findViewById(R.id.player_buffering_progress).setVisibility(View.INVISIBLE); root.findViewById(R.id.player_buffering_progress).setVisibility(View.INVISIBLE);
PlayerView playerView = root.findViewById(R.id.file_view_exoplayer_view);
playerView.findViewById(R.id.player_play_pause).setVisibility(View.VISIBLE);
playerView.findViewById(R.id.player_skip_back_10).setVisibility(View.VISIBLE);
playerView.findViewById(R.id.player_skip_forward_10).setVisibility(View.VISIBLE);
} }
} }