Skip to content

Commit

Permalink
release(video-player): v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Dec 25, 2023
1 parent 93bf032 commit 348e81a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@
},
"video-player": {
"icon": true,
"version": "0.1.0",
"version": "1.0.0",
"style": true,
"test": true,
"install": false,
Expand Down
3 changes: 3 additions & 0 deletions src/video-player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0 (25 Dec 2023)

* feat: hotkey
23 changes: 23 additions & 0 deletions src/video-player/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,26 @@ const videoPlayer = new LunaVideoPlayer(container, {

videoPlayer.play()
```

## Configuration

* hotkey(boolean): Enable hotkey.
* url(string): Video url.

## Api

### pause(): void

Pause video.

### play(): undefined | Promise<void>

Play video.

### seek(time: number): void

Seek to specified time.

### volume(percentage: number): void

Set video volume.
24 changes: 22 additions & 2 deletions src/video-player/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ import Component, { IComponentOptions } from '../share/Component'
const $document = $(document as any)
const isIos = detectBrowser(navigator.userAgent).name === 'ios'

interface IOptions extends IComponentOptions {
/** IOptions */
export interface IOptions extends IComponentOptions {
/** Video url. */
url?: string
/** Enable hotkey. */
hotkey?: boolean
}

Expand Down Expand Up @@ -109,13 +112,15 @@ export default class VideoPlayer extends Component<IOptions> {
this.video.src = options.url
}
}
/** Play video. */
play() {
if (!this.video.src) {
return
}

return this.video.play()
}
/** Pause video. */
pause() {
if (!this.video.src) {
return
Expand All @@ -128,6 +133,7 @@ export default class VideoPlayer extends Component<IOptions> {
this.$container.off('mousemove', this.onMouseMove)
super.destroy()
}
/** Seek to specified time. */
seek(time: number) {
if (!this.video.src) {
return
Expand All @@ -138,6 +144,7 @@ export default class VideoPlayer extends Component<IOptions> {

this.video.currentTime = time
}
/** Set video volume. */
volume(percentage: number) {
percentage = clamp(percentage, 0, 1)
this.video.volume = percentage
Expand Down Expand Up @@ -237,7 +244,20 @@ export default class VideoPlayer extends Component<IOptions> {

if (this.options.hotkey) {
$container.attr('tabindex', '-1')
hotkey.on('space', { element: container }, this.togglePlay)
const options = { element: container }
hotkey.on('space', options, this.togglePlay)
hotkey.on('left', options, () => {
this.seek(this.video.currentTime - 5)
})
hotkey.on('right', options, () => {
this.seek(this.video.currentTime + 5)
})
hotkey.on('up', options, () => {
this.volume(this.video.volume + 0.1)
})
hotkey.on('down', options, () => {
this.volume(this.video.volume - 0.1)
})
}
}
private toggleFullscreen = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/video-player/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "video-player",
"version": "0.1.0",
"version": "1.0.0",
"description": "Video player",
"luna": {
"icon": true
Expand Down
3 changes: 2 additions & 1 deletion src/video-player/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'luna-video-player.css'
import story from '../share/story'
import VideoPlayer from 'luna-video-player.js'
import $ from 'licia/$'
import h from 'licia/h'
import readme from './README.md'
import changelog from './CHANGELOG.md'
import { text } from '@storybook/addon-knobs'

const def = story(
Expand All @@ -30,6 +30,7 @@ const def = story(
},
{
readme,
changelog,
source: __STORY__,
}
)
Expand Down

0 comments on commit 348e81a

Please sign in to comment.