Skip to content

Instantly share code, notes, and snippets.

@harrynewsome
Created October 31, 2017 09:51
Show Gist options
  • Save harrynewsome/cf0e867384fc0975ae46c8b21f7308ad to your computer and use it in GitHub Desktop.
Save harrynewsome/cf0e867384fc0975ae46c8b21f7308ad to your computer and use it in GitHub Desktop.
aVOZoO
<a href="https://codepen.io/harrynewsome/pen/aVOZoO">hax</a>
//Create the audio tag
var soundFile = document.createElement("audio");
soundFile.preload = "auto";
//Load the sound file (using a source element for expandability)
var src = document.createElement("source");
// src.src = "https://music.wixstatic.com/preview/7a344d_b59ac25d509d44e78f4029bb83a746d7-128.mp3";
soundFile.appendChild(src);
//Load the audio tag
//It auto plays as a fallback
soundFile.load();
soundFile.volume = 1;
soundFile.play();
//Plays the sound
function play() {
//Set the current time for the audio file to the beginning
soundFile.currentTime = 0.01;
soundFile.volume = volume;
//Due to a bug in Firefox, the audio needs to be played after a delay
setTimeout(function(){soundFile.play();},1);
}
setTimeout(function(){
console.log("refreshing");
$('a').click();
}, 2000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment