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