Skip to content

Commit

Permalink
feat(video-player): toggle play hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Dec 24, 2023
1 parent 112fc45 commit 93bf032
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"homepage": "https://github.com/liriliri/luna#readme",
"dependencies": {
"licia": "^1.38.1"
"licia": "^1.39.2"
},
"devDependencies": {
"@babel/core": "^7.10.5",
Expand Down
10 changes: 9 additions & 1 deletion src/video-player/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import stripIndent from 'licia/stripIndent'
import toStr from 'licia/toStr'
import durationFormat from 'licia/durationFormat'
import fullscreen from 'licia/fullscreen'
import hotkey from 'licia/hotkey'
import { eventPage, drag } from '../share/util'
import Component, { IComponentOptions } from '../share/Component'

Expand All @@ -17,6 +18,7 @@ const isIos = detectBrowser(navigator.userAgent).name === 'ios'

interface IOptions extends IComponentOptions {
url?: string
hotkey?: boolean
}

const videoEvents = [
Expand Down Expand Up @@ -77,6 +79,7 @@ export default class VideoPlayer extends Component<IOptions> {

this.initOptions(options, {
url: '',
hotkey: true,
})

const { video } = this
Expand Down Expand Up @@ -201,7 +204,7 @@ export default class VideoPlayer extends Component<IOptions> {
}, 3000)
}
private bindEvent() {
const { c } = this
const { c, container, $container } = this

this.$controller
.on('click', c('.play'), this.togglePlay)
Expand Down Expand Up @@ -231,6 +234,11 @@ export default class VideoPlayer extends Component<IOptions> {
this.on('pause', this.onPause)
this.on('canplay', this.onLoaded)
this.on('progress', this.onLoaded)

if (this.options.hotkey) {
$container.attr('tabindex', '-1')
hotkey.on('space', { element: container }, this.togglePlay)
}
}
private toggleFullscreen = () => {
const { video } = this as any
Expand Down
1 change: 1 addition & 0 deletions src/video-player/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
min-height: 150px;
position: relative;
font-size: 14px;
outline: none;
}

@include controller('video-player');
Expand Down

0 comments on commit 93bf032

Please sign in to comment.