mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-27 09:41:20 -08:00
Update ads docs
This commit is contained in:
1 parent
b584550917
commit
75baca8462
7 files changed
+198
-14
No files matched your search
@@ -0,0 +1,78 @@
|
||||
---
|
||||
title: How to add video ads
|
||||
sidebar_position: 5
|
||||
---
|
||||
|
||||
Video ads play before main video playback, support multiple video ads
|
||||
|
||||
<div className="run-code">▶ Run Code</div>
|
||||
|
||||
```js
|
||||
var art = new Artplayer({
|
||||
container: '.artplayer-app',
|
||||
url: 'https://artplayer.org/assets/sample/video.mp4',
|
||||
muted: true,
|
||||
autoSize: true,
|
||||
autoplay: true,
|
||||
ads: [
|
||||
{
|
||||
url: '/assets/sample/test1.mp4'
|
||||
},
|
||||
{
|
||||
url: '/assets/sample/test2.webm'
|
||||
},
|
||||
],
|
||||
controls: [
|
||||
{
|
||||
position: 'right',
|
||||
html: 'Skip The Ads',
|
||||
click: function () {
|
||||
// Skip The Ads
|
||||
art.ads.end();
|
||||
},
|
||||
},
|
||||
],
|
||||
layers: [
|
||||
{
|
||||
html: 'Skip The Ads',
|
||||
style: {
|
||||
position: 'absolute',
|
||||
top: '20px',
|
||||
right: '20px',
|
||||
},
|
||||
click: function () {
|
||||
// Skip The Ads
|
||||
art.ads.end();
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// Triggers when each video advertisement is played
|
||||
art.on('ads:start', (item) => {
|
||||
console.info('Ads is playing: ' + item.url);
|
||||
});
|
||||
|
||||
// Triggers when all video advertisements are end
|
||||
art.on('ads:end', () => {
|
||||
console.info('Ads is end');
|
||||
});
|
||||
|
||||
// Current advertising index
|
||||
console.info(art.ads.index);
|
||||
|
||||
// Whether all the advertisements are ended
|
||||
console.info(art.ads.isEnd);
|
||||
|
||||
// Whether the advertisement is playing
|
||||
console.info(art.ads.playing);
|
||||
|
||||
// The object of the prev advertisement
|
||||
console.info(art.ads.prev);
|
||||
|
||||
// The object of the current advertisement
|
||||
console.info(art.ads.current);
|
||||
|
||||
// The object of the next advertisement
|
||||
console.info(art.ads.next);
|
||||
```
|
||||
@@ -0,0 +1,78 @@
|
||||
---
|
||||
title: 如何添加视频广告
|
||||
sidebar_position: 5
|
||||
---
|
||||
|
||||
视频广告存在于正式视频播放之前,支持多个视频广告
|
||||
|
||||
<div className="run-code">▶ Run Code</div>
|
||||
|
||||
```js
|
||||
var art = new Artplayer({
|
||||
container: '.artplayer-app',
|
||||
url: 'https://artplayer.org/assets/sample/video.mp4',
|
||||
muted: true,
|
||||
autoSize: true,
|
||||
autoplay: true,
|
||||
ads: [
|
||||
{
|
||||
url: '/assets/sample/test1.mp4'
|
||||
},
|
||||
{
|
||||
url: '/assets/sample/test2.webm'
|
||||
},
|
||||
],
|
||||
controls: [
|
||||
{
|
||||
position: 'right',
|
||||
html: '跳过广告',
|
||||
click: function () {
|
||||
// 跳过广告
|
||||
art.ads.end();
|
||||
},
|
||||
},
|
||||
],
|
||||
layers: [
|
||||
{
|
||||
html: '跳过广告',
|
||||
style: {
|
||||
position: 'absolute',
|
||||
top: '20px',
|
||||
right: '20px',
|
||||
},
|
||||
click: function () {
|
||||
// 跳过广告
|
||||
art.ads.end();
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// 当每个视频广告播放时触发
|
||||
art.on('ads:start', (item) => {
|
||||
console.info('Ads is playing: ' + item.url);
|
||||
});
|
||||
|
||||
// 当全部视频广告播放完成
|
||||
art.on('ads:end', () => {
|
||||
console.info('Ads is end');
|
||||
});
|
||||
|
||||
// 当前广告的下标
|
||||
console.info(art.ads.index);
|
||||
|
||||
// 广告是否已经结束
|
||||
console.info(art.ads.isEnd);
|
||||
|
||||
// 广告是否正在播放
|
||||
console.info(art.ads.playing);
|
||||
|
||||
// 上一个广告的对象
|
||||
console.info(art.ads.prev);
|
||||
|
||||
// 当前广告的对象
|
||||
console.info(art.ads.current);
|
||||
|
||||
// 下一个广告的对象
|
||||
console.info(art.ads.next);
|
||||
```
|
||||
@@ -27,6 +27,7 @@ export default class Ads {
|
||||
}
|
||||
|
||||
play(item) {
|
||||
if (this.isEnd || !item.url) return;
|
||||
this.art.player.switchUrl(item.url);
|
||||
|
||||
this.art.once('video:timeupdate', () => {
|
||||
@@ -45,6 +46,7 @@ export default class Ads {
|
||||
}
|
||||
|
||||
end() {
|
||||
if (this.isEnd) return;
|
||||
this.isEnd = true;
|
||||
this.playing = false;
|
||||
this.art.option.url = this.urlCache;
|
||||
|
||||
+18
-6
@@ -139,6 +139,13 @@ type SubtitleOption = {
|
||||
bilingual?: boolean;
|
||||
};
|
||||
|
||||
type AdsOption = {
|
||||
/**
|
||||
* The ads video url
|
||||
*/
|
||||
url: string;
|
||||
};
|
||||
|
||||
type Option = {
|
||||
/**
|
||||
* The container mounted by the player
|
||||
@@ -308,12 +315,7 @@ type Option = {
|
||||
/**
|
||||
* Custom ads list
|
||||
*/
|
||||
ads?: {
|
||||
/**
|
||||
* The ads video url
|
||||
*/
|
||||
url: string;
|
||||
}[];
|
||||
ads?: AdsOption[];
|
||||
|
||||
/**
|
||||
* Custom layer list
|
||||
@@ -654,6 +656,16 @@ declare class Artplayer extends Player {
|
||||
switch(url: string, option?: SubtitleOption): Promise<string>;
|
||||
};
|
||||
|
||||
readonly ads: {
|
||||
index: number;
|
||||
isEnd: boolean;
|
||||
playing: boolean;
|
||||
current: AdsOption;
|
||||
prev: AdsOption;
|
||||
next: AdsOption;
|
||||
end(): void;
|
||||
};
|
||||
|
||||
readonly mobile: object;
|
||||
|
||||
readonly player: Player;
|
||||
|
||||
Reference in new issue
Block a user