Do not set a duration for live streams

A live window with changing duration can't be properly
displayed in a media notification. The duration constantly
changes and creates a nervous jumping seekbar that is not
really useful.

This change sets the duration for live streams to `C.TIME_UNSET`
when publishing the player state to the platform session. This
way no duration is sent to the platform session which prevents
media controls from drawing a seekbar.

Issue: androidx/media#1256
PiperOrigin-RevId: 624112541
This commit is contained in:
bachinger 2024-04-12 03:12:26 -07:00 committed by Copybara-Service
parent 8ba44ad2b1
commit fc1d60beb9
3 changed files with 11 additions and 1 deletions

View File

@ -19,6 +19,9 @@
* Muxers:
* IMA extension:
* Session:
* Hide seekbar in the media notification for live streams by not setting
the duration into the platform session metadata
([#1256](https://github.com/androidx/media/issues/1256)).
* UI:
* Downloads:
* OkHttp Extension:

View File

@ -1292,7 +1292,10 @@ import org.checkerframework.checker.initialization.qual.Initialized;
PlayerWrapper player = sessionImpl.getPlayerWrapper();
@Nullable MediaItem currentMediaItem = player.getCurrentMediaItemWithCommandCheck();
MediaMetadata newMediaMetadata = player.getMediaMetadataWithCommandCheck();
long newDurationMs = player.getDurationWithCommandCheck();
long newDurationMs =
player.isCurrentMediaItemLiveWithCommandCheck()
? C.TIME_UNSET
: player.getDurationWithCommandCheck();
String newMediaId =
currentMediaItem != null ? currentMediaItem.mediaId : MediaItem.DEFAULT_MEDIA_ID;
@Nullable

View File

@ -982,6 +982,10 @@ import java.util.List;
return super.isCurrentMediaItemLive();
}
public boolean isCurrentMediaItemLiveWithCommandCheck() {
return isCommandAvailable(COMMAND_GET_CURRENT_MEDIA_ITEM) && isCurrentMediaItemLive();
}
@Override
public boolean isCurrentMediaItemSeekable() {
verifyApplicationThread();