GithubHelp home page GithubHelp logo

dariocravero / media-overlays-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from marisademeglio/media-overlays-js

0.0 3.0 0.0 254.66 MB

EPUB Media Overlays javascript implementation

Ruby 0.01% HTML 99.87% JavaScript 0.10% CSS 0.03%

media-overlays-js's Introduction

media-overlays-js

EPUB Media Overlays javascript implementation

This is a partial implementation of EPUB Media Overlays.

See the API for more details

Run test

(first time) Get Ruby 1.9.x, install it, and run:

$ gem install bundler
$ bundle install

Then (every time), start the local server in the source code directory with

$ rake server

Navigate to http://localhost:4000/tests/test-index.html and select a test to run.

Future additions

  • Special handling when encountering a text node by itself. This means that the text node is pointing to timed media in the HTML file.

Approach to SMIL playback

See smil-model.js .

Parse a single SMIL file into a tree structure with the following functions on the nodes:

  • Node.render = function to render that node
  • Node.notifyChildDone = function called when the node's child is done rendering

The SMIL tree plays itself, calling

root->render

which in turn renders its children.

The tree may be played starting from any node by simply calling

node->render

All nodes are hooked up to renderers to manage how they should be played. Each node's render function is described briefly below.

  • Audio nodes trigger the audio clip player
  • Text node @srcs get broadcast via observable properties
  • Seq and body nodes render by calling their children's render functions in sequence
  • Par nodes render their children in parallel (e.g. this text with this audio).

When a node is done playing, it must notify its parent via the Node.notifyChildDone method. This method is also used to communicate from the audio clip player to the audio node that owns that clip.

In addition to the functions, nodes may also pick up this property:

  • Node.isJumpTarget = the node is the start of playback in the middle of the tree.

This property is necessary because of this use case: the user clicks "footnote 5" and the player jumps there. Footnote 5 is in the middle of a SMIL file and therefore in the middle of a playback tree. The first clip of footnote 5 is 4 seconds long. After 1 second, the user clicks "footnote 5" again. Normally, the audio player would see that it is already playing that clip and would just continue doing so. However, in this case, we want to force it to re-start, so we identify the node as a jump target. The audio player's behavior has been optimized for smooth playback so this type of interruption is the exception.

Notes about parsing

Two parsers have been tested, DOM and SAX. SAX + custom tree object consumes less memory but is too slow to be practical.

For DOM parsing, there are two options: use the DOM tree as-is and add the properties we need or use the DOM tree to construct a custom object.

Using a DOM as-is is very fast though risks high memory usage. This is the current approach, which seems reasonable for all but the hugest files (e.g. 50 MB).

Using the DOM to construct a custom tree object seems as though it would consume less memory once the DOM is discarded (letting only the custom tree object persist); however, actual results vary. Sometimes after waiting a minute or so, the browser does some garbage collection, indicating removal of the DOM; other times, it seems to hang around. See experiments/2-smil-models/custom-smil-model.js .

Audio playback

An issue with audio playback is that we have to use a timer to monitor for the end of a clip. This timer fires about once every 11ms when the tab is in focus, which is sufficient. However, when the tab loses focus, it fires only once every second. Read more about this issue.

media-overlays-js's People

Contributors

marisademeglio avatar matthewrobertson avatar

Watchers

Darío Javier Cravero avatar James Cloos avatar  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.