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

Support for subtitles? #13

Open
pharshdev opened this issue Sep 9, 2019 · 1 comment
Open

Support for subtitles? #13

pharshdev opened this issue Sep 9, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@pharshdev
Copy link

No description provided.

@terrabythia terrabythia added the enhancement New feature or request label Sep 3, 2020
@snaeji
Copy link

snaeji commented Dec 16, 2020

I haven't had any time to make this code pretty and make a PR, if anyone is able to they are welcome.

class CastMedia {

  final String contentId;
  String title;
  String subtitle;
  bool autoPlay = true;
  double position;
  String contentType;
  String streamType;
  List<String> images;
  String subtitlesUrl;

  CastMedia({
    this.contentId,
    this.title = "",
    this.subtitle = "",
    this.autoPlay = true,
    this.position = 0.0,
    this.contentType = 'video/mp4',
    this.streamType = "BUFFERED",
    this.images,
    this.subtitlesUrl = "",
  }) {
    if (null == images) {
      images = [];
    }
  }

  Map toChromeCastMap() {
    // If media doesn't have subtitles send without media->Tracks
    if (subtitlesUrl == "")
      return {
      'type': 'LOAD',
      'autoPlay': autoPlay,
      'currentTime': position,
      'activeTracks': [],
      'media': {
        'contentId': contentId,
        'contentType': contentType,
        'streamType': streamType,
        'textTrackStyle': {
          'edgeType': 'NONE', // can be: "NONE", "OUTLINE", "DROP_SHADOW", "RAISED", "DEPRESSED"
          'fontScale': 1.0, // transforms into "font-size: " + (fontScale*100) +"%"
          'fontStyle': 'NORMAL', // can be: "NORMAL", "BOLD", "BOLD_ITALIC", "ITALIC",
          'fontFamily': 'Droid Sans',
          'fontGenericFamily': 'SANS_SERIF', // can be: "SANS_SERIF", "MONOSPACED_SANS_SERIF", "SERIF", "MONOSPACED_SERIF", "CASUAL", "CURSIVE", "SMALL_CAPITALS",
          'windowColor': '#00000', // see http://dev.w3.org/csswg/css-color/#hex-notation
          'windowRoundedCornerRadius': 10, // radius in px
          'windowType': 'NONE' // can be: "NONE", "NORMAL", "ROUNDED_CORNERS"
        },
        'metadata': {
          'metadataType': 0,
          'title': title,
          'subtitle': subtitle,
          'images': [{'url': images[0]}],
        },
      }
    };
    // If media has subtitles send subtitles tracks in media->Tracks
    return {
      'type': 'LOAD',
      'autoPlay': autoPlay,
      'currentTime': position,
      'activeTracks': [],
      'media': {
        'contentId': contentId,
        'contentType': contentType,
        'streamType': streamType,
        'textTrackStyle': {
          'edgeType': 'NONE', // can be: "NONE", "OUTLINE", "DROP_SHADOW", "RAISED", "DEPRESSED"
          'fontScale': 1.0, // transforms into "font-size: " + (fontScale*100) +"%"
          'fontStyle': 'NORMAL', // can be: "NORMAL", "BOLD", "BOLD_ITALIC", "ITALIC",
          'fontFamily': 'Droid Sans',
          'fontGenericFamily': 'SANS_SERIF', // can be: "SANS_SERIF", "MONOSPACED_SANS_SERIF", "SERIF", "MONOSPACED_SERIF", "CASUAL", "CURSIVE", "SMALL_CAPITALS",
          'windowColor': '#00000', // see http://dev.w3.org/csswg/css-color/#hex-notation
          'windowRoundedCornerRadius': 10, // radius in px
          'windowType': 'NONE' // can be: "NONE", "NORMAL", "ROUNDED_CORNERS"
        },
        'metadata': {
          'metadataType': 0,
          'title': title,
          'subtitle': subtitle,
          'images': [{'url': images[0]}],
        },
        'tracks': [{
          'trackId': 10, // This is an unique ID, used to reference the track
          'type': 'TEXT', // Default Media Receiver currently only supports TEXT
          'trackContentId': subtitlesUrl, // the URL of the VTT (enabled CORS and the correct ContentType are required)
          'trackContentType': 'text/vtt', // Currently only VTT is supported
          'name': 'Íslenska', // a Name for humans
          'language': 'is-IS', // the language
          'subtype': 'SUBTITLES' // should be SUBTITLES
        }]
      }
    };
  }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants