-
-
Save Mifrill/f9c8f7dd91f5edb4107c946fd88fe604 to your computer and use it in GitHub Desktop.
Video.js, TypeScript, traditional Ember Component
This file contains hidden or 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