Skip to content

Commit

Permalink
Merge pull request #137 from Quantizr/master
Browse files Browse the repository at this point in the history
Fix playback speed issue on certain detected media
  • Loading branch information
vantezzen authored Mar 10, 2023
2 parents 6ac09af + f2e29c4 commit be57451
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/contents/lib/SpeedController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import debugging from "debug"
import inspectMediaElements from "./inspectMediaElements"

import type { MediaElement } from "../../shared/types"

Expand All @@ -16,6 +17,12 @@ export default class SpeedController {

elements: MediaElement[] = []

constructor() {
inspectMediaElements((element: MediaElement) => {
this.elements.push(element)
})
}

/**
* Fixes issues changing the playback rate by temporarily blocking `ratechange` event listeners.
*/
Expand Down Expand Up @@ -100,17 +107,6 @@ export default class SpeedController {
}

setPlaybackRate(rate: number) {
this.elements = [
...document.querySelectorAll("video, audio")
] as MediaElement[]
debug(
"Setting playback rate to",
rate,
"on",
this.elements.length,
"elements"
)

this.elements.forEach((element) => {
this.setPlaybackRateForElement(rate, element)
})
Expand Down

0 comments on commit be57451

Please sign in to comment.