mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 05:41:20 -08:00
add ads.js
This commit is contained in:
1 parent
0048991f7e
commit
6c32895d34
7 files changed
+124
-4
No files matched your search
@@ -0,0 +1,45 @@
|
||||
export default class Ads {
|
||||
constructor(art) {
|
||||
this.art = art;
|
||||
const { option } = art;
|
||||
|
||||
this.index = 0;
|
||||
this.playing = false;
|
||||
this.isEnd = false;
|
||||
this.urlCache = option.url;
|
||||
|
||||
if (option.ads.length) {
|
||||
this.playing = true;
|
||||
this.play(option.ads[this.index]);
|
||||
}
|
||||
}
|
||||
|
||||
get current() {
|
||||
return this.art.option.ads[this.index];
|
||||
}
|
||||
|
||||
play(item) {
|
||||
const { option, player } = this.art;
|
||||
|
||||
player.url = item.url;
|
||||
this.art.emit('ads:start', item);
|
||||
|
||||
this.art.once('video:ended', () => {
|
||||
const nextIndex = this.index + 1;
|
||||
const nextItem = option.ads[nextIndex];
|
||||
if (nextItem) {
|
||||
this.index = nextIndex;
|
||||
this.play(nextItem);
|
||||
} else {
|
||||
this.end();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
end() {
|
||||
this.playing = false;
|
||||
this.isEnd = true;
|
||||
this.art.option.url = this.urlCache;
|
||||
this.art.emit('ads:end');
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import Icons from './icons';
|
||||
import Setting from './setting';
|
||||
import Storage from './storage';
|
||||
import Plugins from './plugins';
|
||||
import Ads from './ads';
|
||||
import Mobile from './mobile';
|
||||
|
||||
let id = 0;
|
||||
@@ -52,6 +53,7 @@ export default class Artplayer extends Emitter {
|
||||
this.controls = new Control(this);
|
||||
this.contextmenu = new Contextmenu(this);
|
||||
this.subtitle = new Subtitle(this);
|
||||
this.ads = new Ads(this);
|
||||
this.info = new Info(this);
|
||||
this.loading = new Loading(this);
|
||||
this.hotkey = new Hotkey(this);
|
||||
|
||||
@@ -34,5 +34,12 @@ export default function attrInit(art, player) {
|
||||
}
|
||||
|
||||
$video.controls = false;
|
||||
player.url = option.url;
|
||||
|
||||
if (option.ads.length) {
|
||||
art.on('ads:end', () => {
|
||||
player.url = option.url;
|
||||
});
|
||||
} else {
|
||||
player.url = option.url;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user