Skip to content

Instantly share code, notes, and snippets.

@GinjaNinja5197
Forked from SheepTester/explainer.md
Last active February 25, 2022 17:06
Show Gist options
  • Save GinjaNinja5197/428adf11833f5f9582697b2b35278d7d to your computer and use it in GitHub Desktop.
Save GinjaNinja5197/428adf11833f5f9582697b2b35278d7d to your computer and use it in GitHub Desktop.
Change speed of Edpuzzle video

Edpuzzle aggressively reverts the playbackRate of a <video> element, so you can't simply change it to increase the speed. Thus, a more aggressive response is necessary to combat it.

Firstly, we get the <video> element:

video = document.querySelector('video')

Then, we get the setter function for the playbackRate property using Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'playbackRate').set. It is called with the <video> element as this and with speed as the new value. This way, the <video> element is properly notified of the speed change by simulating assigning a value to playBackRate directly (ie using =).

Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'playbackRate').set.call(video, speed)

After that, to prevent Edpuzzle from changing it back, we make playbackRate unwritable, so they can't simply set it:

Object.defineProperty(video, 'playbackRate', { writable: false })

Of course, if we can change the speed this way, so can Edpuzzle, so this might not work in the future.

speed = 2 // Change this to the speed (eg 2 for 2x speed)
video = document.querySelector('video')
video.currentTime = video.duration
Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'playbackRate').set.call(video, speed)
Object.defineProperty(video, 'playbackRate', { writable: false })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment