Skip to content

Commit

Permalink
fix: flv error controll
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyiya committed Feb 17, 2025
1 parent 4b474ed commit 50ffb36
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/mpegts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oplayer/mpegts",
"version": "1.2.25",
"version": "1.2.26-beta.0",
"description": "mpegts.js plugin for oplayer",
"type": "module",
"main": "./dist/index.es.js",
Expand Down
28 changes: 15 additions & 13 deletions packages/mpegts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,16 @@ class MpegtsPlugin implements PlayerPlugin {
(globalThis as any).mpegts ||
//@ts-expect-error
(library ? await loadSDK(library, 'mpegts') : (await import('mpegts.js/dist/mpegts.js')).default)

MpegtsPlugin.library.LoggingControl.applyConfig({
enableAll: false
})
}

if (!MpegtsPlugin.library.isSupported()) return false

MpegtsPlugin.library.LoggingControl.addLogListener(this.logListener.bind(this))

this.instance = MpegtsPlugin.library.createPlayer(
{
url: source.src,
Expand All @@ -75,25 +81,21 @@ class MpegtsPlugin implements PlayerPlugin {
this.options.config
)

const { player, instance } = this

instance.on(MpegtsPlugin.library.Events.ERROR, function (_, data) {
const { type, details, fatal } = data

if (fatal) {
player.hasError = true
player.emit('error', { ...data, pluginName: PLUGIN_NAME, message: type + ': ' + details })
}
})

instance.attachMediaElement($video)
instance.load()
this.instance.attachMediaElement($video)
this.instance.load()

return this
}

destroy() {
this.instance?.destroy()
MpegtsPlugin.library.LoggingControl.removeLogListener(this.logListener.bind(this))
}

logListener(level: string, msg: string) {
if (level === 'error') {
this.player.emit('error', { level, msg, pluginName: PLUGIN_NAME, message: msg })
}
}
}

Expand Down

0 comments on commit 50ffb36

Please sign in to comment.