mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
feat: enhance artplayerPluginAudioTrack with update method for dynamic option changes
This commit is contained in:
1 parent
a8d36a38ad
commit
e559d3bc6f
23 files changed
+73
-83
No files matched your search
+2
-2
@@ -48,5 +48,5 @@ declare const artplayerPluginAds: (option: Option) => (art: Artplayer) => Ads
|
||||
|
||||
export default artplayerPluginAds
|
||||
|
||||
export = artplayerPluginAds;
|
||||
export as namespace artplayerPluginAds;
|
||||
export = artplayerPluginAds
|
||||
export as namespace artplayerPluginAds;
|
||||
+2
-2
@@ -16,5 +16,5 @@ declare const artplayerPluginAmbilight: (option: Option) => (art: Artplayer) =>
|
||||
|
||||
export default artplayerPluginAmbilight
|
||||
|
||||
export = artplayerPluginAmbilight;
|
||||
export as namespace artplayerPluginAmbilight;
|
||||
export = artplayerPluginAmbilight
|
||||
export as namespace artplayerPluginAmbilight;
|
||||
+2
-2
@@ -22,5 +22,5 @@ declare function artplayerPluginAsr(option?: AsrPluginOption): (art: Artplayer)
|
||||
|
||||
export default artplayerPluginAsr
|
||||
|
||||
export = artplayerPluginAsr;
|
||||
export as namespace artplayerPluginAsr;
|
||||
export = artplayerPluginAsr
|
||||
export as namespace artplayerPluginAsr;
|
||||
+2
-2
@@ -31,5 +31,5 @@ declare const artplayerPluginAudioTrack: (option: Option) => (art: Artplayer) =>
|
||||
|
||||
export default artplayerPluginAudioTrack
|
||||
|
||||
export = artplayerPluginAudioTrack;
|
||||
export as namespace artplayerPluginAudioTrack;
|
||||
export = artplayerPluginAudioTrack
|
||||
export as namespace artplayerPluginAudioTrack;
|
||||
+2
-2
@@ -13,5 +13,5 @@ declare const artplayerPluginAutoThumbnail: (option: Option) => (art: Artplayer)
|
||||
|
||||
export default artplayerPluginAutoThumbnail
|
||||
|
||||
export = artplayerPluginAutoThumbnail;
|
||||
export as namespace artplayerPluginAutoThumbnail;
|
||||
export = artplayerPluginAutoThumbnail
|
||||
export as namespace artplayerPluginAutoThumbnail;
|
||||
+2
-2
@@ -17,5 +17,5 @@ declare const artplayerPluginChapter: (option: Option) => (art: Artplayer) => Re
|
||||
|
||||
export default artplayerPluginChapter
|
||||
|
||||
export = artplayerPluginChapter;
|
||||
export as namespace artplayerPluginChapter;
|
||||
export = artplayerPluginChapter
|
||||
export as namespace artplayerPluginChapter;
|
||||
+2
-2
@@ -13,5 +13,5 @@ declare const artplayerPluginChromecast: (option: Option) => (art: Artplayer) =>
|
||||
|
||||
export default artplayerPluginChromecast
|
||||
|
||||
export = artplayerPluginChromecast;
|
||||
export as namespace artplayerPluginChromecast;
|
||||
export = artplayerPluginChromecast
|
||||
export as namespace artplayerPluginChromecast;
|
||||
+2
-2
@@ -21,5 +21,5 @@ declare const artplayerPluginDanmukuMask: (option?: Option) => (art: Artplayer)
|
||||
|
||||
export default artplayerPluginDanmukuMask
|
||||
|
||||
export = artplayerPluginDanmukuMask;
|
||||
export as namespace artplayerPluginDanmukuMask;
|
||||
export = artplayerPluginDanmukuMask
|
||||
export as namespace artplayerPluginDanmukuMask;
|
||||
+2
-2
@@ -255,5 +255,5 @@ declare const artplayerPluginDanmuku: (option: Option) => (art: Artplayer) => Re
|
||||
|
||||
export default artplayerPluginDanmuku
|
||||
|
||||
export = artplayerPluginDanmuku;
|
||||
export as namespace artplayerPluginDanmuku;
|
||||
export = artplayerPluginDanmuku
|
||||
export as namespace artplayerPluginDanmuku;
|
||||
+2
-2
@@ -13,5 +13,5 @@ declare const artplayerPluginDashControl: (option: { quality?: Config, audio?: C
|
||||
|
||||
export default artplayerPluginDashControl
|
||||
|
||||
export = artplayerPluginDashControl;
|
||||
export as namespace artplayerPluginDashControl;
|
||||
export = artplayerPluginDashControl
|
||||
export as namespace artplayerPluginDashControl;
|
||||
+2
-2
@@ -18,5 +18,5 @@ declare const artplayerPluginDocumentPip: (option: Option) => (art: Artplayer) =
|
||||
|
||||
export default artplayerPluginDocumentPip
|
||||
|
||||
export = artplayerPluginDocumentPip;
|
||||
export as namespace artplayerPluginDocumentPip;
|
||||
export = artplayerPluginDocumentPip
|
||||
export as namespace artplayerPluginDocumentPip;
|
||||
+2
-2
@@ -13,5 +13,5 @@ declare const artplayerPluginHlsControl: (option: { quality?: Config, audio?: Co
|
||||
|
||||
export default artplayerPluginHlsControl
|
||||
|
||||
export = artplayerPluginHlsControl;
|
||||
export as namespace artplayerPluginHlsControl;
|
||||
export = artplayerPluginHlsControl
|
||||
export as namespace artplayerPluginHlsControl;
|
||||
+2
-2
@@ -28,5 +28,5 @@ declare class ArtplayerPluginIframe {
|
||||
|
||||
export default ArtplayerPluginIframe
|
||||
|
||||
export = artplayerPluginIframe;
|
||||
export as namespace artplayerPluginIframe;
|
||||
export = artplayerPluginIframe
|
||||
export as namespace artplayerPluginIframe;
|
||||
+2
-2
@@ -11,5 +11,5 @@ declare const artplayerPluginAss: (options: Options) => (art: Artplayer) => {
|
||||
|
||||
export default artplayerPluginAss
|
||||
|
||||
export = artplayerPluginLibass;
|
||||
export as namespace artplayerPluginLibass;
|
||||
export = artplayerPluginLibass
|
||||
export as namespace artplayerPluginLibass;
|
||||
+2
-2
@@ -12,5 +12,5 @@ declare const artplayerPluginLiquidGlass: (option?: Option) => (art: Artplayer)
|
||||
|
||||
export default artplayerPluginLiquidGlass
|
||||
|
||||
export = artplayerPluginLiquidGlass;
|
||||
export as namespace artplayerPluginLiquidGlass;
|
||||
export = artplayerPluginLiquidGlass
|
||||
export as namespace artplayerPluginLiquidGlass;
|
||||
+2
-2
@@ -12,5 +12,5 @@ declare const artplayerPluginMultipleSubtitles: (option: {
|
||||
|
||||
export default artplayerPluginMultipleSubtitles
|
||||
|
||||
export = artplayerPluginMultipleSubtitles;
|
||||
export as namespace artplayerPluginMultipleSubtitles;
|
||||
export = artplayerPluginMultipleSubtitles
|
||||
export as namespace artplayerPluginMultipleSubtitles;
|
||||
+2
-2
@@ -29,5 +29,5 @@ declare function artplayerPluginVast(
|
||||
|
||||
export default artplayerPluginVast
|
||||
|
||||
export = artplayerPluginVast;
|
||||
export as namespace artplayerPluginVast;
|
||||
export = artplayerPluginVast
|
||||
export as namespace artplayerPluginVast;
|
||||
+2
-2
@@ -6,5 +6,5 @@ declare const artplayerPluginVttThumbnail: (option: { vtt?: string, style?: Part
|
||||
|
||||
export default artplayerPluginVttThumbnail
|
||||
|
||||
export = artplayerPluginVttThumbnail;
|
||||
export as namespace artplayerPluginVttThumbnail;
|
||||
export = artplayerPluginVttThumbnail
|
||||
export as namespace artplayerPluginVttThumbnail;
|
||||
+2
-2
@@ -6,5 +6,5 @@ declare const artplayerProxyCanvas: (option?: Option) => (art: Artplayer) => Res
|
||||
|
||||
export default artplayerProxyCanvas
|
||||
|
||||
export = artplayerProxyCanvas;
|
||||
export as namespace artplayerProxyCanvas;
|
||||
export = artplayerProxyCanvas
|
||||
export as namespace artplayerProxyCanvas;
|
||||
+2
-2
@@ -75,5 +75,5 @@ declare const artplayerProxyMediabunny: (option?: Option) => (art: Artplayer) =>
|
||||
|
||||
export default artplayerProxyMediabunny
|
||||
|
||||
export = artplayerProxyMediabunny;
|
||||
export as namespace artplayerProxyMediabunny;
|
||||
export = artplayerProxyMediabunny
|
||||
export as namespace artplayerProxyMediabunny;
|
||||
Vendored
+2
-34
@@ -126,8 +126,6 @@ export interface Subtitle {
|
||||
onVttLoad?: (vtt: string) => string
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface SettingOption extends Omit<Setting, 'html' | 'icon' | 'tooltip'> {
|
||||
html: string
|
||||
icon: string | undefined
|
||||
@@ -239,10 +237,6 @@ export interface Quality {
|
||||
url: string
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export type AspectRatio = 'default' | '4:3' | '16:9' | (`${number}:${number}` & Record<never, never>)
|
||||
export type PlaybackRate = 0.5 | 0.75 | 1.0 | 1.25 | 1.5 | 1.75 | 2.0 | (number & Record<never, never>)
|
||||
export type Flip = 'normal' | 'horizontal' | 'vertical' | (string & Record<never, never>)
|
||||
@@ -352,15 +346,6 @@ export declare class Player {
|
||||
reset(): void
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export type CustomType
|
||||
= | 'flv'
|
||||
| 'm3u8'
|
||||
@@ -769,9 +754,6 @@ declare module 'artplayer/i18n/*' {
|
||||
export default lang
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export type Bar = 'loaded' | 'played' | 'hover'
|
||||
|
||||
export interface Events {
|
||||
@@ -995,8 +977,6 @@ export interface Config {
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface Selector {
|
||||
/**
|
||||
* Whether the default is selected
|
||||
@@ -1128,18 +1108,6 @@ export interface ComponentOption {
|
||||
onSelect?: (this: Artplayer, selector: Selector, element: HTMLElement, event: Event) => void
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export type {
|
||||
Config,
|
||||
Events,
|
||||
@@ -1329,5 +1297,5 @@ export default class Artplayer extends Player {
|
||||
} & Record<string, unknown>
|
||||
}
|
||||
|
||||
export = Artplayer;
|
||||
export as namespace Artplayer;
|
||||
export = Artplayer
|
||||
export as namespace Artplayer;
|
||||
@@ -1,19 +1,15 @@
|
||||
export default function artplayerPluginAudioTrack(option) {
|
||||
return (art) => {
|
||||
const { url, offset = 0, sync = 0.3 } = option
|
||||
|
||||
if (!url) {
|
||||
return {
|
||||
name: 'artplayerPluginAudioTrack',
|
||||
}
|
||||
}
|
||||
let { url, offset = 0, sync = 0.3 } = option
|
||||
|
||||
const audio = new Audio()
|
||||
audio.src = url
|
||||
audio.preload = 'auto'
|
||||
if (url) {
|
||||
audio.src = url
|
||||
}
|
||||
|
||||
function syncAudio() {
|
||||
if (!art.video)
|
||||
if (!art.video || !url)
|
||||
return
|
||||
|
||||
const videoTime = art.currentTime
|
||||
@@ -25,6 +21,8 @@ export default function artplayerPluginAudioTrack(option) {
|
||||
}
|
||||
|
||||
art.on('play', () => {
|
||||
if (!url)
|
||||
return
|
||||
syncAudio()
|
||||
audio.play().catch((err) => {
|
||||
console.warn(err)
|
||||
@@ -60,6 +58,24 @@ export default function artplayerPluginAudioTrack(option) {
|
||||
audio.load()
|
||||
})
|
||||
|
||||
function update(newOption) {
|
||||
if (newOption.url && newOption.url !== url) {
|
||||
url = newOption.url
|
||||
audio.src = url
|
||||
if (art.playing) {
|
||||
audio.play().catch(err => console.warn(err))
|
||||
}
|
||||
}
|
||||
|
||||
if (newOption.offset !== undefined) {
|
||||
offset = newOption.offset
|
||||
}
|
||||
|
||||
if (newOption.sync !== undefined) {
|
||||
sync = newOption.sync
|
||||
}
|
||||
}
|
||||
|
||||
audio.volume = art.volume
|
||||
audio.muted = art.muted
|
||||
audio.playbackRate = art.video?.playbackRate || 1
|
||||
@@ -67,6 +83,7 @@ export default function artplayerPluginAudioTrack(option) {
|
||||
return {
|
||||
name: 'artplayerPluginAudioTrack',
|
||||
audio,
|
||||
update,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,11 @@ interface Result {
|
||||
* The audio element
|
||||
*/
|
||||
audio: HTMLAudioElement
|
||||
|
||||
/**
|
||||
* Update option
|
||||
*/
|
||||
update: (option: Option) => void
|
||||
}
|
||||
|
||||
declare const artplayerPluginAudioTrack: (option: Option) => (art: Artplayer) => Result
|
||||
|
||||
Reference in new issue
Block a user