Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am trying to play an audio file which i uploaded using a image button using html. I used a <embed> tag which is created when i click on that image. But sadly this works only in chrome not in FF or IE.. Can anyone pls help. The javascript is used is below

JavaScript
function DHTMLSoundOnBusyGreeting(surl) {
       try {
           document.getElementById("imgPlayBusyGreeting").innerHTML = "<embed id='embedWav' src='" + surl + "' hidden=true autostart=true loop=false '><noembed><bgsound src=" + surl + " volume=100></noembed>";
           document.getElementById("hideAudioBusyGreeting").style.display = "";
       }
       catch (e) {
           alert(e.Message)
       }
   }
Posted
Comments
sajjad hasanzadeh 19-Sep-13 2:00am    
Different Ways to Play a Sound from a Web Page
See: http://www.phon.ucl.ac.uk/home/mark/audio/play.htm
Arjun Menon U.K 19-Sep-13 3:56am    
Hi sajjad, the got the code from the mentioned site and it doesn't seems to work :(

1 solution

Hi Arjun,

Try this code
First Add div to your page
HTML
<div style="display: none" id="divSound"></div>


then add following js code to your script file.
JavaScript
var val = navigator.userAgent.toLowerCase();
    if (val.indexOf("msie") > -1)
    {
        $("#divSound").html('<embed src="stompa.mp3" autostart=true width=0 height=0 id="LegacySound" enablejavascript="true" >');
    } else
    {
        var audio = new Audio();
        audio.src = 'stompa.mp3';
        audio.play();
    }


this should be working in all browser.
Hope this helps!
 
Share this answer
 
Comments
Arjun Menon U.K 19-Sep-13 3:55am    
Hi,
can u pls explain the concept here... what does the code actually do?
Arjun Menon U.K 19-Sep-13 4:00am    
msie = Microsoft IE?
Arjun Menon U.K 19-Sep-13 4:36am    
didn't work in FF
bitofweb 19-Sep-13 4:45am    
Hi Arjun,
we are playing audio file on the basis of browser's ability to play media file.
In first line of js code we are getting browser type i.e msie is microsoft internet explorer. when the browser is IE just added the embed code to the #divsound element to play audio in background, else we are just using javascript code play audio file and this should work in FF. Do one one more thing tell me which version of FF you are using, is the version of FF supports HTML5.
Arjun Menon U.K 19-Sep-13 4:53am    
24.0 this is the version of firefox am using and if my memory is correct audio tag wont work in FF

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900