From 03a196c4910d7658b8ee083e1f8e4a5f128ee57d Mon Sep 17 00:00:00 2001 From: dhk2 Date: Tue, 30 Jun 2020 14:56:01 -0700 Subject: [PATCH 01/35] fixing duplicate controlelrs --- .../schueller/peertube/activity/VideoPlayActivity.java | 10 +++++++++- .../schueller/peertube/service/VideoPlayerService.java | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) 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 28e80ad..7015118 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -61,7 +61,7 @@ import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; public class VideoPlayActivity extends AppCompatActivity { private static final String TAG = "VideoPlayActivity"; - + private static boolean floatMode = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -112,6 +112,12 @@ public class VideoPlayActivity extends AppCompatActivity { VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) getSupportFragmentManager().findFragmentById(R.id.video_player_fragment); assert videoPlayerFragment != null; + Boolean killFloat=intent.getBooleanExtra("killFloat",false); + Log.e(TAG,killFloat.toString()+" "+floatMode); + if (killFloat && floatMode){ + finish(); + return; + } String videoUuid = intent.getStringExtra(VideoListActivity.EXTRA_VIDEOID); Log.v(TAG, "new intent click: " + videoUuid +" is trying to replace: "+videoPlayerFragment.getVideoUuid()); assert videoPlayerFragment != null; @@ -355,8 +361,10 @@ public class VideoPlayActivity extends AppCompatActivity { public void onPictureInPictureModeChanged (boolean isInPictureInPictureMode, Configuration newConfig) { if (isInPictureInPictureMode) { Log.v(TAG,"switched to pip "); + floatMode=true; } else { Log.v(TAG,"switched to normal"); + floatMode=false; } } } diff --git a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java index bb22505..6d9c9f9 100644 --- a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java +++ b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java @@ -239,6 +239,7 @@ public class VideoPlayerService extends Service { // don't show skip buttons in notification playerNotificationManager.setUseNavigationActions(false); + playerNotificationManager.setUseStopAction(true); playerNotificationManager.setNotificationListener( new PlayerNotificationManager.NotificationListener() { @@ -250,7 +251,10 @@ public class VideoPlayerService extends Service { @Override public void onNotificationCancelled(int notificationId) { Log.v(TAG, "onNotificationCancelled..."); - + Intent killFloatingWindow = new Intent(getApplicationContext(),VideoPlayActivity.class); + killFloatingWindow.putExtra("killFloat",true); + killFloatingWindow.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(killFloatingWindow); // TODO: only kill the notification if we no longer have a bound activity stopForeground(true); } From ae058167b6b58976f85f6793d0246bc1f5c7108c Mon Sep 17 00:00:00 2001 From: dhk2 Date: Wed, 1 Jul 2020 09:04:20 -0700 Subject: [PATCH 02/35] fixing duplicate controlelrs --- .../peertube/activity/VideoPlayActivity.java | 90 ++++++++++++++++--- .../fragment/VideoPlayerFragment.java | 5 +- .../schueller/peertube/helper/Constants.java | 1 + .../peertube/service/VideoPlayerService.java | 9 +- 4 files changed, 93 insertions(+), 12 deletions(-) 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 7015118..ba64f12 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -21,11 +21,16 @@ package net.schueller.peertube.activity; import android.annotation.SuppressLint; import android.app.AppOpsManager; +import android.app.PendingIntent; import android.app.PictureInPictureParams; +import android.app.RemoteAction; +import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.graphics.drawable.Icon; import android.os.Build; import android.os.Bundle; @@ -49,12 +54,16 @@ import net.schueller.peertube.fragment.VideoMetaDataFragment; import net.schueller.peertube.fragment.VideoPlayerFragment; import net.schueller.peertube.service.VideoPlayerService; -import java.util.Objects; +import java.util.ArrayList; 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; import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; @@ -62,7 +71,8 @@ public class VideoPlayActivity extends AppCompatActivity { private static final String TAG = "VideoPlayActivity"; private static boolean floatMode = false; - + private static final int REQUEST_CODE = 101; + private BroadcastReceiver receiver; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -112,12 +122,6 @@ public class VideoPlayActivity extends AppCompatActivity { VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) getSupportFragmentManager().findFragmentById(R.id.video_player_fragment); assert videoPlayerFragment != null; - Boolean killFloat=intent.getBooleanExtra("killFloat",false); - Log.e(TAG,killFloat.toString()+" "+floatMode); - if (killFloat && floatMode){ - finish(); - return; - } String videoUuid = intent.getStringExtra(VideoListActivity.EXTRA_VIDEOID); Log.v(TAG, "new intent click: " + videoUuid +" is trying to replace: "+videoPlayerFragment.getVideoUuid()); assert videoPlayerFragment != null; @@ -167,7 +171,7 @@ public class VideoPlayActivity extends AppCompatActivity { if (isLandscape) { assert videoPlayerFragment != null; - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) Objects.requireNonNull(videoPlayerFragment.getView()).getLayoutParams(); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) videoPlayerFragment.requireView().getLayoutParams(); params.width = FrameLayout.LayoutParams.MATCH_PARENT; params.height = FrameLayout.LayoutParams.MATCH_PARENT; videoPlayerFragment.getView().setLayoutParams(params); @@ -182,7 +186,7 @@ public class VideoPlayActivity extends AppCompatActivity { } else { assert videoPlayerFragment != null; - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) Objects.requireNonNull(videoPlayerFragment.getView()).getLayoutParams(); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) videoPlayerFragment.requireView().getLayoutParams(); params.width = FrameLayout.LayoutParams.MATCH_PARENT; params.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250, getResources().getDisplayMetrics()); videoPlayerFragment.getView().setLayoutParams(params); @@ -357,14 +361,80 @@ public class VideoPlayActivity extends AppCompatActivity { enterPictureInPictureMode(mParams); } + @RequiresApi(api = Build.VERSION_CODES.O) @Override public void onPictureInPictureModeChanged (boolean isInPictureInPictureMode, Configuration newConfig) { + VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) + getSupportFragmentManager().findFragmentById(R.id.video_player_fragment); + if (isInPictureInPictureMode) { + 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 "); floatMode=true; } else { + videoPlayerFragment.showControls(true); + if (receiver != null) { + unregisterReceiver(receiver); + } Log.v(TAG,"switched to normal"); floatMode=false; } } + + @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); + + } } diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java index a37af1c..ab0e4d1 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java @@ -264,10 +264,13 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL mService.player.setPlayWhenReady(!mService.player.getPlayWhenReady()); } } + public void showControls(boolean value){ + simpleExoPlayerView.setUseController(value); + } public void stopVideo() { if (mBound) { - Objects.requireNonNull(getContext()).unbindService(mConnection); + requireContext().unbindService(mConnection); mBound = false; } } diff --git a/app/src/main/java/net/schueller/peertube/helper/Constants.java b/app/src/main/java/net/schueller/peertube/helper/Constants.java index 729377f..0e87a3f 100644 --- a/app/src/main/java/net/schueller/peertube/helper/Constants.java +++ b/app/src/main/java/net/schueller/peertube/helper/Constants.java @@ -21,4 +21,5 @@ public class Constants { public static final String THEME_PREF_KEY = "pref_theme"; public static final String DEFAULT_THEME = "AppTheme.BLUE"; public static final String BACKGROUND_PLAY_PREF_KEY = "pref_background_play"; + public static final String BACKGROUND_AUDIO = "BACKGROUND_AUDIO"; } diff --git a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java index 6d9c9f9..a601af4 100644 --- a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java +++ b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java @@ -64,6 +64,7 @@ import net.schueller.peertube.model.Video; import static android.media.session.PlaybackState.ACTION_PAUSE; import static android.media.session.PlaybackState.ACTION_PLAY; +import static com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_STOP; import static net.schueller.peertube.activity.VideoListActivity.EXTRA_VIDEOID; public class VideoPlayerService extends Service { @@ -251,12 +252,18 @@ public class VideoPlayerService extends Service { @Override public void onNotificationCancelled(int notificationId) { Log.v(TAG, "onNotificationCancelled..."); + stopForeground(true); + Intent killFloat = new Intent(ACTION_STOP); + sendBroadcast(killFloat); + /* + Intent killFloat = new Intent(BROADCAST_ACTION); Intent killFloatingWindow = new Intent(getApplicationContext(),VideoPlayActivity.class); killFloatingWindow.putExtra("killFloat",true); - killFloatingWindow.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(killFloatingWindow); // TODO: only kill the notification if we no longer have a bound activity stopForeground(true); + */ } } ); From f04c64a60df3d0038f2acb13c8a8f83308057242 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 14:41:09 -0700 Subject: [PATCH 03/35] adding controls to exit pip or switch to background audio --- .../net/schueller/peertube/activity/VideoPlayActivity.java | 7 +++++-- .../schueller/peertube/fragment/VideoPlayerFragment.java | 2 +- app/src/main/res/layout/row_video.xml | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) 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 ba64f12..ba8c71e 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -70,6 +70,8 @@ import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; public class VideoPlayActivity extends AppCompatActivity { private static final String TAG = "VideoPlayActivity"; + + private static boolean floatMode = false; private static final int REQUEST_CODE = 101; private BroadcastReceiver receiver; @@ -171,7 +173,7 @@ public class VideoPlayActivity extends AppCompatActivity { if (isLandscape) { assert videoPlayerFragment != null; - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) videoPlayerFragment.requireView().getLayoutParams(); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) Objects.requireNonNull(videoPlayerFragment.getView()).getLayoutParams(); params.width = FrameLayout.LayoutParams.MATCH_PARENT; params.height = FrameLayout.LayoutParams.MATCH_PARENT; videoPlayerFragment.getView().setLayoutParams(params); @@ -186,7 +188,7 @@ public class VideoPlayActivity extends AppCompatActivity { } else { assert videoPlayerFragment != null; - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) videoPlayerFragment.requireView().getLayoutParams(); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) Objects.requireNonNull(videoPlayerFragment.getView()).getLayoutParams(); params.width = FrameLayout.LayoutParams.MATCH_PARENT; params.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250, getResources().getDisplayMetrics()); videoPlayerFragment.getView().setLayoutParams(params); @@ -388,6 +390,7 @@ public class VideoPlayActivity extends AppCompatActivity { if (action.equals(ACTION_PLAY)){ videoPlayerFragment.pauseToggle(); } + */ if (action.equals(BACKGROUND_AUDIO)) { unregisterReceiver(receiver); finish(); diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java index ab0e4d1..2c4140f 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java @@ -270,7 +270,7 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL public void stopVideo() { if (mBound) { - requireContext().unbindService(mConnection); + Objects.requireNonNull(getContext()).unbindService(mConnection); mBound = false; } } diff --git a/app/src/main/res/layout/row_video.xml b/app/src/main/res/layout/row_video.xml index afc2c1e..170c104 100644 --- a/app/src/main/res/layout/row_video.xml +++ b/app/src/main/res/layout/row_video.xml @@ -3,6 +3,7 @@ xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" + android:focusable="true" card_view:cardCornerRadius="0dp" card_view:cardElevation="0dp" card_view:contentPadding="0dp" From 61aa0e379ba60fef6cfb547e8da587504afb94e0 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 14:44:25 -0700 Subject: [PATCH 04/35] adding controls to exit pip or switch to background audio --- .../net/schueller/peertube/activity/VideoPlayActivity.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 ba8c71e..cd424dc 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -56,6 +56,8 @@ import net.schueller.peertube.service.VideoPlayerService; import java.util.ArrayList; +import java.util.Objects; + import androidx.fragment.app.FragmentManager; @@ -173,7 +175,7 @@ public class VideoPlayActivity extends AppCompatActivity { if (isLandscape) { assert videoPlayerFragment != null; - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) Objects.requireNonNull(videoPlayerFragment.getView()).getLayoutParams(); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) videoPlayerFragment.requireView().getLayoutParams(); params.width = FrameLayout.LayoutParams.MATCH_PARENT; params.height = FrameLayout.LayoutParams.MATCH_PARENT; videoPlayerFragment.getView().setLayoutParams(params); @@ -390,7 +392,7 @@ public class VideoPlayActivity extends AppCompatActivity { if (action.equals(ACTION_PLAY)){ videoPlayerFragment.pauseToggle(); } - */ + if (action.equals(BACKGROUND_AUDIO)) { unregisterReceiver(receiver); finish(); From 05595b7b4e854ef18230fdf1884a9b6c46424b8b Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 14:49:02 -0700 Subject: [PATCH 05/35] adding controls to exit pip or switch to background audio --- .../net/schueller/peertube/activity/VideoPlayActivity.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 cd424dc..6c16c75 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -175,7 +175,7 @@ public class VideoPlayActivity extends AppCompatActivity { if (isLandscape) { assert videoPlayerFragment != null; - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) videoPlayerFragment.requireView().getLayoutParams(); + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) Objects.requireNonNull(videoPlayerFragment.getView()).getLayoutParams(); params.width = FrameLayout.LayoutParams.MATCH_PARENT; params.height = FrameLayout.LayoutParams.MATCH_PARENT; videoPlayerFragment.getView().setLayoutParams(params); @@ -368,8 +368,8 @@ public class VideoPlayActivity extends AppCompatActivity { @RequiresApi(api = Build.VERSION_CODES.O) @Override public void onPictureInPictureModeChanged (boolean isInPictureInPictureMode, Configuration newConfig) { - VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) - getSupportFragmentManager().findFragmentById(R.id.video_player_fragment); + FragmentManager fragmentManager = getSupportFragmentManager(); + VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); if (isInPictureInPictureMode) { videoPlayerFragment.showControls(false); From a11a62ede47d4cee5eff3dfe2f2588507511b146 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:04:57 -0700 Subject: [PATCH 06/35] adding controls to exit pip or switch to background audio --- .../net/schueller/peertube/activity/VideoPlayActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 6c16c75..6d8ca33 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -406,14 +406,14 @@ public class VideoPlayActivity extends AppCompatActivity { registerReceiver(receiver, filter); Log.v(TAG,"switched to pip "); - floatMode=true; + // videoPlayerFragment.useController(false); } else { videoPlayerFragment.showControls(true); if (receiver != null) { unregisterReceiver(receiver); } Log.v(TAG,"switched to normal"); - floatMode=false; + // videoPlayerFragment.useController(true); } } From fb6462a67fd8ec53050869b14003783e693ca53a Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:17:31 -0700 Subject: [PATCH 07/35] adding controls to exit pip or switch to background audio --- .../peertube/activity/VideoPlayActivity.java | 99 ++++++++++--------- 1 file changed, 55 insertions(+), 44 deletions(-) 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 6d8ca33..db1dc13 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -368,52 +368,11 @@ public class VideoPlayActivity extends AppCompatActivity { @RequiresApi(api = Build.VERSION_CODES.O) @Override public void onPictureInPictureModeChanged (boolean isInPictureInPictureMode, Configuration newConfig) { - FragmentManager fragmentManager = getSupportFragmentManager(); - VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); + if (isInPictureInPictureMode) { + changedToPipMode(); - if (isInPictureInPictureMode) { - 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); } else { - videoPlayerFragment.showControls(true); - if (receiver != null) { - unregisterReceiver(receiver); - } - Log.v(TAG,"switched to normal"); - // videoPlayerFragment.useController(true); + } } @@ -442,4 +401,56 @@ public class VideoPlayActivity extends AppCompatActivity { setPictureInPictureParams(params); } + 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); + } + public void changedToNormalMode(){ + FragmentManager fragmentManager = getSupportFragmentManager(); + VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); + + videoPlayerFragment.showControls(true); + if (receiver != null) { + unregisterReceiver(receiver); + } + Log.v(TAG,"switched to normal"); + // videoPlayerFragment.useController(true); + } } + From c4da2a53692eb44171364228ff8b9f9a9f58917f Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:22:12 -0700 Subject: [PATCH 08/35] adding controls to exit pip or switch to background audio --- .../peertube/activity/VideoPlayActivity.java | 100 +----------------- 1 file changed, 3 insertions(+), 97 deletions(-) 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 db1dc13..28e80ad 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -21,16 +21,11 @@ package net.schueller.peertube.activity; import android.annotation.SuppressLint; import android.app.AppOpsManager; -import android.app.PendingIntent; import android.app.PictureInPictureParams; -import android.app.RemoteAction; -import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.res.Configuration; -import android.graphics.drawable.Icon; import android.os.Build; import android.os.Bundle; @@ -54,18 +49,12 @@ import net.schueller.peertube.fragment.VideoMetaDataFragment; import net.schueller.peertube.fragment.VideoPlayerFragment; import net.schueller.peertube.service.VideoPlayerService; - -import java.util.ArrayList; import java.util.Objects; 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; import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; @@ -74,9 +63,6 @@ public class VideoPlayActivity extends AppCompatActivity { private static final String TAG = "VideoPlayActivity"; - private static boolean floatMode = false; - private static final int REQUEST_CODE = 101; - private BroadcastReceiver receiver; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -365,92 +351,12 @@ public class VideoPlayActivity extends AppCompatActivity { enterPictureInPictureMode(mParams); } - @RequiresApi(api = Build.VERSION_CODES.O) @Override public void onPictureInPictureModeChanged (boolean isInPictureInPictureMode, Configuration newConfig) { - if (isInPictureInPictureMode) { - changedToPipMode(); - + if (isInPictureInPictureMode) { + Log.v(TAG,"switched to pip "); } else { - + 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); - - } - 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); - } - public void changedToNormalMode(){ - FragmentManager fragmentManager = getSupportFragmentManager(); - VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); - - videoPlayerFragment.showControls(true); - if (receiver != null) { - unregisterReceiver(receiver); - } - Log.v(TAG,"switched to normal"); - // videoPlayerFragment.useController(true); - } } - From 35742c656e3d40e516f9db6e10f7326d82acb7ae Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:23:42 -0700 Subject: [PATCH 09/35] adding controls to exit pip or switch to background audio --- .../net/schueller/peertube/activity/VideoPlayActivity.java | 7 +++++++ 1 file changed, 7 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 28e80ad..a55de18 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -21,11 +21,16 @@ package net.schueller.peertube.activity; import android.annotation.SuppressLint; import android.app.AppOpsManager; +import android.app.PendingIntent; import android.app.PictureInPictureParams; +import android.app.RemoteAction; +import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.graphics.drawable.Icon; import android.os.Build; import android.os.Bundle; @@ -49,6 +54,8 @@ import net.schueller.peertube.fragment.VideoMetaDataFragment; import net.schueller.peertube.fragment.VideoPlayerFragment; import net.schueller.peertube.service.VideoPlayerService; + +import java.util.ArrayList; import java.util.Objects; import androidx.fragment.app.FragmentManager; From dd455de9557c4392adaf491c8de961675bb3039e Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:28:03 -0700 Subject: [PATCH 10/35] adding controls to exit pip or switch to background audio --- .../net/schueller/peertube/activity/VideoPlayActivity.java | 3 +++ 1 file changed, 3 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 a55de18..70e98fd 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -69,6 +69,9 @@ public class VideoPlayActivity extends AppCompatActivity { private static final String TAG = "VideoPlayActivity"; + private static boolean floatMode = false; + private static final int REQUEST_CODE = 101; + private BroadcastReceiver receiver; @Override protected void onCreate(Bundle savedInstanceState) { From 2bfc846ec0dadc1a280daed5f78264f9848e279d Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:32:19 -0700 Subject: [PATCH 11/35] 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); + + } } From 7c0f45c602357bb996e86eab536967a38911f42b Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:35:26 -0700 Subject: [PATCH 12/35] 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); + } } From f6cfe248f415b65f30bb89296b7d21fbabd5d474 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:38:41 -0700 Subject: [PATCH 13/35] adding controls to exit pip or switch to background audio --- .../java/net/schueller/peertube/activity/VideoPlayActivity.java | 1 - 1 file changed, 1 deletion(-) 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 34af981..09482b0 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -399,7 +399,6 @@ 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); From b7fc1b02a3480d6a2033273a5a6dc2f230de92b2 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:40:12 -0700 Subject: [PATCH 14/35] adding controls to exit pip or switch to background audio --- .../peertube/activity/VideoPlayActivity.java | 43 +------------------ 1 file changed, 1 insertion(+), 42 deletions(-) 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 09482b0..5c7e09f 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -62,8 +62,6 @@ 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; @@ -399,44 +397,5 @@ public class VideoPlayActivity extends AppCompatActivity { setPictureInPictureParams(params); } - 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); - } + } From bec85eab89e332add7578b162e714e7906dcb541 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:41:42 -0700 Subject: [PATCH 15/35] adding controls to exit pip or switch to background audio --- .../java/net/schueller/peertube/activity/VideoPlayActivity.java | 1 - 1 file changed, 1 deletion(-) 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 5c7e09f..14df78a 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -397,5 +397,4 @@ public class VideoPlayActivity extends AppCompatActivity { setPictureInPictureParams(params); } - } From 33779e10a1e7c34a41710a098e7d664d9dab78c6 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:43:13 -0700 Subject: [PATCH 16/35] adding controls to exit pip or switch to background audio --- .../peertube/activity/VideoPlayActivity.java | 25 ------------------- 1 file changed, 25 deletions(-) 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..aec6dad 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -372,29 +372,4 @@ public class VideoPlayActivity extends AppCompatActivity { } } - @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); - - } } From 71bc325d49f427386f126519fa4cfafa15682edb Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:44:22 -0700 Subject: [PATCH 17/35] adding controls to exit pip or switch to background audio --- .../peertube/activity/VideoPlayActivity.java | 23 +++++++++++++++++++ 1 file changed, 23 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 aec6dad..779afea 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -74,7 +74,30 @@ public class VideoPlayActivity extends AppCompatActivity { private static boolean floatMode = false; private static final int REQUEST_CODE = 101; private BroadcastReceiver receiver; + 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); + + } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); From 76b3ddcf6947c6327fbd8d19a509f4bff33a0717 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:47:20 -0700 Subject: [PATCH 18/35] adding controls to exit pip or switch to background audio --- .../net/schueller/peertube/activity/VideoPlayActivity.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 779afea..c890b91 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -74,14 +74,16 @@ public class VideoPlayActivity extends AppCompatActivity { private static boolean floatMode = false; private static final int REQUEST_CODE = 101; private BroadcastReceiver receiver; + //This can only be called when in entering pip mode which can only happen on a high enough level to support pip mode. + @SuppressLint("NewApi") 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); + @SuppressLint("NewApi") Icon icon = Icon.createWithResource(getApplicationContext(), android.R.drawable.stat_sys_speakerphone); + @SuppressLint("NewApi") RemoteAction remoteAction = new RemoteAction(icon, "close pip", "from pip window custom command", pendingIntent); actions.add(remoteAction); actionIntent = new Intent(ACTION_STOP); From 81e92a421a74c2d4edc14eb3fed9264e7da1b82b Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:50:54 -0700 Subject: [PATCH 19/35] 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 c890b91..608b653 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; @@ -100,6 +102,46 @@ public class VideoPlayActivity extends AppCompatActivity { setPictureInPictureParams(params); } + 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); + } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -391,6 +433,7 @@ public class VideoPlayActivity extends AppCompatActivity { @Override public void onPictureInPictureModeChanged (boolean isInPictureInPictureMode, Configuration newConfig) { if (isInPictureInPictureMode) { + changedToPipMode(); Log.v(TAG,"switched to pip "); } else { Log.v(TAG,"switched to normal"); From c05c67e7f8fb78dd5810dd3dea59546e1a2b7b60 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 15:53:38 -0700 Subject: [PATCH 20/35] adding controls to exit pip or switch to background audio --- .../peertube/activity/VideoPlayActivity.java | 12 ++++++++++++ 1 file changed, 12 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 608b653..091a6f0 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -142,6 +142,17 @@ public class VideoPlayActivity extends AppCompatActivity { Log.v(TAG, "switched to pip "); // videoPlayerFragment.useController(false); } + public void changedToNormalMode(){ + FragmentManager fragmentManager = getSupportFragmentManager(); + VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); + + videoPlayerFragment.showControls(true); + if (receiver != null) { + unregisterReceiver(receiver); + } + Log.v(TAG,"switched to normal"); + // videoPlayerFragment.useController(true); + } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -436,6 +447,7 @@ public class VideoPlayActivity extends AppCompatActivity { changedToPipMode(); Log.v(TAG,"switched to pip "); } else { + changedToNormalMode(); Log.v(TAG,"switched to normal"); } } From fabb8a6d792de630c19b5b24c1a64511c71b1b44 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 16:00:29 -0700 Subject: [PATCH 21/35] adding controls to exit pip or switch to background audio --- .../schueller/peertube/service/VideoPlayerService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java index a601af4..fbfc033 100644 --- a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java +++ b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java @@ -131,8 +131,13 @@ public class VideoPlayerService extends Service { playerNotificationManager.setPlayer(null); } //Was seeing an error when exiting the program about about not unregistering the receiver. - if (null!=myNoisyAudioStreamReceiver) { - this.unregisterReceiver(myNoisyAudioStreamReceiver); + //Null check is insufficient to determine if it's been registered + try { + if (null!=myNoisyAudioStreamReceiver) { + this.unregisterReceiver(myNoisyAudioStreamReceiver); + } + } catch (Exception e) { + Log.e(TAG,"attempted to unregister a nonregistered noisy audio service"); } if (player != null) { player.release(); From 6995d9fde61ac761c2192d33e4af64d764dc25a3 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 16:02:57 -0700 Subject: [PATCH 22/35] adding controls to exit pip or switch to background audio --- .../net/schueller/peertube/activity/VideoPlayActivity.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 091a6f0..71b8924 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -76,7 +76,7 @@ public class VideoPlayActivity extends AppCompatActivity { private static boolean floatMode = false; private static final int REQUEST_CODE = 101; private BroadcastReceiver receiver; - //This can only be called when in entering pip mode which can only happen on a high enough level to support pip mode. + //This can only be called when in entering pip mode which can't happen if the device doesn't support pip mode. @SuppressLint("NewApi") public void setActions(String actionCommand) { @@ -84,8 +84,8 @@ public class VideoPlayActivity extends AppCompatActivity { Intent actionIntent = new Intent(BACKGROUND_AUDIO); PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0); - @SuppressLint("NewApi") Icon icon = Icon.createWithResource(getApplicationContext(), android.R.drawable.stat_sys_speakerphone); - @SuppressLint("NewApi") RemoteAction remoteAction = new RemoteAction(icon, "close pip", "from pip window custom command", pendingIntent); + @SuppressLint({"NewApi", "LocalSuppress"}) Icon icon = Icon.createWithResource(getApplicationContext(), android.R.drawable.stat_sys_speakerphone); + @SuppressLint({"NewApi", "LocalSuppress"}) RemoteAction remoteAction = new RemoteAction(icon, "close pip", "from pip window custom command", pendingIntent); actions.add(remoteAction); actionIntent = new Intent(ACTION_STOP); From 42ce468b31b1711c65d88afdeacbf1fa637a3f9a Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 16:06:14 -0700 Subject: [PATCH 23/35] Trying to assuage gits conflict adverse attitude --- .../peertube/service/VideoPlayerService.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java index fbfc033..cc7823c 100644 --- a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java +++ b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java @@ -131,13 +131,11 @@ public class VideoPlayerService extends Service { playerNotificationManager.setPlayer(null); } //Was seeing an error when exiting the program about about not unregistering the receiver. - //Null check is insufficient to determine if it's been registered - try { - if (null!=myNoisyAudioStreamReceiver) { - this.unregisterReceiver(myNoisyAudioStreamReceiver); - } - } catch (Exception e) { - Log.e(TAG,"attempted to unregister a nonregistered noisy audio service"); + //TODO figure out how to stop this from crashing sometimes when the non null service is still not registered + // try catch fixes it but GIT considers that an unacceptable change to the code + + if (null!=myNoisyAudioStreamReceiver) { + this.unregisterReceiver(myNoisyAudioStreamReceiver); } if (player != null) { player.release(); From 46f6cf51698deae4c4352f054d1816d5a7e1b05b Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 16:08:05 -0700 Subject: [PATCH 24/35] Trying to assuage gits conflict adverse attitude --- .../net/schueller/peertube/service/VideoPlayerService.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java index cc7823c..a601af4 100644 --- a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java +++ b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java @@ -131,9 +131,6 @@ public class VideoPlayerService extends Service { playerNotificationManager.setPlayer(null); } //Was seeing an error when exiting the program about about not unregistering the receiver. - //TODO figure out how to stop this from crashing sometimes when the non null service is still not registered - // try catch fixes it but GIT considers that an unacceptable change to the code - if (null!=myNoisyAudioStreamReceiver) { this.unregisterReceiver(myNoisyAudioStreamReceiver); } From 63469d12beeb2ddec87e9bd20b96b0959aeda91e Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 16:15:15 -0700 Subject: [PATCH 25/35] Trying to assuage gits conflict adverse attitude --- .../java/net/schueller/peertube/activity/VideoPlayActivity.java | 2 ++ 1 file changed, 2 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 71b8924..479b5ea 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -140,6 +140,7 @@ public class VideoPlayActivity extends AppCompatActivity { registerReceiver(receiver, filter); Log.v(TAG, "switched to pip "); + floatMode=true; // videoPlayerFragment.useController(false); } public void changedToNormalMode(){ @@ -151,6 +152,7 @@ public class VideoPlayActivity extends AppCompatActivity { unregisterReceiver(receiver); } Log.v(TAG,"switched to normal"); + floatMode=false; // videoPlayerFragment.useController(true); } @Override From 9d1ffd77c36b4137736ab3a847c2356dfdaecdba Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 20:09:33 -0700 Subject: [PATCH 26/35] Trying to assuage gits conflict adverse attitude --- .../peertube/activity/VideoPlayActivity.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) 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 479b5ea..d5c9a1a 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -78,7 +78,9 @@ public class VideoPlayActivity extends AppCompatActivity { private BroadcastReceiver receiver; //This can only be called when in entering pip mode which can't happen if the device doesn't support pip mode. @SuppressLint("NewApi") - public void setActions(String actionCommand) { + public void makePipControls() { + FragmentManager fragmentManager = getSupportFragmentManager(); + VideoPlayerFragment videoPlayerFragment = (VideoPlayerFragment) fragmentManager.findFragmentById(R.id.video_player_fragment); ArrayList actions = new ArrayList<>(); @@ -94,6 +96,23 @@ public class VideoPlayActivity extends AppCompatActivity { remoteAction = new RemoteAction(icon, "play", "stop the media", pendingIntent); actions.add(remoteAction); + if (videoPlayerFragment.isPaused()){ + Log.e(TAG,"setting actions with play button"); + actionIntent = new Intent(ACTION_PLAY); + pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0); + icon = Icon.createWithResource(getApplicationContext(), com.google.android.exoplayer2.ui.R.drawable.exo_notification_play); + remoteAction = new RemoteAction(icon, "play", "play the media", pendingIntent); + actions.add(remoteAction); + } else { + Log.e(TAG,"setting actions with pause button"); + actionIntent = new Intent(ACTION_PAUSE); + pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, actionIntent, 0); + icon = Icon.createWithResource(getApplicationContext(), com.google.android.exoplayer2.ui.R.drawable.exo_notification_pause); + remoteAction = new RemoteAction(icon, "pause", "pause the media", pendingIntent); + actions.add(remoteAction); + } + + //add custom actions to pip window PictureInPictureParams params = new PictureInPictureParams.Builder() @@ -108,7 +127,7 @@ public class VideoPlayActivity extends AppCompatActivity { videoPlayerFragment.showControls(false); //create custom actions - setActions(""); + makePipControls(); //setup receiver to handle customer actions IntentFilter filter = new IntentFilter(); @@ -122,9 +141,11 @@ public class VideoPlayActivity extends AppCompatActivity { String action = intent.getAction(); if (action.equals(ACTION_PAUSE)) { videoPlayerFragment.pauseVideo(); + makePipControls(); } if (action.equals(ACTION_PLAY)) { - videoPlayerFragment.pauseToggle(); + videoPlayerFragment.unPauseVideo(); + makePipControls(); } if (action.equals(BACKGROUND_AUDIO)) { @@ -141,7 +162,7 @@ public class VideoPlayActivity extends AppCompatActivity { Log.v(TAG, "switched to pip "); floatMode=true; - // videoPlayerFragment.useController(false); + videoPlayerFragment.showControls(false); } public void changedToNormalMode(){ FragmentManager fragmentManager = getSupportFragmentManager(); @@ -153,7 +174,6 @@ public class VideoPlayActivity extends AppCompatActivity { } Log.v(TAG,"switched to normal"); floatMode=false; - // videoPlayerFragment.useController(true); } @Override protected void onCreate(Bundle savedInstanceState) { From a99e9978de2fcb93bb82e77fc0a60cdbf5c4f871 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 20:33:14 -0700 Subject: [PATCH 27/35] Fixing unregister error for noisy audio --- .../schueller/peertube/fragment/VideoPlayerFragment.java | 7 +++++-- .../schueller/peertube/service/VideoPlayerService.java | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java index 2c4140f..08e4275 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java @@ -259,11 +259,14 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL mService.player.setPlayWhenReady(false); } } - public void pauseToggle() { + public void unPauseVideo() { if (mBound) { - mService.player.setPlayWhenReady(!mService.player.getPlayWhenReady()); + mService.player.setPlayWhenReady(true); } } + public boolean isPaused(){ + return !mService.player.getPlayWhenReady(); + } public void showControls(boolean value){ simpleExoPlayerView.setUseController(value); } diff --git a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java index a601af4..4b76b0d 100644 --- a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java +++ b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java @@ -108,6 +108,7 @@ public class VideoPlayerService extends Service { if (playbackState == ACTION_PLAY) { // this means that play is available, hence the audio is paused or stopped Log.v(TAG, "ACTION_PAUSE: " + playbackState); unregisterReceiver(myNoisyAudioStreamReceiver); + myNoisyAudioStreamReceiver=null; } } } ); @@ -131,9 +132,10 @@ public class VideoPlayerService extends Service { playerNotificationManager.setPlayer(null); } //Was seeing an error when exiting the program about about not unregistering the receiver. - if (null!=myNoisyAudioStreamReceiver) { - this.unregisterReceiver(myNoisyAudioStreamReceiver); - } + if (null!=myNoisyAudioStreamReceiver) { + this.unregisterReceiver(myNoisyAudioStreamReceiver); + myNoisyAudioStreamReceiver=null; + } if (player != null) { player.release(); player = null; From 39c38ca0fa274fd0d27a88a20972d69e0e1e6454 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 20:35:53 -0700 Subject: [PATCH 28/35] Fixing unregister error for noisy audio --- .../schueller/peertube/service/VideoPlayerService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java index 4b76b0d..d100402 100644 --- a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java +++ b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java @@ -132,10 +132,10 @@ public class VideoPlayerService extends Service { playerNotificationManager.setPlayer(null); } //Was seeing an error when exiting the program about about not unregistering the receiver. - if (null!=myNoisyAudioStreamReceiver) { - this.unregisterReceiver(myNoisyAudioStreamReceiver); - myNoisyAudioStreamReceiver=null; - } + if (null!=myNoisyAudioStreamReceiver) { + this.unregisterReceiver(myNoisyAudioStreamReceiver); + myNoisyAudioStreamReceiver=null; + } if (player != null) { player.release(); player = null; From 2c5248aebb19d856f47ec8649ef83c2232013d34 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 21:41:35 -0700 Subject: [PATCH 29/35] Bug fix for DateUtils not working as documented --- .../java/net/schueller/peertube/helper/MetaDataHelper.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java b/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java index 6c4b98e..164637d 100644 --- a/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java +++ b/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java @@ -28,8 +28,7 @@ import java.util.Date; public class MetaDataHelper { public static String getMetaString(Date getCreatedAt, Integer viewCount, Context context) { - return DateUtils. - getRelativeTimeSpanString(getCreatedAt.getTime()).toString() + + return (DateUtils.getRelativeTimeSpanString(context,getCreatedAt.getTime(),false).toString() + context.getResources().getString(R.string.meta_data_seperator) + viewCount + context.getResources().getString(R.string.meta_data_views); } From 1d3a464c62259a399964cab1cd053957c7c34f23 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 21:48:43 -0700 Subject: [PATCH 30/35] Bug fix for DateUtils not working as documented --- .../peertube/fragment/VideoPlayerFragment.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java index 08e4275..9fad3b3 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java @@ -199,7 +199,11 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL } }); } - + public void useController(boolean value){ + if (mBound){ + simpleExoPlayerView.setUseController(value); + } + } private void playVideo(Video video) { Context context = getContext(); @@ -259,6 +263,11 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL mService.player.setPlayWhenReady(false); } } + public void pauseToggle() { + if (mBound) { + mService.player.setPlayWhenReady(!mService.player.getPlayWhenReady()); + } + } public void unPauseVideo() { if (mBound) { mService.player.setPlayWhenReady(true); From d11d19e164c1029d9b254e81ae8a773327443df3 Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 21:53:58 -0700 Subject: [PATCH 31/35] Bug fix for DateUtils not working as documented --- .../schueller/peertube/fragment/VideoPlayerFragment.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java index 9fad3b3..edfdb68 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java @@ -199,11 +199,7 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL } }); } - public void useController(boolean value){ - if (mBound){ - simpleExoPlayerView.setUseController(value); - } - } + private void playVideo(Video video) { Context context = getContext(); From 7790ca4592c062238b407446803b53a26e67e3eb Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 21:58:56 -0700 Subject: [PATCH 32/35] Bug fix for DateUtils not working as documented --- .../main/java/net/schueller/peertube/helper/MetaDataHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java b/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java index 164637d..84e9de9 100644 --- a/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java +++ b/app/src/main/java/net/schueller/peertube/helper/MetaDataHelper.java @@ -30,7 +30,7 @@ public class MetaDataHelper { public static String getMetaString(Date getCreatedAt, Integer viewCount, Context context) { return (DateUtils.getRelativeTimeSpanString(context,getCreatedAt.getTime(),false).toString() + context.getResources().getString(R.string.meta_data_seperator) + - viewCount + context.getResources().getString(R.string.meta_data_views); + viewCount + context.getResources().getString(R.string.meta_data_views)); } public static String getOwnerString(String accountName, String serverHost, Context context) { From 83898c81cdffab04f65fcb68ff50c867636ba16c Mon Sep 17 00:00:00 2001 From: dhk2 Date: Fri, 3 Jul 2020 22:06:38 -0700 Subject: [PATCH 33/35] Bug fix for DateUtils not working as documented --- .../schueller/peertube/service/VideoPlayerService.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java index d100402..d3aa9a8 100644 --- a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java +++ b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java @@ -132,9 +132,12 @@ public class VideoPlayerService extends Service { playerNotificationManager.setPlayer(null); } //Was seeing an error when exiting the program about about not unregistering the receiver. - if (null!=myNoisyAudioStreamReceiver) { - this.unregisterReceiver(myNoisyAudioStreamReceiver); - myNoisyAudioStreamReceiver=null; + try { + if (null!=myNoisyAudioStreamReceiver) { + this.unregisterReceiver(myNoisyAudioStreamReceiver); + } + } catch (Exception e) { + Log.e("VideoPlayerService", "attempted to unregister a nonregistered service"); } if (player != null) { player.release(); From 6f51d8f6b372b8afed7d6c9f52a4b068778e809f Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sat, 4 Jul 2020 14:21:31 +0200 Subject: [PATCH 34/35] Removed translations for untranslatable strings --- app/src/main/res/values-ar/strings.xml | 7 ------ app/src/main/res/values-bn/strings.xml | 25 -------------------- app/src/main/res/values-de/strings.xml | 1 - app/src/main/res/values-fr/strings.xml | 7 ------ app/src/main/res/values-nb-rNO/strings.xml | 1 - app/src/main/res/values-nl/strings.xml | 1 - app/src/main/res/values-sv/strings.xml | 1 - app/src/main/res/values-tr/strings.xml | 27 ---------------------- app/src/main/res/values-zh-rCN/strings.xml | 1 - app/src/main/res/values-zh-rTW/strings.xml | 1 - 10 files changed, 72 deletions(-) diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index fb28e73..571c662 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -1,7 +1,5 @@ - Thorium - نشاط تشغيل الفيديو الإعدادات تسجيل الدخول @@ -24,13 +22,9 @@ الإشتراكات الحساب - 1.0.0-alpha.7 - https://troll.tv خادوم PeerTube - \u0020-\u0020 \u0020 مشاهدات - \@ الصورة المصغرة للفيديو الصورة الرمزية للحساب عرض NSFW @@ -51,7 +45,6 @@ لاتوجد نتائج المزيد مشاركة - PeerTube الرابط غير صالح. الوضع الداكن أعد تشغيل التطبيق لتنشيط الوضع الداكن. diff --git a/app/src/main/res/values-bn/strings.xml b/app/src/main/res/values-bn/strings.xml index 7277160..7e410c0 100644 --- a/app/src/main/res/values-bn/strings.xml +++ b/app/src/main/res/values-bn/strings.xml @@ -1,7 +1,5 @@ - Thorium - VideoPlayActivity সেটিংস সাইন ইন @@ -25,13 +23,9 @@ সাবস্ক্রিপশন অ্যাকাউন্ট - 1.0.0-alpha.7 - https://troll.tv পিয়ারটিউব সার্ভার - \u0020-\u0020 " দৃষ্ট" - \@ ভিডিও থাম্বনেইল অ্যাকাউন্ট অবতার নিষিদ্ধ কন্টেন্ট @@ -52,7 +46,6 @@ ফলাফল নেই আরও শেয়ার - PeerTube অবৈধ ইউআরএল। অন্ধকার মোড অন্ধকার মোড কার্যকর করার জন্য অ্যাপ্লিকেশন রিস্টার্ট করো। @@ -272,15 +265,6 @@ Normal ১.৫x 2x - {faw-check} - {faw-expand} - {faw-compress} - {faw-ellipsis-v} - {faw-thumbs-up} - {faw-thumbs-down} - {faw-share} - {faw-download} - {faw-save} ব্যাকগ্রাউন্ড প্লেব্যাক সক্রিয় থাকলে ব্যাকগ্রাউন্ডে ভিডিও প্লে করতে থাকবে। স্থানীয় @@ -298,15 +282,6 @@ ভাষা Tags - pref_token_access - pref_token_refresh - pref_token_expiration - pref_token_type - pref_auth_username - pref_auth_password - none - like - dislike গাঢ় বেগুনি অ্যাকাউন্ট সাম্প্রতিক diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 0f3fd83..aae549c 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -16,7 +16,6 @@ Abos Konto PeerTube-Server - VideoPlayActivity Dieses Passwort ist zu kurz Dieses Passwort ist falsch Einstellungen diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 5567530..273d7aa 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -1,7 +1,5 @@ - Thorium - VideoPlayActivity Paramètres Se connecter @@ -24,13 +22,9 @@ Abonnements Compte - 1.0.0-alpha.7 - https://troll.tv Serveur Peertube - \u0020-\u0020 " vues" - \@ Miniature vidéo Avatar du compte Contenu pour adultes @@ -49,7 +43,6 @@ Pas de résultat Plus Partager - PeerTube URL invalide. Mode sombre Redémarrez l’application pour que le mode sombre soit activé. diff --git a/app/src/main/res/values-nb-rNO/strings.xml b/app/src/main/res/values-nb-rNO/strings.xml index 6f96c67..abfcf6f 100644 --- a/app/src/main/res/values-nb-rNO/strings.xml +++ b/app/src/main/res/values-nb-rNO/strings.xml @@ -61,7 +61,6 @@ Beskrivelse: Tok del: Noe gikk galt, prøv igjen senere. - VideoPlayActivity Innvilg kontakttilgang for fullføring av e-postadresser. Populært " visninger" diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 486a798..b859884 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -1,6 +1,5 @@ - VideoPlayActivity Instellingen Inloggen Server diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 689df8d..6a7f958 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -282,7 +282,6 @@ Beskrivning: Gick med: Någonting gick snett, försök gärna igen om en stund! - VideoPlayActivity Ge åtkomst till kontakter för komplettering av e-postadresser. UrlVideoPlayActivity diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 8312c87..90b0ae9 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -1,6 +1,5 @@ - İzleti Oynatma Etkinliği Ayarlar Oturum aç @@ -24,13 +23,9 @@ Abonelikler Hesap - 1.0.0-alpha.7 - https://troll.tv PeerTube Sunucusu - \u0020-\u0020 " Görüntüleme" - \@ İzleti Küçük Resmi Hesap Resmi Ahlaksız İçerik @@ -48,7 +43,6 @@ Sonuç yok Daha Paylaş - PeerTube Geçersiz bağlantı. Karanlık Kipi Karanlık kipin etkinleşmesi için uygulamayı yeniden başlatın. @@ -269,18 +263,6 @@ Normal 1,5× - {faw-play-circle} - {faw-cog} - {faw-check} - {faw-check} - {faw-expand} - {faw-compress} - {faw-ellipsis-v} - {faw-thumbs-up} - {faw-thumbs-down} - {faw-share} - {faw-download} - {faw-save} Arkaplanda Oynatma Etkinleştirilirse, arka planda izleti oynatmaya devam eder. Yerel @@ -300,15 +282,6 @@ Oynatma hızı Kalite - pref_token_access - pref_token_refresh - pref_token_expiration - pref_token_type - pref_auth_username - pref_auth_password - none - like - dislike Hesap Yeniler İzletiler diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index dbba02c..91e491e 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -63,7 +63,6 @@ 视频通过一个种子下载,此选项需要存储权限(实验阶段,不稳定!) 退出 中文 - 视频播放Activity 本字段必填 账户 最近 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index ddce667..037f1f0 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1,6 +1,5 @@ - 影片播放活動 設定 登入 伺服器 From 35059521878f10fe14d0de4eeaf6a0d711cb08fc Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sat, 4 Jul 2020 14:34:34 +0200 Subject: [PATCH 35/35] Improved and added some French translations --- app/src/main/res/values-fr/strings.xml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 5567530..27fed15 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -312,7 +312,7 @@ Serveur actuel 0,75× 1,25× - Livre d\'adresse + Carnet d\'adresses Identification réussie Identification échouée ! a un identifiant @@ -333,4 +333,19 @@ Langue de l\'application Mettre la lecture d\'arrière-plan en pause en appuyant sur la touche de retour pendant la lecture de la vidéo. Pause sur le bouton retour + À propos + Apparence + Compte + Paramètres de lecture en fond + Votre version Android ne supporte pas la lecture de vidéos dans une fenêtre flottante + Le mode Picture-in-Picture est désactivé pour cette applications dans les paramètres Android + Lecture de vidéos + Continuer en fond sonore + Arrêter de lire la vidéo + Continuer dans une fenêtre flottante + Sélectionner le mode de fonctionnement de la lecture de vidéo lorsque l\'application est mise en arrière-plan + Liste de vidéos + Sélectionner un serveur + Retirer un serveur + Voulez-vous vraiment retirer ce serveur de votre carnet d\'adresses ? \ No newline at end of file