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