adding controls to exit pip or switch to background audio

This commit is contained in:
dhk2 2020-07-03 15:50:54 -07:00
parent 76b3ddcf69
commit 81e92a421a
1 changed files with 43 additions and 0 deletions

View File

@ -62,6 +62,8 @@ import androidx.fragment.app.FragmentManager;
//import static net.schueller.peertube.helper.Constants.BACKGROUND_PLAY_PREF_KEY; //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 com.google.android.exoplayer2.ui.PlayerNotificationManager.ACTION_STOP;
import static net.schueller.peertube.helper.Constants.BACKGROUND_AUDIO; 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.DEFAULT_THEME;
@ -100,6 +102,46 @@ public class VideoPlayActivity extends AppCompatActivity {
setPictureInPictureParams(params); 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 @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -391,6 +433,7 @@ public class VideoPlayActivity extends AppCompatActivity {
@Override @Override
public void onPictureInPictureModeChanged (boolean isInPictureInPictureMode, Configuration newConfig) { public void onPictureInPictureModeChanged (boolean isInPictureInPictureMode, Configuration newConfig) {
if (isInPictureInPictureMode) { if (isInPictureInPictureMode) {
changedToPipMode();
Log.v(TAG,"switched to pip "); Log.v(TAG,"switched to pip ");
} else { } else {
Log.v(TAG,"switched to normal"); Log.v(TAG,"switched to normal");