Created
November 5, 2020 17:15
-
-
Save nbibler/eabe2575938343bfd76577399686094f to your computer and use it in GitHub Desktop.
Video.js, TypeScript, traditional Ember Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from "@ember/component"; | |
import { assert } from "@ember/debug"; | |
import { isNone } from "@ember/utils"; | |
import ModelRegistry from "ember-data/types/registries/model"; | |
import videojs, { VideoJsPlayer } from "video.js"; | |
export default class MyVideoComponent extends Component { | |
player?: VideoJsPlayer; | |
video!: ModelRegistry["video"]; | |
didInsertElement() { | |
super.didInsertElement(); | |
this.player = videojs(this.element.querySelector(".video-js"), { controls: true, fluid: true }); | |
this.player.on("play", () => { | |
console.log("playing..."); | |
}); | |
} | |
didRender() { | |
if (!this.player || !this.video.mediaPath || this.video.mediaPath === this.player.src()) { | |
return; | |
} | |
this.player.src(this.video.mediaPath); | |
} | |
init() { | |
super.init(); | |
assert("`video` is required", !isNone(this.video)); | |
} | |
willDestroyElement() { | |
super.willDestroyElement(); | |
if (this.player) { | |
this.player.dispose(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment