Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyiya committed Aug 25, 2022
1 parent 0a79140 commit 6a87d29
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export const VIDEO_EVENTS = [
'volumechange',
'waiting',
'encrypted',
'waitingforkey'
'waitingforkey',
'enterpictureinpicture',
'leavepictureinpicture'
] as const

export const PLAYER_EVENTS = [
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export default class E {
}
}

offAny(name: string) {
this.events[name] = []
}

offAll() {
this.events = Object.create(null)
}
Expand Down
16 changes: 10 additions & 6 deletions packages/core/src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export class Player {
this.#E.off(name as string, listener)
}

readonly offAny = (name: PlayerEventName) => {
this.#E.offAny(name as string)
}

readonly emit = (name: PlayerEventName, payload?: PlayerEvent['payload']) => {
this.#E.emit(name as any, payload)
}
Expand Down Expand Up @@ -127,6 +131,8 @@ export class Player {
autoplay: this.#options.autoplay,
loop: this.#options.loop,
playsinline: this.#options.playsinline,
'webkit-playsinline': this.#options.playsinline,
'x5-playsinline': this.#options.playsinline,
volume: this.#options.volume,
preload: this.#options.preload,
poster: this.#options.source.poster,
Expand Down Expand Up @@ -176,12 +182,10 @@ export class Player {
play = () => {
if (!this.$video.src) throw Error('The element has no supported sources.')

if (this.#isCustomLoader) {
this.#playPromise = this.$video.play()
} else {
if (this.canPlay) {
this.#playPromise = this.$video.play()
}
if (this.#isCustomLoader || this.canPlay) {
this.#playPromise = this.$video
.play()
.catch((reason) => this.emit('notice', { text: (<Error>reason).message }))
}
}

Expand Down
12 changes: 7 additions & 5 deletions packages/hls/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@ const hlsPlugin = ({

return {
name: PLUGIN_NAME,
load: ({ on, emit }, video, source) => {
load: ({ on, emit, offAny }, video, source) => {
if (!matcher(video, source)) return false

hlsInstance = getHls({ autoStartLoad: false, ...hlsConfig })
if (!isInitial) {
emit('loadedplugin', { name: PLUGIN_NAME })
isInitial = true
}

if (!hlsInstance || !Hls.isSupported()) {
emit('pluginerror', {
Expand All @@ -52,6 +48,12 @@ const hlsPlugin = ({
return true
}

if (!isInitial) {
emit('loadedplugin', { name: PLUGIN_NAME })
isInitial = true
offAny('canplay') //onReady is handled by hls.js
}

hlsInstance?.attachMedia(video)
hlsInstance?.loadSource(source.src)
hlsInstance?.startLoad()
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/ControllerBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const mini = $.css({
})

const hide = $.css({
transform: 'translateY(calc(100%))'
transform: 'translateY(100%)'
})

const controllerBar = $.css({
Expand Down

0 comments on commit 6a87d29

Please sign in to comment.