javascriptibookssmilepub3

Make javascript aware of when media overlays are being played in an epub3 ebook


I would like to have some javascript code modify some properties of the element that is being played as part of a media overlay (smil driven). In particular, I am interested in text media overlays, which get highlighted as some audio is played. My question is two-fold:


Solution

  • The EPUB 3 specification allows JavaScript contents embedded inside an EPUB container to "communicate" with the reading application only via the epubReadingSystem object.

    Unfortunately, the specification requires the exposure of basic fields only, like the name and the version of the Reading System, and probes for its scripting capabilities (hasFeature). See: http://www.idpf.org/epub/301/spec/epub-contentdocs.html#app-epubReadingSystem

    In particular, there is no IDPF-anointed way to get the state of the Media Overlays (not started/playing/pausing, which fragment is active, etc.) exposed to JS embedded inside the EPUB.

    Of course, in theory one might find an "hack" for a specific reading system (especially if it relies on JS for the GUI, like Readium or iBooks), and be able to route those pieces of information to the JS code inside the EPUB (and rendered by the Reading System). But of course this approach is brittle --- as you know from my previous observations about my own rb_smil_emulator.js.

    Another possibility is to just monitor the DOM, keeping track of the changes in classes applied to all the SMIL fragments, but this technique might prove problematic in terms of timing performance/accuracy.