ulvis.paste.net

Paste Search Dynamic
Recent pastes
play sound
  1. var lPlaySound=1;
  2. function PlaySound(cLink)
  3. {
  4. //      alert(cLink);
  5.         if(lPlaySound==1)
  6.                 document.getElementById("sndspan").innerHTML="<embed src='"+cLink+"' hidden=true autostart=true loop=false>";
  7. }
  8. function SoundLink(cLink)
  9. {
  10.         if(lPlaySound==1)
  11.                 return void(0);
  12.         else
  13.                 window.open(cLink);
  14. }
  15.  
  16. function SoundDownload(cLink)
  17. {
  18.         window.open(cLink);
  19. }
  20.  
  21.  
  22.  
  23. var soundEmbed = null;
  24.  
  25. function IsHtml5SoundSupported() {
  26.     var a = document.createElement('audio');
  27.     return !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, ''));
  28. }
  29.  
  30.  
  31. function PlaySound2(SoundFile) {
  32.  
  33.     if (IsHtml5SoundSupported())
  34.         PlaySoundHtml5(SoundFile);
  35.     else {
  36.  
  37.         if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent))
  38.             PlaySoundMobile(SoundFile);
  39.         else
  40.             PlaySoundWeb(SoundFile);
  41.     }
  42.    
  43. }
  44. function PlaySoundMobile(SoundFile) {
  45.         $(".sndaudio").unbind()
  46.         $(".sndaudio").remove();
  47.         $(".sndembed").unbind()
  48.         $(".sndembed").remove();
  49.  
  50.         var sound = $("<audio class='sndaudio' autoplay='autoplay'><source src='" + SoundFile + "' type='audio/mpeg' /><embed class='sndembed' height='50' width='100' src='" + SoundFile + "' hidden='true' autostart='true' display='none'/></audio>");
  51.         $('body').append(sound);
  52. }
  53.  
  54. function PlaySoundWeb(SoundFile) {
  55.     if (!soundEmbed) {
  56.         soundEmbed = document.createElement("embed");
  57.         soundEmbed.setAttribute("src", SoundFile);
  58.         soundEmbed.setAttribute("hidden", true);
  59.         soundEmbed.setAttribute("autostart", true);
  60.     }
  61.     else {
  62.         document.body.removeChild(soundEmbed);
  63.         soundEmbed.removed = true;
  64.         soundEmbed = null;
  65.         soundEmbed = document.createElement("embed");
  66.         soundEmbed.setAttribute("src", SoundFile);
  67.         soundEmbed.setAttribute("hidden", true);
  68.         soundEmbed.setAttribute("autostart", true);
  69.     }
  70.     soundEmbed.removed = false;
  71.     document.body.appendChild(soundEmbed);
  72. }
  73. function PlaySoundHtml5(SoundFile) {
  74.     var snd = new Audio(SoundFile);
  75.     snd.load();
  76.     snd.play();
  77. }
Parsed in 0.015 seconds