@@ -1729,6 +1729,17 @@ default ListenableFuture<MediaItemsWithStartPosition> onSetMediaItems(
1729
1729
new MediaItemsWithStartPosition (mediaItemList , startIndex , startPositionMs )));
1730
1730
}
1731
1731
1732
+ /**
1733
+ * @deprecated Override {@link MediaSession.Callback#onPlaybackResumption(MediaSession,
1734
+ * ControllerInfo, boolean)} instead.
1735
+ */
1736
+ @ Deprecated
1737
+ @ UnstableApi
1738
+ default ListenableFuture <MediaItemsWithStartPosition > onPlaybackResumption (
1739
+ MediaSession mediaSession , ControllerInfo controller ) {
1740
+ return Futures .immediateFailedFuture (new UnsupportedOperationException ());
1741
+ }
1742
+
1732
1743
/**
1733
1744
* Returns the playlist with which the player should be prepared when a controller requests to
1734
1745
* play without a current {@link MediaItem}.
@@ -1750,16 +1761,24 @@ default ListenableFuture<MediaItemsWithStartPosition> onSetMediaItems(
1750
1761
* Player#COMMAND_GET_CURRENT_MEDIA_ITEM} and either {@link Player#COMMAND_SET_MEDIA_ITEM} or
1751
1762
* {@link Player#COMMAND_CHANGE_MEDIA_ITEMS} available.
1752
1763
*
1764
+ * <p>If {@code isForPlayback} is true, {@link ManuallyHandlePlaybackResumption} may be set on
1765
+ * the future to manually handle playback resumption. Refer to the {@link
1766
+ * ManuallyHandlePlaybackResumption} javadoc for more details.
1767
+ *
1753
1768
* @param mediaSession The media session for which playback resumption is requested.
1754
1769
* @param controller The {@linkplain ControllerInfo controller} that requests the playback
1755
1770
* resumption. This may be a short living controller created only for issuing a play command
1756
1771
* for resuming playback.
1772
+ * @param isForPlayback Whether playback is going to be started as a result of the future being
1773
+ * completed. If false, SystemUI is querying for media item data in order to build and
1774
+ * display the resumption notification at boot time.
1757
1775
* @return The {@linkplain MediaItemsWithStartPosition playlist} to resume playback with.
1758
1776
*/
1759
1777
@ UnstableApi
1778
+ @ SuppressWarnings ("deprecation" ) // calling deprecated API for backwards compatibility
1760
1779
default ListenableFuture <MediaItemsWithStartPosition > onPlaybackResumption (
1761
- MediaSession mediaSession , ControllerInfo controller ) {
1762
- return Futures . immediateFailedFuture ( new UnsupportedOperationException () );
1780
+ MediaSession mediaSession , ControllerInfo controller , boolean isForPlayback ) {
1781
+ return onPlaybackResumption ( mediaSession , controller );
1763
1782
}
1764
1783
1765
1784
/**
@@ -1875,6 +1894,25 @@ public int hashCode() {
1875
1894
}
1876
1895
}
1877
1896
1897
+ /**
1898
+ * Exception that may be set to the future in {@link
1899
+ * MediaSession.Callback#onPlaybackResumption(MediaSession, ControllerInfo, boolean)} if the
1900
+ * parameter {@code isForPlayback} is true, in order to signal that the app wishes to handle this
1901
+ * resumption itself. This means the app is responsible for restoring a playlist, setting it to
1902
+ * the player, and starting playback.
1903
+ *
1904
+ * <p>Do note this has various pitfalls and needs to be used carefully:<br>
1905
+ * - {@link MediaSession.Callback#onPlayerInteractionFinished(MediaSession, ControllerInfo,
1906
+ * Player.Commands)} will NOT be called for the resumption command.<br>
1907
+ * - If playback is not actually resumed in this method, the resumption notification will end up
1908
+ * non-functional, but will keep being displayed. This is not a suitable way to disable playback
1909
+ * resumption, do not attempt to disable it this way.<br>
1910
+ * - If the app takes too long to go into foreground, the grant to go into foreground may have
1911
+ * expired.
1912
+ */
1913
+ @ UnstableApi
1914
+ public static class ManuallyHandlePlaybackResumption extends Exception {}
1915
+
1878
1916
/**
1879
1917
* A result for {@link Callback#onConnect(MediaSession, ControllerInfo)} to denote the set of
1880
1918
* available commands and the media button preferences for a {@link ControllerInfo controller}.
0 commit comments