mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-11 13:56:15 -08:00
feat: update version to 1.1.0 and enhance VAST plugin with new event handling and configuration options
This commit is contained in:
1 parent
4a980971f7
commit
486231f04b
3 files changed
+31
-12
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "artplayer-plugin-vast",
|
||||
"version": "1.0.2",
|
||||
"version": "1.1.0",
|
||||
"description": "VAST plugin for ArtPlayer",
|
||||
"author": "Harvey Zack <laozhaochaguan@gmail.com>",
|
||||
"license": "MIT",
|
||||
@@ -35,6 +35,6 @@
|
||||
"legacy": "./dist/artplayer-plugin-vast.legacy.js",
|
||||
"browserslist": "last 1 Chrome version",
|
||||
"dependencies": {
|
||||
"@glomex/vast-ima-player": "^1.21.0"
|
||||
"@glomex/vast-ima-player": "^1.21.2"
|
||||
}
|
||||
}
|
||||
@@ -45,16 +45,21 @@ export default function artplayerPluginVast(callback) {
|
||||
|
||||
imaPlayer = new Player(ima, $video, $container, adsRenderingSettings, playerOptions)
|
||||
|
||||
imaPlayer.addEventListener('AdStarted', () => {
|
||||
imaPlayer.addEventListener('AdContentPauseRequested', () => {
|
||||
isAdPlaying = true
|
||||
$container.style.display = 'block'
|
||||
})
|
||||
|
||||
imaPlayer.addEventListener('AdComplete', () => {
|
||||
imaPlayer.addEventListener('AdContentResumeRequested', () => {
|
||||
isAdPlaying = false
|
||||
$container.style.display = 'none'
|
||||
})
|
||||
|
||||
imaPlayer.addEventListener('AdStarted', () => {
|
||||
isAdPlaying = true
|
||||
$container.style.display = 'block'
|
||||
})
|
||||
|
||||
imaPlayer.addEventListener('AdError', (event) => {
|
||||
console.error('VAST Ad Error:', event.detail)
|
||||
isAdPlaying = false
|
||||
@@ -73,23 +78,29 @@ export default function artplayerPluginVast(callback) {
|
||||
imaPlayer = null
|
||||
}
|
||||
|
||||
function playUrl(url) {
|
||||
function playUrl(url, config = {}) {
|
||||
if (isAdPlaying)
|
||||
return
|
||||
if (!imaPlayer)
|
||||
initPlayer()
|
||||
const request = new ima.AdsRequest()
|
||||
request.adTagUrl = url
|
||||
for (const key in config) {
|
||||
request[key] = config[key]
|
||||
}
|
||||
imaPlayer.playAds(request)
|
||||
}
|
||||
|
||||
function playRes(res) {
|
||||
function playRes(res, config = {}) {
|
||||
if (isAdPlaying)
|
||||
return
|
||||
if (!imaPlayer)
|
||||
initPlayer()
|
||||
const request = new ima.AdsRequest()
|
||||
request.adsResponse = res
|
||||
for (const key in config) {
|
||||
request[key] = config[key]
|
||||
}
|
||||
imaPlayer.playAds(request)
|
||||
}
|
||||
|
||||
@@ -98,8 +109,13 @@ export default function artplayerPluginVast(callback) {
|
||||
art,
|
||||
playUrl,
|
||||
playRes,
|
||||
init: initPlayer,
|
||||
ima,
|
||||
imaPlayer,
|
||||
adsRenderingSettings,
|
||||
playerOptions,
|
||||
get imaPlayer() {
|
||||
return imaPlayer
|
||||
},
|
||||
get container() {
|
||||
return $container
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Player } from '@glomex/vast-ima-player'
|
||||
import type { Player, PlayerOptions } from '@glomex/vast-ima-player'
|
||||
import type Artplayer from 'artplayer'
|
||||
|
||||
declare global {
|
||||
@@ -7,15 +7,18 @@ declare global {
|
||||
}
|
||||
}
|
||||
|
||||
type PlayUrlFn = (url: string) => void
|
||||
type PlayResFn = (res: string) => void
|
||||
type PlayUrlFn = (url: string, config?: any) => void
|
||||
type PlayResFn = (res: string, config?: any) => void
|
||||
|
||||
interface VastPluginContext {
|
||||
art: Artplayer
|
||||
ima: any // Replace 'any' with a more specific type if available, or declare google.ima type above
|
||||
imaPlayer: Player
|
||||
ima: any
|
||||
imaPlayer: Player | null
|
||||
playUrl: PlayUrlFn
|
||||
playRes: PlayResFn
|
||||
init: () => Player
|
||||
adsRenderingSettings: any
|
||||
playerOptions: PlayerOptions
|
||||
container: HTMLDivElement | null
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user