From 7c0f45c602357bb996e86eab536967a38911f42b Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:35:26 -0700 Subject: [PATCH] adding controls to exit pip or switch to background audio --- .../peertube/activity/VideoPlayActivity.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java index 14df78a..34af981 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -62,6 +62,8 @@ import androidx.fragment.app.FragmentManager; //import static net.schueller.peertube.helper.Constants.BACKGROUND_PLAY_PREF_KEY; +import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PAUSE; +import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_PLAY; import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_STOP; import static net.schueller.peertube.helper.Constants.BACKGROUND_AUDIO; import static net.schueller.peertube.helper.Constants.DEFAULT_THEME; @@ -397,4 +399,45 @@ public class VideoPlayActivity extends AppCompatActivity { setPictureInPictureParams(params); } + @RequiresApi(api = Build.VERSION_CODES.O) + public void changedToPipMode() { + FragmentManager fragmentManager = getSupportFragmentManager(); + VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); + + videoPlayerFragment.showControls(false); + //create custom actions + setActions(""); + + //setup receiver to handle customer actions + IntentFilter filter = new IntentFilter(); + filter.addAction(ACTION_STOP); + filter.addAction(ACTION_PAUSE); + filter.addAction(ACTION_PLAY); + filter.addAction((BACKGROUND_AUDIO)); + receiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (action.equals(ACTION_PAUSE)) { + videoPlayerFragment.pauseVideo(); + } + if (action.equals(ACTION_PLAY)) { + videoPlayerFragment.pauseToggle(); + } + + if (action.equals(BACKGROUND_AUDIO)) { + unregisterReceiver(receiver); + finish(); + } + if (action.equals(ACTION_STOP)) { + unregisterReceiver(receiver); + finishAndRemoveTask(); + } + } + }; + registerReceiver(receiver, filter); + + Log.v(TAG, "switched to pip "); + // videoPlayerFragment.useController(false); + } }