mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-11 22:06:17 -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: '',
|
||||
playDuration: 5,
|
||||
totalDuration: 10,
|
||||
muted: false,
|
||||
i18n: {
|
||||
close: '关闭广告',
|
||||
countdown: '%s秒',
|
||||
@@ -32,6 +33,7 @@ export default function artplayerPluginAds(option) {
|
||||
url: '?string',
|
||||
playDuration: 'number',
|
||||
totalDuration: 'number',
|
||||
muted: 'boolean',
|
||||
i18n: {
|
||||
close: 'string',
|
||||
countdown: 'string',
|
||||
@@ -103,7 +105,7 @@ export default function artplayerPluginAds(option) {
|
||||
$ads = append(
|
||||
art.template.$ads,
|
||||
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>`,
|
||||
);
|
||||
|
||||
@@ -165,6 +167,13 @@ export default function artplayerPluginAds(option) {
|
||||
const $volumeClose = append($muted, volumeClose);
|
||||
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', () => {
|
||||
$ads.muted = !$ads.muted;
|
||||
if ($ads.muted) {
|
||||
|
||||
Reference in new issue
Block a user