Code Monkey home page Code Monkey logo

html5-media-synchronized-subtitles's Introduction

html5-media-synchronized-subtitles

Pure HTML5 synchronized subtitles and movie display:

Synopsis

  1. A hidden element with the synchronized-subtitle-display class exists somewhere on the page with a data-player-id attribute pointing to a <video> element
  2. Add <script async src="html5-media-synchronized-subtitles.js"></script> to the page
  3. When the async JavaScript loads, it registers event handlers for the subtitle <track> loading
  4. Browsers which support WebVTT will load the track and parse it
  5. JavaScript creates an ordered list of track cues so the entire transcript may be displayed
  6. As the browser fires timeupdate events on the video, cues which overlap in time have the CSS class highlighted added and the scrollTop property of the cue list will be updated. If jQuery is present, the scrollTop change will be animated.

Notes & Browser Compatibility

Customization

Set the data-cue-element-callback attribute on the .synchronized-subtitle-display HTML element to the name of a global variable and it will be called with each element created for a track cue, allowing you to customize the display. The default behaviour is to replace the <br> generated by IE11 with spaces so the cues can be styled using display: inline without line-breaks which cannot be overridden using CSS.

Browsers

  • Safari 7 on OS X:
    • The standard subtitle controls will set the track state to disabled when the user deselects it, which will stop triggering cuechange events. We could solve this by listening for change events on the track list and resetting the mode to hidden but since Firefox doesn't support cuechange yet there's limited benefit.
  • Safari on iOS 7: ok
  • Chrome: ok
  • Firefox:
    • WebVTT is currently unsupported prior to Firefox 31
    • cuechange events are not yet dispatched: https://bugzilla.mozilla.org/show_bug.cgi?id=996331
    • The demo will not work in Firefox on OS X until H.264 support ships
    • Unlike other browsers, the content returned by getCueAsHTML will be wrapped in a <div>
  • IE11:

html5-media-synchronized-subtitles's People

Contributors

acdha avatar

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.