Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAST improve MediaTrack converting to Format #2082

Open
StaehliJ opened this issue Jan 28, 2025 · 0 comments
Open

CAST improve MediaTrack converting to Format #2082

StaehliJ opened this issue Jan 28, 2025 · 0 comments

Comments

@StaehliJ
Copy link

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);
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants