mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-28 18:41:20 -08:00
fix(audio): [PKG-AUDIO-05] checkpoint zero-time resume and native buffering evidence
This commit is contained in:
1 parent
0218196df9
commit
d18c545675
25 files changed
+14373
-32
No files matched your search
@@ -2,7 +2,7 @@ import type Artplayer from 'artplayer'
|
||||
import type { Option, RuntimeResult, UpdateOption } from '../types/artplayer-plugin-audio-track'
|
||||
import { createAudioTrack } from './track'
|
||||
|
||||
type AudioEvent = 'play' | 'pause' | 'seek' | 'destroy' | 'video:pause' | 'video:ended' | 'video:waiting' | 'video:emptied' | 'video:seeking' | 'video:seeked' | 'video:timeupdate' | 'video:ratechange' | 'video:volumechange' | 'video:playing'
|
||||
type AudioEvent = 'play' | 'pause' | 'seek' | 'destroy' | 'video:pause' | 'video:ended' | 'video:waiting' | 'video:emptied' | 'video:seeking' | 'video:seeked' | 'video:timeupdate' | 'video:ratechange' | 'video:volumechange' | 'video:playing' | 'video:canplay'
|
||||
|
||||
export default function artplayerPluginAudioTrack(option: Option) {
|
||||
return (art: Artplayer): RuntimeResult => {
|
||||
@@ -16,6 +16,15 @@ export default function artplayerPluginAudioTrack(option: Option) {
|
||||
track.sync(art.currentTime)
|
||||
}
|
||||
|
||||
function canResumeAudio() {
|
||||
const video = art.video
|
||||
if (!video)
|
||||
return false
|
||||
if ('playing' in video && typeof video.playing === 'boolean')
|
||||
return video.playing
|
||||
return art.playing || (video.paused === false && !video.ended && video.readyState > 2)
|
||||
}
|
||||
|
||||
function listen(event: AudioEvent, callback: () => void) {
|
||||
const listener = () => {
|
||||
if (active)
|
||||
@@ -54,7 +63,7 @@ export default function artplayerPluginAudioTrack(option: Option) {
|
||||
listen('seek', syncAudio)
|
||||
listen('video:seeked', () => {
|
||||
syncAudio()
|
||||
if (art.playing)
|
||||
if (canResumeAudio())
|
||||
track.play()
|
||||
})
|
||||
listen('video:timeupdate', () => {
|
||||
@@ -69,7 +78,13 @@ export default function artplayerPluginAudioTrack(option: Option) {
|
||||
audio.muted = art.muted
|
||||
})
|
||||
listen('video:playing', () => {
|
||||
if (art.playing) {
|
||||
if (canResumeAudio()) {
|
||||
syncAudio()
|
||||
track.play()
|
||||
}
|
||||
})
|
||||
listen('video:canplay', () => {
|
||||
if (audio.paused && canResumeAudio()) {
|
||||
syncAudio()
|
||||
track.play()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user