Skip to content

MediaElement and SyntheticMediaElement #8129

@ysulyma

Description

@ysulyma

Introduction

The <video> element was one of the most revolutionary new features of HTML5, and a key part of "Web 2.0". Today, the web platform has become powerful enough to create videos. Libraries such as GSAP, Liqvid, and Remotion allow developers to create seekable animations and even full-length videos using Javascript, just as we did with Flash in the days of yore. (Disclaimer: I am the author of Liqvid.) Such "videos" are just DOM manipulation synced up to an audio track (which is still a normal audio file) and a scrubber bar; in particular, they can be interactive, which is impossible with .mp4 videos.

This proposal standardizes the behavior which is common between GSAP's Timeline, Liqvid's Playback, Remotion's PlayerRef, and other libraries. It defines one new interface, MediaElement, and one new class, SyntheticMediaElement. The desiderata are:

  • the existing HTMLMediaElement interface must implement MediaElement

  • SyntheticMediaElement must implement MediaElement

  • the initial specification of SyntheticMediaElement should do no more than implement MediaElement, in order for the proposal easy to adopt.

In other words, SyntheticMediaElement implements a subset of the functionality of <audio>/<video> elements. It has a current time, a playback rate and a duration, and can be played, paused, and seeked.

The choice of which properties/events to include is dicated by experience. The Liqvid plugin suite is compatible with all three of GSAP/Liqvid/Remotion, and this proposal is a less-kludgy version of the @lqv/playback interface that those plugins are built around.

Details

The MediaElement interface includes the following properties of HTMLMediaElement:

  • currentTime
  • duration
  • muted
  • pause()
  • paused
  • play()
  • playbackRate
  • seeking
  • volume

It also supports addEventListener and removeEventListener with the following event types:

  • durationchange
  • ended
  • pause
  • play
  • playing
  • ratechange
  • seeked
  • seeking
  • timeupdate
  • volumechange

The SyntheticMediaElement class implements MediaElement.

Polyfill

Polyfill: mjs, types, source.

This polyfill is based on Liqvid's Playback class. However, due to design errors that class does not currently implement MediaElement as defined above (it measures currentTime in milliseconds rather than seconds, and some of the event names are different).

Enhancements

All three reference libraries implement additional functionality beyond the MediaElement interface defined above. We have not included these in the proposal since they violate Desiderata 1 and/or 3. However, they are useful to keep in mind.

  • GSAP and Liqvid support giving string names to specific times or intervals.

  • GSAP and Remotion allow nesting of Timelines/Sequences. Relatedly, Liqvid and Remotion allow ordinary <audio>/<video> elements to be controlled by the "synthetic" playback. In the future, both of these could be implemented by some sort of adopt() method on SyntheticMediaElement.

  • Liqvid allows a Playback to control an AnimationTimeline. In the future, this could be added to SyntheticMediaElement.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions