Coder Social home page Coder Social logo

Support for subtitles? about dart_chromecast HOT 1 OPEN

terrabythia avatar terrabythia commented on September 15, 2024 4
Support for subtitles?

from dart_chromecast.

Comments (1)

snaeji avatar snaeji commented on September 15, 2024 1

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
        }]
      }
    };
  }

}

from dart_chromecast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.