5

I have two activity A & B, A activity have list of videos. After click the video it goes to B(Player) activity to play video.

Issue faced

A(Video List) --> B(Player Activity)

  1. When i click the back button B activity goes to PIP mode. Now A is visible & B activity in PIP mode(Video Playing). Again i click the back button it closed the A activity, but B still in PIP Mode. Now B activity leave PIP mode to Full activity.

    Now again click the back button, i want to show the A as back stack B activity to PIP mode. But B activity goes to PIP mode but Back screen as homes screen.

  2. When i clicked the Home button while in B activity, B activity goes to PIP mode. B activity in PIP now can access the home screens. Now click the PIP mode screen to full activity.

    Now again click the back button, i want to show the A as back stack B activity to PIP mode. But B activity goes to PIP mode but Back screen as homes screen.

Manifest

<activity
   android:name=".MainActivity"
   android:screenOrientation="portrait"/>

<activity
   android:name=".PlayerActivity"
   android:allowTaskReparenting="true"
   android:autoRemoveFromRecents="true"
   android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|layoutDirection"
   android:excludeFromRecents="true"
   android:launchMode="singleTask"
   android:resizeableActivity="true"
   android:screenOrientation="sensor"
   android:supportsPictureInPicture="true" />

Picuture-in-Picture code

private void pictureInPictureMode() {

    if (supportsPiPMode() && getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {

        Rational aspectRatio = new Rational(playerView.getWidth(), playerView.getHeight());
        pictureInPictureParamsBuilder.setAspectRatio(aspectRatio).build();
        if (canEnterPiPMode()) enterPictureInPictureMode(pictureInPictureParamsBuilder.build());

    }

}

@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
    inPIP = isInPictureInPictureMode;
    if (isInPictureInPictureMode) {
        landscapeViews();
        bottomAdv.setVisibility(View.GONE);
    } else {
        portraitViews();
    }
}

@Override
protected void onUserLeaveHint() {
     pictureInPictureMode();
}

private boolean canEnterPiPMode() {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
        return (AppOpsManager.MODE_ALLOWED == appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_PICTURE_IN_PICTURE, Process.myUid(), getPackageName()));
    }

    return false;
 }

public boolean supportsPiPMode() {
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
}

In B activity whenever click the back button need A activity as back stack B to PIP mode. Guide me to solve this issue.

Yugesh
  • 4,030
  • 9
  • 57
  • 97
  • I think it's the standard behaviour for PIP mode you can see the example as MX player app. If you can show or provide example that would be great. – Deepak Kumar Sep 12 '19 at 02:44
  • 1
    @deepakkumar Did you see the **JIO TV** application. Home page it has shows list of Channels. Click to play any channel. After click the Home button it goes to PIP mode to play video. After exit the PIP mode click back it will shows the Channels list. – Yugesh Sep 12 '19 at 04:47

0 Answers0