Skip to content

Commit

Permalink
updated for ODP4
Browse files Browse the repository at this point in the history
  • Loading branch information
commonsguy committed Aug 7, 2017
1 parent b5a13c8 commit 2e51a61
Showing 1 changed file with 15 additions and 11 deletions.
Expand Up @@ -16,12 +16,14 @@

import android.app.Activity;
import android.app.PendingIntent;
import android.app.PictureInPictureArgs;
import android.app.PictureInPictureParams;
import android.app.RemoteAction;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.drawable.Icon;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Rational;
import android.view.View;
import android.widget.MediaController;
import android.widget.VideoView;
Expand All @@ -36,12 +38,12 @@ public class VideoPlayerActivity extends Activity
private static final int REQUEST_PLAY=REQUEST_PAUSE+1;
private static final String EXTRA_REQUEST="requestCode";
private static final String STATE_POSITION="position";
private final PictureInPictureArgs pipArgs=new PictureInPictureArgs();
private VideoView video;
private MediaController ctlr;
private View fab;
private int lastPosition;
private Intent current;
private Rational aspectRatio;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand Down Expand Up @@ -112,14 +114,14 @@ protected void onStop() {

@Override
public void onClick(View view) {
pipArgs.setAspectRatio((float) video.getWidth() / video.getHeight());
updateActions();
enterPictureInPictureMode(pipArgs);
aspectRatio=new Rational(video.getWidth(), video.getHeight());
enterPictureInPictureMode(updateActions());
}

@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode);
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode,
Configuration cfg) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, cfg);

fab.setVisibility(isInPictureInPictureMode ? View.GONE : View.VISIBLE);
}
Expand All @@ -135,7 +137,7 @@ else if (requestCode==REQUEST_PLAY) {
video.start();
}

updateActions();
setPictureInPictureParams(updateActions());
}

private void play() {
Expand All @@ -144,7 +146,7 @@ private void play() {
video.start();
}

private void updateActions() {
private PictureInPictureParams updateActions() {
ArrayList<RemoteAction> actions=new ArrayList<>();

if (video.isPlaying()) {
Expand All @@ -156,8 +158,10 @@ private void updateActions() {
R.drawable.ic_play_arrow_white_24dp, R.string.play, R.string.play_desc));
}

pipArgs.setActions(actions);
setPictureInPictureArgs(pipArgs);
return(new PictureInPictureParams.Builder()
.setAspectRatio(aspectRatio)
.setActions(actions)
.build());
}

private RemoteAction buildRemoteAction(int requestCode, int iconId,
Expand Down

0 comments on commit 2e51a61

Please sign in to comment.