mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-12 06:26:16 -08:00
update
This commit is contained in:
1 parent
640360abd7
commit
ff1f38aeb7
5 files changed
+111
-42
No files matched your search
@@ -6,28 +6,22 @@ var art = new Artplayer({
|
||||
fullscreenWeb: true,
|
||||
plugins: [
|
||||
artplayerPluginAds({
|
||||
// html广告,假如存在视频广告则忽略该值
|
||||
html: '123456',
|
||||
// html广告,假如是视频广告则忽略该值
|
||||
html: '<img src="/assets/sample/layer.png">',
|
||||
|
||||
// 视频广告
|
||||
video: '',
|
||||
// video: '/assets/sample/test1.mp4',
|
||||
|
||||
// 广告跳转网址,为空则不跳转
|
||||
url: 'http://artplayer.org',
|
||||
|
||||
// 必须观看的时长,期间不能被跳过
|
||||
playDuration: 0,
|
||||
playDuration: 5,
|
||||
|
||||
// 广告总时长,假如是视频广告则自动获取
|
||||
totalDuration: 0,
|
||||
totalDuration: 10,
|
||||
|
||||
// 是否允许广告全屏
|
||||
fullscreen: true,
|
||||
|
||||
// 是否允许视频广告静音
|
||||
muted: true,
|
||||
|
||||
// 多语言支持
|
||||
// 多语言
|
||||
i18n: {
|
||||
//
|
||||
},
|
||||
|
||||
@@ -149,20 +149,36 @@ var _styleLess = require("bundle-text:./style.less");
|
||||
var _styleLessDefault = parcelHelpers.interopDefault(_styleLess);
|
||||
function artplayerPluginAds(option) {
|
||||
return (art)=>{
|
||||
const { constructor: { utils: { append } , } , template: { $player } , } = art;
|
||||
const { template: { $player } , constructor: { utils: { append , setStyle } , } , } = art;
|
||||
let isEnd = false;
|
||||
let $ads = null;
|
||||
let $timer = null;
|
||||
let time = 0;
|
||||
let timer = null;
|
||||
function skip() {
|
||||
//
|
||||
isEnd = true;
|
||||
art.play();
|
||||
if (option.video) $ads.pause();
|
||||
setStyle(art.template.$ads, "display", "none");
|
||||
art.emit("artplayerPluginAds:skip", option);
|
||||
}
|
||||
function toggleFullscreen() {
|
||||
//
|
||||
function play() {
|
||||
if (isEnd) return;
|
||||
timer = setTimeout(()=>{
|
||||
time += 1;
|
||||
$timer.innerHTML = time;
|
||||
if (time >= option.totalDuration) skip();
|
||||
else play();
|
||||
}, 1000);
|
||||
}
|
||||
function toggleMuted() {
|
||||
//
|
||||
function pause() {
|
||||
if (isEnd) return;
|
||||
clearTimeout(timer);
|
||||
}
|
||||
function show() {
|
||||
art.template.$ads = append($player, '<div class="artplayer-plugin-ads"></div>');
|
||||
const html = option.video ? `<video class="artplayer-plugin-ads-video" src="${option.video}" controls="false"></video>` : option.html;
|
||||
const $ads = append(art.template.$ads, html);
|
||||
$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>');
|
||||
art.proxy($ads, "click", ()=>{
|
||||
if (option.url) window.open(option.url);
|
||||
art.emit("artplayerPluginAds:click", option);
|
||||
@@ -171,14 +187,24 @@ function artplayerPluginAds(option) {
|
||||
}
|
||||
art.on("ready", ()=>{
|
||||
art.once("play", ()=>{
|
||||
show();
|
||||
art.pause();
|
||||
const $ads = show();
|
||||
const isVideo = $ads instanceof HTMLVideoElement;
|
||||
if (option.video) {
|
||||
art.proxy($ads, "ended", skip);
|
||||
art.proxy($ads, "error", skip);
|
||||
art.proxy($ads, "loadedmetadata", ()=>{
|
||||
play();
|
||||
$ads.play();
|
||||
if ($ads.duration && $ads.duration !== Infinity) option.totalDuration = $ads.duration;
|
||||
});
|
||||
} else play();
|
||||
});
|
||||
});
|
||||
return {
|
||||
name: "artplayerPluginAds",
|
||||
skip
|
||||
skip,
|
||||
pause,
|
||||
play
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -227,7 +253,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 justify-content: center;\n align-items: center;\n display: flex;\n position: absolute;\n inset: 0;\n overflow: hidden;\n}\n\n.artplayer-plugin-ads .artplayer-plugin-ads-video {\n width: 100%;\n height: 100%;\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 position: absolute;\n top: 20px;\n right: 20px;\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,WAAW,EAAE,EACT,KAAK,EAAE,EAAE,MAAM,CAAA,EAAE,CAAA,IACpB,CAAA,EACD,QAAQ,EAAE,EAAE,OAAO,CAAA,EAAE,CAAA,IACxB,GAAG,GAAG,AAAC;QAER,SAAS,IAAI,GAAG;QACZ,EAAE;SACL;QAED,SAAS,gBAAgB,GAAG;QACxB,EAAE;SACL;QAED,SAAS,WAAW,GAAG;QACnB,EAAE;SACL;QAED,SAAS,IAAI,GAAG;YACZ,GAAG,CAAC,QAAQ,CAAC,IAAI,GAAG,MAAM,CAAC,OAAO,EAAE,0CAA0C,CAA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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 constructor: {\n utils: { append },\n },\n template: { $player },\n } = art;\n\n function skip() {\n //\n }\n\n function toggleFullscreen() {\n //\n }\n\n function toggleMuted() {\n //\n }\n\n function show() {\n art.template.$ads = append($player, '<div class=\"artplayer-plugin-ads\"></div>');\n\n const html = option.video\n ? `<video class=\"artplayer-plugin-ads-video\" src=\"${option.video}\" controls=\"false\"></video>`\n : option.html;\n\n const $ads = append(art.template.$ads, html);\n\n art.proxy($ads, 'click', () => {\n if (option.url) window.open(option.url);\n art.emit('artplayerPluginAds:click', option);\n });\n\n return $ads;\n }\n\n art.on('ready', () => {\n art.once('play', () => {\n art.pause();\n const $ads = show();\n const isVideo = $ads instanceof HTMLVideoElement;\n });\n });\n\n return {\n name: 'artplayerPluginAds',\n skip,\n };\n };\n}\n\nartplayerPluginAds.env = process.env.NODE_ENV;\nartplayerPluginAds.version = process.env.APP_VER;\nartplayerPluginAds.build = process.env.BUILD_DATE;\n\nif (typeof document !== 'undefined') {\n if (!document.getElementById('artplayer-plugin-ads')) {\n const $style = document.createElement('style');\n $style.id = 'artplayer-plugin-ads';\n $style.textContent = style;\n document.head.appendChild($style);\n }\n}\n\nif (typeof window !== 'undefined') {\n window['artplayerPluginAds'] = artplayerPluginAds;\n}\n","exports.interopDefault = function (a) {\n return a && a.__esModule ? a : {default: a};\n};\n\nexports.defineInteropFlag = function (a) {\n Object.defineProperty(a, '__esModule', {value: Line truncated
|
||||
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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zC,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: { 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
|
||||
@@ -3,32 +3,56 @@ import style from 'bundle-text:./style.less';
|
||||
export default function artplayerPluginAds(option) {
|
||||
return (art) => {
|
||||
const {
|
||||
constructor: {
|
||||
utils: { append },
|
||||
},
|
||||
template: { $player },
|
||||
constructor: {
|
||||
utils: { append, setStyle },
|
||||
},
|
||||
} = art;
|
||||
|
||||
let isEnd = false;
|
||||
let $ads = null;
|
||||
let $timer = null;
|
||||
|
||||
let time = 0;
|
||||
let timer = null;
|
||||
|
||||
function skip() {
|
||||
//
|
||||
isEnd = true;
|
||||
art.play();
|
||||
if (option.video) $ads.pause();
|
||||
setStyle(art.template.$ads, 'display', 'none');
|
||||
art.emit('artplayerPluginAds:skip', option);
|
||||
}
|
||||
|
||||
function toggleFullscreen() {
|
||||
//
|
||||
function play() {
|
||||
if (isEnd) return;
|
||||
timer = setTimeout(() => {
|
||||
time += 1;
|
||||
$timer.innerHTML = time;
|
||||
if (time >= option.totalDuration) {
|
||||
skip();
|
||||
} else {
|
||||
play();
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function toggleMuted() {
|
||||
//
|
||||
function pause() {
|
||||
if (isEnd) return;
|
||||
clearTimeout(timer);
|
||||
}
|
||||
|
||||
function show() {
|
||||
art.template.$ads = append($player, '<div class="artplayer-plugin-ads"></div>');
|
||||
|
||||
const html = option.video
|
||||
? `<video class="artplayer-plugin-ads-video" src="${option.video}" controls="false"></video>`
|
||||
: option.html;
|
||||
$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>`,
|
||||
);
|
||||
|
||||
const $ads = append(art.template.$ads, html);
|
||||
$timer = append(art.template.$ads, '<div class="artplayer-plugin-ads-timer"></div>');
|
||||
|
||||
art.proxy($ads, 'click', () => {
|
||||
if (option.url) window.open(option.url);
|
||||
@@ -40,15 +64,29 @@ export default function artplayerPluginAds(option) {
|
||||
|
||||
art.on('ready', () => {
|
||||
art.once('play', () => {
|
||||
show();
|
||||
art.pause();
|
||||
const $ads = show();
|
||||
const isVideo = $ads instanceof HTMLVideoElement;
|
||||
if (option.video) {
|
||||
art.proxy($ads, 'ended', skip);
|
||||
art.proxy($ads, 'error', skip);
|
||||
art.proxy($ads, 'loadedmetadata', () => {
|
||||
play();
|
||||
$ads.play();
|
||||
if ($ads.duration && $ads.duration !== Infinity) {
|
||||
option.totalDuration = $ads.duration;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
play();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
name: 'artplayerPluginAds',
|
||||
skip,
|
||||
pause,
|
||||
play,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
.artplayer-plugin-ads {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
position: absolute;
|
||||
z-index: 150;
|
||||
left: 0;
|
||||
@@ -14,8 +11,22 @@
|
||||
color: #fff;
|
||||
background-color: #000;
|
||||
|
||||
.artplayer-plugin-ads-html {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.artplayer-plugin-ads-video {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.artplayer-plugin-ads-timer {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user