Fix for NPE when playerState is null (#14191)

Signed-off-by: Mark Hilbush <mark@hilbush.com>
This commit is contained in:
Mark Hilbush 2023-01-10 09:02:40 -05:00 committed by Jacob Laursen
parent 551cd8f41d
commit e392f7f3bf

View File

@ -157,30 +157,32 @@ public class ChromecastStatusUpdater {
return; return;
} }
switch (mediaStatus.playerState) { if (mediaStatus.playerState != null) {
case IDLE: switch (mediaStatus.playerState) {
break; case IDLE:
case PAUSED: break;
callback.updateState(CHANNEL_CONTROL, PlayPauseType.PAUSE); case PAUSED:
callback.updateState(CHANNEL_STOP, OnOffType.OFF); callback.updateState(CHANNEL_CONTROL, PlayPauseType.PAUSE);
break; callback.updateState(CHANNEL_STOP, OnOffType.OFF);
case BUFFERING: break;
case LOADING: case BUFFERING:
case PLAYING: case LOADING:
callback.updateState(CHANNEL_CONTROL, PlayPauseType.PLAY); case PLAYING:
callback.updateState(CHANNEL_STOP, OnOffType.OFF); callback.updateState(CHANNEL_CONTROL, PlayPauseType.PLAY);
break; callback.updateState(CHANNEL_STOP, OnOffType.OFF);
default: break;
logger.debug("Unknown media status: {}", mediaStatus.playerState); default:
break; logger.debug("Unknown media status: {}", mediaStatus.playerState);
break;
}
} }
callback.updateState(CHANNEL_CURRENT_TIME, new QuantityType<>(mediaStatus.currentTime, Units.SECOND)); callback.updateState(CHANNEL_CURRENT_TIME, new QuantityType<>(mediaStatus.currentTime, Units.SECOND));
// If we're playing, paused or buffering but don't have any MEDIA information don't null everything out. // If we're playing, paused or buffering but don't have any MEDIA information don't null everything out.
Media media = mediaStatus.media; Media media = mediaStatus.media;
if (media == null && (mediaStatus.playerState == PLAYING || mediaStatus.playerState == PAUSED if (media == null && (mediaStatus.playerState == null || mediaStatus.playerState == PLAYING
|| mediaStatus.playerState == BUFFERING)) { || mediaStatus.playerState == PAUSED || mediaStatus.playerState == BUFFERING)) {
return; return;
} }