MediaSync API¶
-
class
MCorp.
mediaSync
(elem, to[, options])¶ Constructor function. Returns handle for controlling synchronization.
Arguments: - elem (HTMLMediaElement) – The HTMLMediaElement to synchronize
- to (TimingObject) – The timingobject to synchronize after
- options (object) – Synchronization options
- options.skew (float) – (default 0.0) Skew for timing object position, ehead of synchronization. Tip: calculate by start offset of content - start position of timing object.
- options.automute (boolean) – (default true) Mute the media element when playing too fast (or too slow)-
- options.mode (string) – (default “auto”) - “skip”: Force “skip” mode - i.e. don’t try using playbackRate. - “vpbr”: Force variable playback rate. Normally not a good idea - “auto” (default): try playbackRate. If it’s not supported, it will struggle for a while before reverting. If ‘options.remember’ is not set to false, this will only happen once after each browser update.
- options.debug (object) – (default null) If debug is true, log to console, if a function, the function will be called with debug info
- options.target (float) – (default 0.025 - 25ms ~ lipsync) Target precision. Default is likely OK, if we can do better, we will. Target too narrow, makes for a more skippy experience. When using variable playback rates, this parameter is ignored (target is always 0)
- options.remember (boolean) – (default true) Remember the last experience on this device - stores support or lack of support for variable playback rate. Records in localStorage under key “mediascape_vpbr”, clear it to re-learn.
Returns object mediaSync: mediaSync object
-
MCorp.mediaSync.
getSkew
()¶ Get the current skew
Returns float skew: current skew
-
MCorp.mediaSync.
setSkew
(skew)¶ Skew the timing object. The same effect can be achieved by using a Skew Converter.
Arguments: - skew (float) – new skew
-
MCorp.mediaSync.
setOption
(key, value)¶ Set or update options
Arguments: - key (string) – The option key to set
- value (object) – The option value to set
sync.setOption("debug", false); // Disable debugging sync.setOption("target", 0.1); // Change to coarser target
-
MCorp.mediaSync.
getMethod
()¶ Get the current method for synchronization
Returns string method: “skip” or “playbackrate”
-
MCorp.mediaSync.
setMotion
(to)¶ Set the timing object to synchronize after
Arguments: - to (TimingObject) – The timingobject to synchronize after
-
MCorp.mediaSync.
stop
()¶ Stop synchronization