From 2bfc846ec0dadc1a280daed5f78264f9848e279d Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:32:19 -0700 Subject: [PATCH] adding controls to exit pip or switch to background audio --- .../peertube/activity/VideoPlayActivity.java | 28 +++++++++++++++++++ 1 file changed, 28 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 70e98fd..14df78a 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_STOP; +import static net.schueller.peertube.helper.Constants.BACKGROUND_AUDIO; import static net.schueller.peertube.helper.Constants.DEFAULT_THEME; import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; @@ -369,4 +371,30 @@ public class VideoPlayActivity extends AppCompatActivity { Log.v(TAG,"switched to normal"); } } + + @RequiresApi(api = Build.VERSION_CODES.O) + public void setActions(String actionCommand) { + + ArrayList actions = new ArrayList<>(); + + Intent actionIntent = new Intent(BACKGROUND_AUDIO); + PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0); + Icon icon = Icon.createWithResource(getApplicationContext(), android.R.drawable.stat_sys_speakerphone); + RemoteAction remoteAction = new RemoteAction(icon, "close pip", "from pip window custom command", pendingIntent); + actions.add(remoteAction); + + actionIntent = new Intent(ACTION_STOP); + pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0); + icon = Icon.createWithResource(getApplicationContext(), com.google.android.exoplayer2.ui.R.drawable.exo_notification_stop); + remoteAction = new RemoteAction(icon, "play", "stop the media", pendingIntent); + actions.add(remoteAction); + + //add custom actions to pip window + PictureInPictureParams params = + new PictureInPictureParams.Builder() + .setActions(actions) + .build(); + setPictureInPictureParams(params); + + } }