Description
Use case description
We are working on a Player experience with Google Cast. We want to add track selection feature to it. We managed to select active tracks by overriding the required methods with a ForwardingPlayer
.
MediaTrack
from remote client converting to Format
are not well parsed with some stream, for example this DASH stream with TTML subtitles is not parsed correctly.
The output TrackGroup type is C.TRACK_TYPE_UNKNOWN
instead of C.TRACK_TYPE_TEXT
.
Proposed solution
Ensure that CastUtils.mediaTrackToFormat
returns a "Text track" type when the given MediaTrack
is type of MediaTrack.TYPE_TEXT
.
public static Format mediaTrackToFormat(MediaTrack mediaTrack) {
Format.Builder builder = new Format.Builder();
if (mediaTrack.getType() == MediaTrack.TYPE_TEXT && MimeTypes.getTrackType(mediaTrack.getContentType()) == C.TRACK_TYPE_UNKNOWN) {
builder.setSampleMimeType(MimeTypes.BASE_TYPE_TEXT+"/cast");
}
return builder
.setId(mediaTrack.getContentId())
.setContainerMimeType(mediaTrack.getContentType())
.setLanguage(mediaTrack.getLanguage())
.build();
}
With the follow code, we are able to handle subtitles.
Alternatives considered
As an alternative we could also implement a system like MediaItemConverter
that could replace CastUtils.mediaTrackToFormat
and add it to CastPlayer
constructor.
public interface MediaTrackConverter {
Format toFormat(MediaTrack mediaTrack);
}