Skip to content

Commit

Permalink
Publishing latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnbuso committed Mar 6, 2018
1 parent fec0710 commit d7a7eb8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions attempt_to_autoplay/ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,39 @@ function initDesktopAutoplayExample() {
videoContent.load();
playAds();
});
setUpIMA();
// Check if autoplay is supported.
checkAutoplaySupport();
setUpIMA();
}

function checkAutoplaySupport() {
// Test for autoplay support with our content player.
videoContent.play().then(onUnmutedAutoplaySuccess, onUnmutedAutoplayFail);
var playPromise = videoContent.play();
if (playPromise !== undefined) {
playPromise.then(onAutoplayWithSoundSuccess).catch(onAutoplayWithSoundFail);
}
}

function onUnmutedAutoplaySuccess() {
function onAutoplayWithSoundSuccess() {
// If we make it here, unmuted autoplay works.
videoContent.pause();
autoplayAllowed = true;
autoplayRequiresMuted = false;
autoplayChecksResolved();
}

function onUnmutedAutoplayFail() {
function onAutoplayWithSoundFail() {
// Unmuted autoplay failed. Now try muted autoplay.
checkMutedAutoplaySupport();
}

function checkMutedAutoplaySupport() {
videoContent.volume = 0;
videoContent.muted = true;
videoContent.play().then(onMutedAutoplaySuccess, onMutedAutoplayFail);
var playPromise = videoContent.play();
if (playPromise !== undefined) {
playPromise.then(onMutedAutoplaySuccess).catch(onMutedAutoplayFail);
}
}

function onMutedAutoplaySuccess() {
Expand Down

0 comments on commit d7a7eb8

Please sign in to comment.