|
22 | 22 | import static androidx.media3.common.Player.STATE_IDLE; |
23 | 23 | import static androidx.media3.common.Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED; |
24 | 24 |
|
| 25 | +import android.os.Binder; |
25 | 26 | import android.os.Bundle; |
| 27 | +import android.os.IBinder; |
26 | 28 | import androidx.annotation.CheckResult; |
27 | 29 | import androidx.annotation.FloatRange; |
28 | 30 | import androidx.annotation.Nullable; |
|
44 | 46 | import androidx.media3.common.VideoSize; |
45 | 47 | import androidx.media3.common.text.CueGroup; |
46 | 48 | import androidx.media3.common.util.Assertions; |
| 49 | +import androidx.media3.common.util.BundleUtil; |
47 | 50 | import androidx.media3.common.util.UnstableApi; |
48 | 51 | import androidx.media3.common.util.Util; |
49 | 52 | import com.google.common.base.Objects; |
@@ -824,8 +827,9 @@ private boolean isPlaying( |
824 | 827 | private static final String FIELD_TRACK_SELECTION_PARAMETERS = Util.intToStringMaxRadix(29); |
825 | 828 | private static final String FIELD_CURRENT_TRACKS = Util.intToStringMaxRadix(30); |
826 | 829 | private static final String FIELD_TIMELINE_CHANGE_REASON = Util.intToStringMaxRadix(31); |
| 830 | + private static final String FIELD_IN_PROCESS_BINDER = Util.intToStringMaxRadix(32); |
827 | 831 |
|
828 | | - // Next field key = 32 |
| 832 | + // Next field key = 33 |
829 | 833 |
|
830 | 834 | /** |
831 | 835 | * Returns a copy of this player info, filtered by the specified available commands. |
@@ -882,6 +886,16 @@ public PlayerInfo filterByAvailableCommands( |
882 | 886 | return builder.build(); |
883 | 887 | } |
884 | 888 |
|
| 889 | + /** |
| 890 | + * Returns a {@link Bundle} that stores a direct object reference to this class for in-process |
| 891 | + * sharing. |
| 892 | + */ |
| 893 | + public Bundle toBundleInProcess() { |
| 894 | + Bundle bundle = new Bundle(); |
| 895 | + BundleUtil.putBinder(bundle, FIELD_IN_PROCESS_BINDER, new InProcessBinder()); |
| 896 | + return bundle; |
| 897 | + } |
| 898 | + |
885 | 899 | @Override |
886 | 900 | public Bundle toBundle() { |
887 | 901 | Bundle bundle = new Bundle(); |
@@ -985,6 +999,10 @@ public Bundle toBundle() { |
985 | 999 | public static final Creator<PlayerInfo> CREATOR = PlayerInfo::fromBundle; |
986 | 1000 |
|
987 | 1001 | private static PlayerInfo fromBundle(Bundle bundle) { |
| 1002 | + @Nullable IBinder inProcessBinder = BundleUtil.getBinder(bundle, FIELD_IN_PROCESS_BINDER); |
| 1003 | + if (inProcessBinder instanceof InProcessBinder) { |
| 1004 | + return ((InProcessBinder) inProcessBinder).getPlayerInfo(); |
| 1005 | + } |
988 | 1006 | @Nullable Bundle playerErrorBundle = bundle.getBundle(FIELD_PLAYBACK_ERROR); |
989 | 1007 | @Nullable |
990 | 1008 | PlaybackException playerError = |
@@ -1115,4 +1133,10 @@ private static PlayerInfo fromBundle(Bundle bundle) { |
1115 | 1133 | currentTracks, |
1116 | 1134 | trackSelectionParameters); |
1117 | 1135 | } |
| 1136 | + |
| 1137 | + private final class InProcessBinder extends Binder { |
| 1138 | + public PlayerInfo getPlayerInfo() { |
| 1139 | + return PlayerInfo.this; |
| 1140 | + } |
| 1141 | + } |
1118 | 1142 | } |
0 commit comments