Skip to content

Instantly share code, notes, and snippets.

@bora89
Created January 23, 2017 16:44
Show Gist options
  • Save bora89/4e3d239e7b8d71b2f9670952b84e5ebc to your computer and use it in GitHub Desktop.
Save bora89/4e3d239e7b8d71b2f9670952b84e5ebc to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Audio test</title>
<script type="text/javascript">
/**
* @param {string} filename The name of the file WITHOUT ending
*/
function playSound(filename){
document.getElementById("sound").innerHTML='<audio autoplay="autoplay"><source src="' + filename + '.mp3" type="audio/mpeg" /><source src="' + filename + '.ogg" type="audio/ogg" /><embed hidden="true" autostart="true" loop="false" src="' + filename +'.mp3" /></audio>';
}
</script>
</head>
<body>
<!-- Will try to play bing.mp3 or bing.ogg (depends on browser compatibility) -->
<button onclick="playSound('bing');">Play</button>
<div id="sound"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment