Skip to content

Commit

Permalink
fix(Ads): Fix muting/unmuting ads won't affect video and vice versa (#…
Browse files Browse the repository at this point in the history
…6073)

Fixes #6071
  • Loading branch information
avelad committed Jan 10, 2024
1 parent 6b7a02a commit 01a217f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/ads/client_side_ad.js
Expand Up @@ -155,6 +155,7 @@ shaka.ads.ClientSideAd = class {
* @export
*/
setVolume(volume) {
this.video_.volume = volume;
return this.manager_.setVolume(volume);
}

Expand Down Expand Up @@ -197,13 +198,14 @@ shaka.ads.ClientSideAd = class {
* @export
*/
setMuted(muted) {
this.video_.muted = muted;
// Emulate the "mute" functionality, where current, pre-mute
// volume is saved and can be restored on unmute.
if (muted) {
this.volume_ = this.getVolume();
this.setVolume(0);
this.manager_.setVolume(0);
} else {
this.setVolume(this.volume_);
this.manager_.setVolume(this.volume_);
}
}

Expand Down
8 changes: 5 additions & 3 deletions lib/ads/client_side_ad_manager.js
Expand Up @@ -234,10 +234,12 @@ shaka.ads.ClientSideAdManager = class {
videoPlayHead.currentTime = this.video_.currentTime;
});
this.eventManager_.listen(this.video_, 'volumechange', () => {
if (!this.ad_) {
return;
}
this.ad_.setVolume(this.video_.volume);
if (this.video_.muted) {
this.imaAdsManager_.setVolume(0);
} else {
this.imaAdsManager_.setVolume(this.video_.volume);
this.ad_.setMuted(true);
}
});
}
Expand Down

0 comments on commit 01a217f

Please sign in to comment.