CAST improve `MediaTrack` converting to `Format`
@marcbaechinger is already working on this.
Since Jan 31, 2025.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
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);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.