mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-28 10:31:20 -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",
|
"name": "artplayer-plugin-vast",
|
||||||
"version": "1.0.2",
|
"version": "1.1.0",
|
||||||
"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",
|
||||||
@@ -35,6 +35,6 @@
|
|||||||
"legacy": "./dist/artplayer-plugin-vast.legacy.js",
|
"legacy": "./dist/artplayer-plugin-vast.legacy.js",
|
||||||
"browserslist": "last 1 Chrome version",
|
"browserslist": "last 1 Chrome version",
|
||||||
"dependencies": {
|
"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 = new Player(ima, $video, $container, adsRenderingSettings, playerOptions)
|
||||||
|
|
||||||
imaPlayer.addEventListener('AdStarted', () => {
|
imaPlayer.addEventListener('AdContentPauseRequested', () => {
|
||||||
isAdPlaying = true
|
isAdPlaying = true
|
||||||
$container.style.display = 'block'
|
$container.style.display = 'block'
|
||||||
})
|
})
|
||||||
|
|
||||||
imaPlayer.addEventListener('AdComplete', () => {
|
imaPlayer.addEventListener('AdContentResumeRequested', () => {
|
||||||
isAdPlaying = false
|
isAdPlaying = false
|
||||||
$container.style.display = 'none'
|
$container.style.display = 'none'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
imaPlayer.addEventListener('AdStarted', () => {
|
||||||
|
isAdPlaying = true
|
||||||
|
$container.style.display = 'block'
|
||||||
|
})
|
||||||
|
|
||||||
imaPlayer.addEventListener('AdError', (event) => {
|
imaPlayer.addEventListener('AdError', (event) => {
|
||||||
console.error('VAST Ad Error:', event.detail)
|
console.error('VAST Ad Error:', event.detail)
|
||||||
isAdPlaying = false
|
isAdPlaying = false
|
||||||
@@ -73,23 +78,29 @@ export default function artplayerPluginVast(callback) {
|
|||||||
imaPlayer = null
|
imaPlayer = null
|
||||||
}
|
}
|
||||||
|
|
||||||
function playUrl(url) {
|
function playUrl(url, config = {}) {
|
||||||
if (isAdPlaying)
|
if (isAdPlaying)
|
||||||
return
|
return
|
||||||
if (!imaPlayer)
|
if (!imaPlayer)
|
||||||
initPlayer()
|
initPlayer()
|
||||||
const request = new ima.AdsRequest()
|
const request = new ima.AdsRequest()
|
||||||
request.adTagUrl = url
|
request.adTagUrl = url
|
||||||
|
for (const key in config) {
|
||||||
|
request[key] = config[key]
|
||||||
|
}
|
||||||
imaPlayer.playAds(request)
|
imaPlayer.playAds(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
function playRes(res) {
|
function playRes(res, config = {}) {
|
||||||
if (isAdPlaying)
|
if (isAdPlaying)
|
||||||
return
|
return
|
||||||
if (!imaPlayer)
|
if (!imaPlayer)
|
||||||
initPlayer()
|
initPlayer()
|
||||||
const request = new ima.AdsRequest()
|
const request = new ima.AdsRequest()
|
||||||
request.adsResponse = res
|
request.adsResponse = res
|
||||||
|
for (const key in config) {
|
||||||
|
request[key] = config[key]
|
||||||
|
}
|
||||||
imaPlayer.playAds(request)
|
imaPlayer.playAds(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,8 +109,13 @@ export default function artplayerPluginVast(callback) {
|
|||||||
art,
|
art,
|
||||||
playUrl,
|
playUrl,
|
||||||
playRes,
|
playRes,
|
||||||
|
init: initPlayer,
|
||||||
ima,
|
ima,
|
||||||
imaPlayer,
|
adsRenderingSettings,
|
||||||
|
playerOptions,
|
||||||
|
get imaPlayer() {
|
||||||
|
return imaPlayer
|
||||||
|
},
|
||||||
get container() {
|
get container() {
|
||||||
return $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'
|
import type Artplayer from 'artplayer'
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@@ -7,15 +7,18 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PlayUrlFn = (url: string) => void
|
type PlayUrlFn = (url: string, config?: any) => void
|
||||||
type PlayResFn = (res: string) => void
|
type PlayResFn = (res: string, config?: any) => void
|
||||||
|
|
||||||
interface VastPluginContext {
|
interface VastPluginContext {
|
||||||
art: Artplayer
|
art: Artplayer
|
||||||
ima: any // Replace 'any' with a more specific type if available, or declare google.ima type above
|
ima: any
|
||||||
imaPlayer: Player
|
imaPlayer: Player | null
|
||||||
playUrl: PlayUrlFn
|
playUrl: PlayUrlFn
|
||||||
playRes: PlayResFn
|
playRes: PlayResFn
|
||||||
|
init: () => Player
|
||||||
|
adsRenderingSettings: any
|
||||||
|
playerOptions: PlayerOptions
|
||||||
container: HTMLDivElement | null
|
container: HTMLDivElement | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user