mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-12 15:26:16 -08:00
update
This commit is contained in:
1 parent
ff1f38aeb7
commit
9716f97a51
5 files changed
+69
-19
No files matched your search
@@ -7,10 +7,10 @@ var art = new Artplayer({
|
||||
plugins: [
|
||||
artplayerPluginAds({
|
||||
// html广告,假如是视频广告则忽略该值
|
||||
html: '<img src="/assets/sample/layer.png">',
|
||||
html: '<img src="/assets/sample/poster.jpg">',
|
||||
|
||||
// 视频广告
|
||||
// video: '/assets/sample/test1.mp4',
|
||||
video: '/assets/sample/test1.mp4',
|
||||
|
||||
// 广告跳转网址,为空则不跳转
|
||||
url: 'http://artplayer.org',
|
||||
@@ -18,7 +18,7 @@ var art = new Artplayer({
|
||||
// 必须观看的时长,期间不能被跳过
|
||||
playDuration: 5,
|
||||
|
||||
// 广告总时长,假如是视频广告则自动获取
|
||||
// 广告总时长
|
||||
totalDuration: 10,
|
||||
|
||||
// 多语言
|
||||
|
||||
@@ -149,12 +149,14 @@ var _styleLess = require("bundle-text:./style.less");
|
||||
var _styleLessDefault = parcelHelpers.interopDefault(_styleLess);
|
||||
function artplayerPluginAds(option) {
|
||||
return (art)=>{
|
||||
const { template: { $player } , constructor: { utils: { append , setStyle } , } , } = art;
|
||||
let isEnd = false;
|
||||
const { template: { $player } , constructor: { utils: { query , append , setStyle } , } , } = art;
|
||||
let $ads = null;
|
||||
let $timer = null;
|
||||
let $close = null;
|
||||
let $countdown = null;
|
||||
let time = 0;
|
||||
let timer = null;
|
||||
let isEnd = false;
|
||||
function skip() {
|
||||
isEnd = true;
|
||||
art.play();
|
||||
@@ -164,9 +166,16 @@ function artplayerPluginAds(option) {
|
||||
}
|
||||
function play() {
|
||||
if (isEnd) return;
|
||||
setStyle($timer, "display", "flex");
|
||||
timer = setTimeout(()=>{
|
||||
time += 1;
|
||||
$timer.innerHTML = time;
|
||||
const playDuration = option.playDuration - time;
|
||||
if (playDuration >= 1) $close.innerHTML = `${playDuration}秒后可关闭广告`;
|
||||
else {
|
||||
$close.innerHTML = "\u5173\u95ED\u5E7F\u544A";
|
||||
art.proxy($close, "click", skip);
|
||||
}
|
||||
$countdown.innerHTML = `${option.totalDuration - time}秒`;
|
||||
if (time >= option.totalDuration) skip();
|
||||
else play();
|
||||
}, 1000);
|
||||
@@ -178,7 +187,12 @@ function artplayerPluginAds(option) {
|
||||
function show() {
|
||||
art.template.$ads = append($player, '<div class="artplayer-plugin-ads"></div>');
|
||||
$ads = append(art.template.$ads, option.video ? `<video class="artplayer-plugin-ads-video" src="${option.video}"></video>` : `<div class="artplayer-plugin-ads-html">${option.html}</div>`);
|
||||
$timer = append(art.template.$ads, '<div class="artplayer-plugin-ads-timer"></div>');
|
||||
$timer = append(art.template.$ads, `<div class="artplayer-plugin-ads-timer">
|
||||
<div class="artplayer-plugin-ads-close">${option.playDuration}秒后可关闭广告</div>
|
||||
<div class="artplayer-plugin-ads-countdown">${option.totalDuration}秒</div>
|
||||
</div>`);
|
||||
$close = query(".artplayer-plugin-ads-close", $timer);
|
||||
$countdown = query(".artplayer-plugin-ads-countdown", $timer);
|
||||
art.proxy($ads, "click", ()=>{
|
||||
if (option.url) window.open(option.url);
|
||||
art.emit("artplayerPluginAds:click", option);
|
||||
@@ -195,7 +209,6 @@ function artplayerPluginAds(option) {
|
||||
art.proxy($ads, "loadedmetadata", ()=>{
|
||||
play();
|
||||
$ads.play();
|
||||
if ($ads.duration && $ads.duration !== Infinity) option.totalDuration = $ads.duration;
|
||||
});
|
||||
} else play();
|
||||
});
|
||||
@@ -253,7 +266,7 @@ exports.export = function(dest, destName, get) {
|
||||
};
|
||||
|
||||
},{}],"1ZB0H":[function(require,module,exports) {
|
||||
module.exports = ".artplayer-plugin-ads {\n z-index: 150;\n width: 100%;\n height: 100%;\n color: #fff;\n background-color: #000;\n position: absolute;\n inset: 0;\n overflow: hidden;\n}\n\n.artplayer-plugin-ads .artplayer-plugin-ads-html {\n width: 100%;\n height: 100%;\n justify-content: center;\n align-items: center;\n display: flex;\n}\n\n.artplayer-plugin-ads .artplayer-plugin-ads-video {\n width: 100%;\n height: 100%;\n}\n\n.artplayer-plugin-ads .artplayer-plugin-ads-timer {\n position: absolute;\n top: 20px;\n right: 20px;\n}\n\n";
|
||||
module.exports = ".artplayer-plugin-ads {\n z-index: 150;\n width: 100%;\n height: 100%;\n color: #fff;\n background-color: #000;\n position: absolute;\n inset: 0;\n overflow: hidden;\n}\n\n.artplayer-plugin-ads .artplayer-plugin-ads-html {\n width: 100%;\n height: 100%;\n justify-content: center;\n align-items: center;\n display: flex;\n}\n\n.artplayer-plugin-ads .artplayer-plugin-ads-video {\n width: 100%;\n height: 100%;\n}\n\n.artplayer-plugin-ads .artplayer-plugin-ads-timer {\n font-size: 14px;\n line-height: 1;\n display: none;\n position: absolute;\n top: 10px;\n right: 10px;\n}\n\n.artplayer-plugin-ads .artplayer-plugin-ads-timer .artplayer-plugin-ads-close {\n cursor: pointer;\n background-color: #000000bf;\n border-radius: 15px;\n margin-right: 5px;\n padding: 5px 10px;\n}\n\n.artplayer-plugin-ads .artplayer-plugin-ads-timer .artplayer-plugin-ads-countdown {\n background-color: #000000bf;\n border-radius: 15px;\n padding: 5px 10px;\n}\n\n";
|
||||
|
||||
},{}]},["gEVO5"], "gEVO5", "parcelRequirea5da")
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAAA,oDAA6C;;AAE9B,SAAS,kBAAkB,CAAC,MAAM,EAAE;IAC/C,OAAO,CAAC,GAAG,GAAK;QACZ,MAAM,EACF,QAAQ,EAAE,EAAE,OAAO,CAAA,EAAE,CAAA,EACrB,WAAW,EAAE,EACT,KAAK,EAAE,EAAE,MAAM,CAAA,EAAE,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GAAG,CAAC,CAAC;aACpB;SACF,CAAC,CAAC;KACJ,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;CACb,CAAC;AAEF,OAAO,CAAC,MAAM,GAAG,SAAU,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE;IAC9C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE;QACpC,UAAU,EAAE,IAAI;QAChB,GAAG,EAAE,GAAG;KACT,CAAC,CAAC;CACJ,CAAC;;;AC9BF,MAAM,CAAC,OAAO,GAAG,kBAAkB,CAAC","sources":["src/index.js","../../node_modules/@parcel/transformer-js/src/esmodule-helpers.js","../../node_modules/@parcel/runtime-js/lib/bundles/runtime-845a50df90dd29ef.js"],"sourcesContent":["import style from 'bundle-text:./style.less';\n\nexport default function artplayerPluginAds(option) {\n return (art) => {\n const {\n template: { $player },\n constructor: {\n utils: { append, setStyle },\n },\n } = art;\n\n let isEnd = false;\n let $ads = null;\n let $timer = null;\n\n let time = 0;\n let timer = null;\n\n function skip() {\n isEnd = true;\n art.play();\n if (option.video) $ads.pause();\n setStyle(art.template.$ads, 'display', 'none');\n art.emit('artplayerPluginAds:skip', option);\n }\n\n function play() {\n if (isEnd) return;\n timer = setTimeout(() => {\n time += 1;\n $timer.innerHTML = time;\n if (time >= option.totalDuration) {\n skip();\n } else {\n play();\n }\n }, 1000);\n }\n\n function pauLine truncated
|
||||
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAAA,oDAA6C;;AAE9B,SAAS,kBAAkB,CAAC,MAAM,EAAE;IAC/C,OAAO,CAAC,GAAG,GAAK;QACZ,MAAM,EACF,QAAQ,EAAE,EAAE,OAAO,CAAA,EAAE,CAAA,EACrB,WAAW,EAAE,EACT,KAAK,E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C,CAAC,UAAU,GAAG,CAAC,GAAG;QAAC,OAAO,EAAE,CAAC;KAAC,CAAC;CAC7C,CAAC;AAEF,OAAO,CAAC,iBAAiB,GAAG,SAAU,CAAC,EAAE;IACvC,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,YAAY,EAAE;QAAC,KAAK,EAAE,IAAI;KAAC,CAAC,CAAC;CACvD,CAAC;AAEF,OAAO,CAAC,SAAS,GAAG,SAAU,MAAM,EAAE,IAAI,EAAE;IAC1C,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,SAAU,GAAG,EAAE;QACzC,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,YAAY,IAAI,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EACvE,OAAO;QAGT,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE;YAC/B,UAAU,EAAE,IAAI;YAChB,GAAG,EAAE,WAAY;gBACf,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;aACpB;SACF,CAAC,CAAC;KACJ,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;CACb,CAAC;AAEF,OAAO,CAAC,MAAM,GAAG,SAAU,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE;IAC9C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE;QACpC,UAAU,EAAE,IAAI;QAChB,GAAG,EAAE,GAAG;KACT,CAAC,CAAC;CACJ,CAAC;;;AC9BF,MAAM,CAAC,OAAO,GAAG,kBAAkB,CAAC","sources":["src/index.js","../../node_modules/@parcel/transformer-js/src/esmodule-helpers.js","../../node_modules/@parcel/runtime-js/lib/bundles/runtime-845a50df90dd29ef.js"],"sourcesContent":["import style from 'bundle-text:./style.less';\n\nexport default function artplayerPluginAds(option) {\n return (art) => {\n const {\n template: { $player },\n constructor: {\n utils: { query, append, setStyle },\n },\n } = art;\n\n let $ads = null;\n let $timer = null;\n let $close = null;\n let $countdown = null;\n\n let time = 0;\n let timer = null;\n let isEnd = false;\n\n function skip() {\n isEnd = true;\n Line truncated
|
||||
@@ -5,16 +5,18 @@ export default function artplayerPluginAds(option) {
|
||||
const {
|
||||
template: { $player },
|
||||
constructor: {
|
||||
utils: { append, setStyle },
|
||||
utils: { query, append, setStyle },
|
||||
},
|
||||
} = art;
|
||||
|
||||
let isEnd = false;
|
||||
let $ads = null;
|
||||
let $timer = null;
|
||||
let $close = null;
|
||||
let $countdown = null;
|
||||
|
||||
let time = 0;
|
||||
let timer = null;
|
||||
let isEnd = false;
|
||||
|
||||
function skip() {
|
||||
isEnd = true;
|
||||
@@ -26,9 +28,21 @@ export default function artplayerPluginAds(option) {
|
||||
|
||||
function play() {
|
||||
if (isEnd) return;
|
||||
setStyle($timer, 'display', 'flex');
|
||||
|
||||
timer = setTimeout(() => {
|
||||
time += 1;
|
||||
$timer.innerHTML = time;
|
||||
|
||||
const playDuration = option.playDuration - time;
|
||||
if (playDuration >= 1) {
|
||||
$close.innerHTML = `${playDuration}秒后可关闭广告`;
|
||||
} else {
|
||||
$close.innerHTML = '关闭广告';
|
||||
art.proxy($close, 'click', skip);
|
||||
}
|
||||
|
||||
$countdown.innerHTML = `${option.totalDuration - time}秒`;
|
||||
|
||||
if (time >= option.totalDuration) {
|
||||
skip();
|
||||
} else {
|
||||
@@ -52,7 +66,16 @@ export default function artplayerPluginAds(option) {
|
||||
: `<div class="artplayer-plugin-ads-html">${option.html}</div>`,
|
||||
);
|
||||
|
||||
$timer = append(art.template.$ads, '<div class="artplayer-plugin-ads-timer"></div>');
|
||||
$timer = append(
|
||||
art.template.$ads,
|
||||
`<div class="artplayer-plugin-ads-timer">
|
||||
<div class="artplayer-plugin-ads-close">${option.playDuration}秒后可关闭广告</div>
|
||||
<div class="artplayer-plugin-ads-countdown">${option.totalDuration}秒</div>
|
||||
</div>`,
|
||||
);
|
||||
|
||||
$close = query('.artplayer-plugin-ads-close', $timer);
|
||||
$countdown = query('.artplayer-plugin-ads-countdown', $timer);
|
||||
|
||||
art.proxy($ads, 'click', () => {
|
||||
if (option.url) window.open(option.url);
|
||||
@@ -72,9 +95,6 @@ export default function artplayerPluginAds(option) {
|
||||
art.proxy($ads, 'loadedmetadata', () => {
|
||||
play();
|
||||
$ads.play();
|
||||
if ($ads.duration && $ads.duration !== Infinity) {
|
||||
option.totalDuration = $ads.duration;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
play();
|
||||
|
||||
@@ -25,8 +25,25 @@
|
||||
}
|
||||
|
||||
.artplayer-plugin-ads-timer {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
|
||||
.artplayer-plugin-ads-close {
|
||||
background-color: rgb(0 0 0 / 75%);
|
||||
border-radius: 15px;
|
||||
margin-right: 5px;
|
||||
padding: 5px 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.artplayer-plugin-ads-countdown {
|
||||
background-color: rgb(0 0 0 / 75%);
|
||||
border-radius: 15px;
|
||||
padding: 5px 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user