feat: added loop button to video.js player

This commit is contained in:
Bobby 2022-05-27 13:44:46 +07:00
parent 7d2e2d97e0
commit b2a11ae42c
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09
2 changed files with 30 additions and 0 deletions

View File

@ -18,6 +18,7 @@
}
}
.vjs-loop-button,
.vjs-seek-button {
.vjs-icon-placeholder {
/* stylelint-disable-next-line font-family-no-missing-generic-family-keyword */
@ -33,6 +34,16 @@
}
}
.vjs-loop-button {
&:not(.vjs-loop-enabled) {
color: $grey
}
.vjs-icon-placeholder::before {
content: "\e81f"
}
}
.vjs-seek-button {
&.skip-back .vjs-icon-placeholder::before {
content: "\e81e";

View File

@ -128,6 +128,25 @@ page.reloadVideo = () => {
})
page.player.seekButtons({ forward: 10, back: 10 })
const videoJSButton = videojs.getComponent('Button')
const loopButtonText = () => page.player.loop()
? 'Disable loop'
: 'Enable loop'
const loopButton = videojs.extend(videoJSButton, {
constructor () {
videoJSButton.apply(this, arguments)
this.addClass('vjs-loop-button')
this.controlText(loopButtonText())
},
handleClick () {
page.player.loop(!page.player.loop())
this.toggleClass('vjs-loop-enabled', page.player.loop())
this.controlText(loopButtonText())
}
})
videojs.registerComponent('loopButton', loopButton)
page.player.getChild('controlBar').addChild('loopButton')
if (page.titleFormat) {
document.title = page.titleFormat.replace(/%identifier%/g, page.urlIdentifier)
}