Sound
Introduction
Use Sound
to play audio directly from the browser.
Syntax
Sound.play( url, [ options ])
Sound.enable()
Sound.disable()
Play Options
Option | Description |
---|---|
replace | replace the current active track, defauts to false |
Notes
- Sound.disable does not disable the playback immediately, it just prevents the next tracks from being played.
Watch the demo to see how to stop the sound immediately. - Sound.enable does not resume the playback, just allows the next track to be played.
- In Firefox 3, Sound does not work from local files, but works if served (even from localhost). As an alternative, you can change the template within sound.js from “object” to “embed” and from “data” to “src”.
Demo
Source code of the demo
<div>
URL: <input type = "text" id = "sound_demo_track_url" style = "width:400px;"
value = "http://www.joshwoodward.com/mp3/TheSimpleLife/JoshWoodward-TheSimpleLife-101-HeritagePlace.mp3"/>
<br/>
Sound: <span id = "sound_status">On</span>
<ul class = "sound_controls">
<li><a href="javascript:void(0)" id="sound_demo_play">Play</a></li>
<li><a href="javascript:void(0)" id="sound_demo_disable">Disable sound</a></li>
<li><a href="javascript:void(0)" id="sound_demo_disable_now">Disable now</a></li>
<li><a href="javascript:void(0)" id="sound_demo_enable">Enable sound</a></li>
</ul>
</div>
<script type="text/javascript">
$('sound_demo_play').observe('click', function(event) {
event.stop();
Sound.play($('sound_demo_track_url').value,{replace:true});
});
$('sound_demo_enable').observe('click', function(event) {
event.stop();
Sound.enable();
$('sound_status').innerHTML = 'On';
});
$('sound_demo_disable').observe('click', function(event) {
event.stop();
Sound.disable();
$('sound_status').innerHTML = 'Pending Off';
});
$('sound_demo_disable_now').observe('click', function(event) {
event.stop();
Sound.enable();
Sound.play('',{replace:true});
Sound.disable();
$('sound_status').innerHTML = 'Off';
});
</script>