148148 private ImmutableList <CommandButton > mediaButtonPreferences ;
149149 private SessionCommands availableSessionCommands ;
150150 private Player .Commands availablePlayerCommands ;
151- @ Nullable private PlaybackException playbackException ;
151+ @ Nullable private PlaybackException customPlaybackException ;
152152 @ Nullable private Player .Commands playerCommandsForErrorState ;
153153
154154 @ SuppressWarnings ({
@@ -269,7 +269,7 @@ public MediaSessionLegacyStub(
269269 */
270270 public void setAvailableCommands (
271271 SessionCommands sessionCommands , Player .Commands playerCommands ) {
272- if (playbackException != null ) {
272+ if (customPlaybackException != null ) {
273273 return ;
274274 }
275275 boolean commandGetTimelineChanged =
@@ -361,7 +361,7 @@ public void setPlatformMediaButtonPreferences(
361361 }
362362
363363 /**
364- * Sets or clears an playback exception override for the platform session.
364+ * Sets or clears a playback exception override for the platform session.
365365 *
366366 * @param playbackException The {@link PlaybackException} or null.
367367 * @param playerCommandsForErrorState The available {@link Player.Commands} while the exception
@@ -373,7 +373,7 @@ public void setPlaybackException(
373373 checkArgument (
374374 (playbackException == null && playerCommandsForErrorState == null )
375375 || (playbackException != null && playerCommandsForErrorState != null ));
376- this . playbackException = playbackException ;
376+ customPlaybackException = playbackException ;
377377 this .playerCommandsForErrorState = playerCommandsForErrorState ;
378378 if (playbackException != null ) {
379379 updateLegacySessionPlaybackState (sessionImpl .getPlayerWrapper ());
@@ -1292,7 +1292,7 @@ public ControllerLegacyCbForBroadcast() {
12921292 * @return True if updates should be skipped.
12931293 */
12941294 public boolean skipLegacySessionPlaybackStateUpdates () {
1295- return playbackException != null ;
1295+ return customPlaybackException != null ;
12961296 }
12971297
12981298 @ Override
@@ -1765,7 +1765,7 @@ private static ComponentName getServiceComponentByAction(Context context, String
17651765
17661766 private PlaybackStateCompat createPlaybackStateCompat (PlayerWrapper player ) {
17671767 LegacyError legacyError = this .legacyError ;
1768- if (playbackException == null && legacyError != null && legacyError .isFatal ) {
1768+ if (customPlaybackException == null && legacyError != null && legacyError .isFatal ) {
17691769 // A fatal legacy error automatically set by Media3 upon a calling
17701770 // MediaLibrarySession.Callback according to the configured LibraryErrorReplicationMode.
17711771 Bundle extras = new Bundle (legacyError .extras );
@@ -1783,17 +1783,17 @@ private PlaybackStateCompat createPlaybackStateCompat(PlayerWrapper player) {
17831783 .setExtras (legacyError .extras )
17841784 .build ();
17851785 }
1786- if ( playbackException == null ) {
1787- // The actual error from the player, if any.
1788- playbackException = player . getPlayerError ();
1789- }
1786+ // The custom error from the session if present, or the actual error from the player, if any.
1787+ @ Nullable
1788+ PlaybackException publicPlaybackException =
1789+ customPlaybackException != null ? customPlaybackException : player . getPlayerError ();
17901790 boolean canReadPositions =
17911791 player .isCommandAvailable (Player .COMMAND_GET_CURRENT_MEDIA_ITEM )
17921792 && !player .isCurrentMediaItemLive ();
17931793 boolean shouldShowPlayButton =
1794- playbackException != null || Util .shouldShowPlayButton (player , playIfSuppressed );
1794+ publicPlaybackException != null || Util .shouldShowPlayButton (player , playIfSuppressed );
17951795 int state =
1796- playbackException != null
1796+ publicPlaybackException != null
17971797 ? PlaybackStateCompat .STATE_ERROR
17981798 : LegacyConversions .convertToPlaybackStateCompatState (player , shouldShowPlayButton );
17991799 // Always advertise ACTION_SET_RATING.
@@ -1824,8 +1824,9 @@ private PlaybackStateCompat createPlaybackStateCompat(PlayerWrapper player) {
18241824 : MediaSessionCompat .QueueItem .UNKNOWN_ID ;
18251825 float playbackSpeed = player .getPlaybackParameters ().speed ;
18261826 float sessionPlaybackSpeed = player .isPlaying () && canReadPositions ? playbackSpeed : 0f ;
1827- Bundle extras = playbackException != null ? new Bundle (playbackException .extras ) : new Bundle ();
1828- if (playbackException == null && legacyError != null ) {
1827+ Bundle extras =
1828+ publicPlaybackException != null ? new Bundle (publicPlaybackException .extras ) : new Bundle ();
1829+ if (publicPlaybackException == null && legacyError != null ) {
18291830 extras .putAll (legacyError .extras );
18301831 }
18311832 extras .putAll (legacyExtras );
@@ -1879,10 +1880,10 @@ private PlaybackStateCompat createPlaybackStateCompat(PlayerWrapper player) {
18791880 .build ());
18801881 }
18811882 }
1882- if (playbackException != null ) {
1883+ if (publicPlaybackException != null ) {
18831884 builder .setErrorMessage (
1884- LegacyConversions .convertToLegacyErrorCode (playbackException ),
1885- playbackException .getMessage ());
1885+ LegacyConversions .convertToLegacyErrorCode (publicPlaybackException ),
1886+ publicPlaybackException .getMessage ());
18861887 } else if (legacyError != null ) {
18871888 builder .setErrorMessage (legacyError .code , legacyError .message );
18881889 }
0 commit comments