feat: update version to 1.0.2 and enhance ad event handling in VAST plugin

This commit is contained in:
Harvey Zack committed 2025-08-19 09:19:31 +08:00
1 parent eccea444b0
commit 68b40de93c
2 files changed
+17 -14

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "artplayer-plugin-vast",
"version": "1.0.1",
"version": "1.0.2",
"description": "VAST plugin for ArtPlayer",
"author": "Harvey Zack <laozhaochaguan@gmail.com>",
"license": "MIT",
+16 -13
View File
@@ -37,35 +37,38 @@ export default function artplayerPluginVast(callback) {
}
function initPlayer() {
if (imaPlayer)
return imaPlayer
$container = createContainer()
$player.appendChild($container)
imaPlayer = new Player(ima, $video, $container, adsRenderingSettings, playerOptions)
// ✅ 事件绑定
imaPlayer.onAdStarted = () => {
imaPlayer.addEventListener('AdStarted', () => {
isAdPlaying = true
$container.style.display = 'block'
art.pause()
}
})
imaPlayer.onAdEnd = () => {
imaPlayer.addEventListener('AdComplete', () => {
isAdPlaying = false
$container.style.display = 'none'
art.play()
}
})
imaPlayer.onAdError = (error) => {
console.error('VAST Ad Error:', error)
imaPlayer.addEventListener('AdError', (event) => {
console.error('VAST Ad Error:', event.detail)
isAdPlaying = false
$container.style.display = 'none'
art.play()
}
})
return imaPlayer
}
function destroyPlayer() {
if ($container && $container.parentNode) {
if (imaPlayer?.destroy)
imaPlayer.destroy()
if ($container?.parentNode)
$container.parentNode.removeChild($container)
}
$container = null
imaPlayer = null
}