Skip to content

Instantly share code, notes, and snippets.

@will-in-wi
Created December 10, 2012 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save will-in-wi/4251919 to your computer and use it in GitHub Desktop.
Save will-in-wi/4251919 to your computer and use it in GitHub Desktop.
Soundmanager Test
<!doctype html>
<html>
<head>
<title>This is an audio tag test.</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<style>
.button {
display: block;
padding: 10px;
border: 1px solid gray;
color: white;
text-decoration: none;
font-weight: bold;
border-radius: 10px;
background-color: green;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="soundmanager/script/soundmanager2.js"></script>
<script>
var sound1url = 'sounds/turret-1.mp3';
var sound2url = 'sounds/explo6b.mp3';
$(function(){
$('.fire1').click(function(e){
e.preventDefault();
var aud1 = new Audio();
aud1.src = sound1url;
aud1.play();
aud1.addEventListener('ended', next_sound, false);
function next_sound () {
var aud2 = new Audio();
aud2.src = sound2url;
aud2.play();
}
});
});
$(function(){
$('.fire2').click(function(e){
e.preventDefault();
var aud = new Audio();
aud.src = sound1url;
aud.play();
aud.addEventListener('ended', next_sound, false);
function next_sound () {
aud.src = sound2url;
aud.play();
aud.removeEventListener('ended', next_sound, false);
}
});
});
$(function(){
soundManager.setup({
url: 'soundmanager/swf/',
flashVersion: 9,
useFlashBlock: false,
onready: function() {
$('.fire3').click(function(e){
e.preventDefault();
var mySound = soundManager.createSound({
id: 'sound1test1',
url: sound1url,
onfinish: function() {
mySound.load({
url: sound2url,
onfinish: null
});
mySound.play();
}
});
mySound.play();
});
$('.fire4').click(function(e){
e.preventDefault();
var mySound = soundManager.createSound({
id: 'sound1test2',
url: sound1url,
onfinish: function() {
var sound2 = soundManager.createSound({
id: 'sound2test2',
url: sound2url,
});
sound2.play();
}
});
mySound.play();
});
$('.fire5').click(function(e){
e.preventDefault();
var mySound = soundManager.createSound({
id: 'sound1test3',
url: sound1url,
onfinish: function() {
soundManager.load('sound1test3', {
url: sound2url,
onfinish: null
});
soundManager.play('sound1test3');
}
});
mySound.play();
});
}
});
});
</script>
</head>
<body>
<div>
<h1>Audio Tag Test</h1>
<p><strong>Be sure to reload your browser before each test.</strong> All tests should play two sounds, one after another. You should hear a blaster fire followed by an explosion. Please ru
n the tests and report the results.</p>
<h2>Pure Javascript</h2>
<h3>Using different audio objects</h3>
<a class="fire1 button" href="#">Fire</a>
<h3>Using the Same audio object</h3>
<a class="fire2 button" href="#">Fire</a>
<h2>Soundmanager</h2>
<h3>Using the same variable</h3>
<a class="fire3 button" href="#">Fire</a>
<h3>Using different variables</h3>
<a class="fire4 button" href="#">Fire</a>
<h3>Using the same id</h3>
<a class="fire5 button" href="#">Fire</a>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment