Skip to content

Commit

Permalink
see changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyiya committed Mar 13, 2024
1 parent e5e8cdc commit 1e4384a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## UnRelease

## [1.2.33-beta.0]
## [1.2.33-beta.1]

- add events `sourcechangeerror`, `qualitychangeerror`.
- qualitychange fallback.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oplayer/core",
"version": "1.2.33-beta.0",
"version": "1.2.33-beta.1",
"description": "Oh! Another HTML5 video player.",
"type": "module",
"main": "./dist/index.es.js",
Expand Down
23 changes: 14 additions & 9 deletions packages/core/src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,41 +384,46 @@ export class Player<Context extends Record<string, any> = Record<string, any>> {
}

changeQuality(source: Omit<Source, 'poster'> | Promise<Omit<Source, 'poster'>>) {
this.isSourceChanging = true
this.emit('videoqualitychange', source)

return this._loader(source, {
keepPlaying: true,
keepTime: true,
preEvent: 'videoqualitychange',
event: 'videoqualitychanged',
brokenEvent: 'qualitychangeerror'
})
}

changeSource(source: Source | Promise<Source>, keepPlaying: boolean = true) {
this.isSourceChanging = true
this.emit('videosourcechange', source)

return this._loader(source, {
keepPlaying,
preEvent: 'videosourcechange',
event: 'videosourcechanged',
brokenEvent: 'sourcechangeerror'
})
}

_loader(
sourceLike: Source | Promise<Source>,
options: { keepPlaying: boolean; event: string; keepTime?: boolean; brokenEvent: string }
options: {
event: string
preEvent: string
brokenEvent: string
keepPlaying: boolean
keepTime?: boolean
}
) {
return new Promise<void>((resolve, reject) => {
if (this.isSourceChanging) return reject()
if (this.isSourceChanging) return reject(Error('Previous Source is Changing.'))

this.hasError = false
this.isSourceChanging = true
this.emit(options.preEvent, sourceLike)

const { isPlaying, currentTime, volume, playbackRate } = this
const { keepPlaying, keepTime } = options
const isPreloadNone = this.options.preload == 'none'
const canplay = isPreloadNone ? 'loadstart' : 'loadedmetadata'
const shouldPlay = keepPlaying && isPlaying
this.hasError = false

let finalSource: Source

Expand Down

0 comments on commit 1e4384a

Please sign in to comment.