sound.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // script.aculo.us sound.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008
  2. // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
  3. //
  4. // Based on code created by Jules Gravinese (http://www.webveteran.com/)
  5. //
  6. // script.aculo.us is freely distributable under the terms of an MIT-style license.
  7. // For details, see the script.aculo.us web site: http://script.aculo.us/
  8. Sound = {
  9. tracks: {},
  10. _enabled: true,
  11. template:
  12. new Template('<embed style="height:0" id="sound_#{track}_#{id}" src="#{url}" loop="false" autostart="true" hidden="true"/>'),
  13. enable: function(){
  14. Sound._enabled = true;
  15. },
  16. disable: function(){
  17. Sound._enabled = false;
  18. },
  19. play: function(url){
  20. if(!Sound._enabled) return;
  21. var options = Object.extend({
  22. track: 'global', url: url, replace: false
  23. }, arguments[1] || {});
  24. if(options.replace && this.tracks[options.track]) {
  25. $R(0, this.tracks[options.track].id).each(function(id){
  26. var sound = $('sound_'+options.track+'_'+id);
  27. sound.Stop && sound.Stop();
  28. sound.remove();
  29. })
  30. this.tracks[options.track] = null;
  31. }
  32. if(!this.tracks[options.track])
  33. this.tracks[options.track] = { id: 0 }
  34. else
  35. this.tracks[options.track].id++;
  36. options.id = this.tracks[options.track].id;
  37. $$('body')[0].insert(
  38. Prototype.Browser.IE ? new Element('bgsound',{
  39. id: 'sound_'+options.track+'_'+options.id,
  40. src: options.url, loop: 1, autostart: true
  41. }) : Sound.template.evaluate(options));
  42. }
  43. };
  44. if(Prototype.Browser.Gecko && navigator.userAgent.indexOf("Win") > 0){
  45. if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('QuickTime') != -1 }))
  46. Sound.template = new Template('<object id="sound_#{track}_#{id}" width="0" height="0" type="audio/mpeg" data="#{url}"/>')
  47. else
  48. Sound.play = function(){}
  49. }