mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
feat: wasm plugin progress event
This commit is contained in:
parent
cb7df01bdf
commit
30ec155fa8
@ -19,6 +19,7 @@ enum FFMessageType {
|
||||
READ_FILE = 'READ_FILE',
|
||||
DELETE_FILE = 'DELETE_FILE',
|
||||
ERROR = 'ERROR',
|
||||
PROGRESS = 'PROGRESS',
|
||||
}
|
||||
|
||||
export class FFmpeg {
|
||||
@ -26,6 +27,8 @@ export class FFmpeg {
|
||||
#resolves: Callbacks = {}
|
||||
#rejects: Callbacks = {}
|
||||
|
||||
#progressEventCallback: (event: ProgressEvent) => void
|
||||
|
||||
public loaded = false
|
||||
|
||||
#registerHandlers = () => {
|
||||
@ -42,6 +45,11 @@ export class FFmpeg {
|
||||
case FFMessageType.DELETE_FILE:
|
||||
this.#resolves[id](data)
|
||||
break
|
||||
case FFMessageType.PROGRESS:
|
||||
if (this.#progressEventCallback) {
|
||||
this.#progressEventCallback(<ProgressEvent>data)
|
||||
}
|
||||
break
|
||||
case FFMessageType.ERROR:
|
||||
this.#rejects[id](data)
|
||||
break
|
||||
@ -197,7 +205,12 @@ interface Message {
|
||||
data?: FFMessageData
|
||||
}
|
||||
|
||||
type CallbackData = Uint8Array | string | boolean | Error | undefined
|
||||
interface ProgressEvent {
|
||||
progress: number
|
||||
time: number
|
||||
}
|
||||
|
||||
type CallbackData = Uint8Array | string | boolean | Error | ProgressEvent | undefined
|
||||
|
||||
interface Callbacks {
|
||||
[id: number | string]: (data: CallbackData) => void
|
||||
|
||||
@ -2,6 +2,7 @@ import { DownloadPackage, PackageEntry } from '@/core/download'
|
||||
import { meta } from '@/core/meta'
|
||||
import { getComponentSettings } from '@/core/settings'
|
||||
import { Toast } from '@/core/toast'
|
||||
import { formatPercent } from '@/core/utils/formatters'
|
||||
import { title as pluginTitle } from '.'
|
||||
import type { Options } from '../../../../components/video/download'
|
||||
import { DownloadVideoAction } from '../../../../components/video/download/types'
|
||||
@ -76,7 +77,9 @@ async function single(
|
||||
|
||||
console.debug('FFmpeg commandline args:', args.join(' '))
|
||||
|
||||
toast.message = '混流中……'
|
||||
ffmpeg.onProgress(event => {
|
||||
toast.message = `混流中: ${formatPercent(event.progress)}`
|
||||
})
|
||||
await ffmpeg.exec(args)
|
||||
|
||||
const output = await ffmpeg.readFile('output')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user