mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-28 10:31:20 -08:00
Add support for muted ads
Allows for more reliable autoplaying when the source video has sound by muting it automatically
This commit is contained in:
1 parent
6a602f4054
commit
95e0e18ecc
1 file changed
+10
-1
@@ -18,6 +18,7 @@ export default function artplayerPluginAds(option) {
|
|||||||
url: '',
|
url: '',
|
||||||
playDuration: 5,
|
playDuration: 5,
|
||||||
totalDuration: 10,
|
totalDuration: 10,
|
||||||
|
muted: false,
|
||||||
i18n: {
|
i18n: {
|
||||||
close: '关闭广告',
|
close: '关闭广告',
|
||||||
countdown: '%s秒',
|
countdown: '%s秒',
|
||||||
@@ -32,6 +33,7 @@ export default function artplayerPluginAds(option) {
|
|||||||
url: '?string',
|
url: '?string',
|
||||||
playDuration: 'number',
|
playDuration: 'number',
|
||||||
totalDuration: 'number',
|
totalDuration: 'number',
|
||||||
|
muted: 'boolean',
|
||||||
i18n: {
|
i18n: {
|
||||||
close: 'string',
|
close: 'string',
|
||||||
countdown: 'string',
|
countdown: 'string',
|
||||||
@@ -103,7 +105,7 @@ export default function artplayerPluginAds(option) {
|
|||||||
$ads = append(
|
$ads = append(
|
||||||
art.template.$ads,
|
art.template.$ads,
|
||||||
option.video
|
option.video
|
||||||
? `<video class="artplayer-plugin-ads-video" src="${option.video}" loop playsInline></video>`
|
? `<video class="artplayer-plugin-ads-video" src="${option.video}" ${option.muted ? 'muted' : ''} loop playsInline></video>`
|
||||||
: `<div class="artplayer-plugin-ads-html">${option.html}</div>`,
|
: `<div class="artplayer-plugin-ads-html">${option.html}</div>`,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -165,6 +167,13 @@ export default function artplayerPluginAds(option) {
|
|||||||
const $volumeClose = append($muted, volumeClose);
|
const $volumeClose = append($muted, volumeClose);
|
||||||
setStyle($volumeClose, 'display', 'none');
|
setStyle($volumeClose, 'display', 'none');
|
||||||
|
|
||||||
|
// If the ad was set to muted initially, match the icon
|
||||||
|
if (option.muted) {
|
||||||
|
$ads.muted = true;
|
||||||
|
setStyle($volume, 'display', 'none');
|
||||||
|
setStyle($volumeClose, 'display', 'inline-flex');
|
||||||
|
}
|
||||||
|
|
||||||
art.proxy($muted, 'click', () => {
|
art.proxy($muted, 'click', () => {
|
||||||
$ads.muted = !$ads.muted;
|
$ads.muted = !$ads.muted;
|
||||||
if ($ads.muted) {
|
if ($ads.muted) {
|
||||||
|
|||||||
Reference in new issue
Block a user