Elm Media Control - API Proposal

Didn’t event take me that long. Yeah, don’t know why I didn’t think of this sooner. This doesn’t result in frame-perfect sync, but it does provide an easy way to synchronize:

There’s an old api in the Media API called Controller, specifically designed to let you control multiple videos in sync. The following works:

const myController = new Controller();
video.controller = myController;
videoDuplicate.controller = myController;

function play(){
    controller.play();
}

function pause(){
    controller.pause();
}

function seek(time){
     controller.currentTime = time;
}

However, not every attribute works like this. Volume, muted, playbackRate, currentTime are all shared, but loop, src, textTracks, autoplay and others are individual. However, the ones that can be set on controller are the ones concerned with synchronization. Others, like loop, can simply be iterated through safely on each element.

EDIT: I’m really upset at myself for not thinking of this sooner. This is an obscure api, but fascinating to me, and I’ve been looking to find a good use for it for years.

1 Like