简体   繁体   中英

how I play .Wav sound in IE7,IE8,Safari and other supported browser using javascript

I need to playing .Wav sound after success some stuff.I tried this one but its not working in IE7,IE8 and Safari whats wrong here?

var currentFile = "";
function playAudio() {
        var oAudio = document.getElementById('myaudio');

        // See if we already loaded this audio file.
        if (jQuery("#audiofile").val() !== currentFile) {

            oAudio.src = jQuery("#audiofile").val();
            currentFile = jQuery("#audiofile").val();

        }

            var test = jQuery("#myaudio");
            test.src = jQuery("#audiofile").val();
            oAudio.play();   
    }


    if (Modernizr.audio) {
            if (Modernizr.audio.wav) {
               jQuery("#audiofile").val("sound/smw_save_menu.wav"); 

            }
            if (Modernizr.audio.mp3) {
                jQuery("#audiofile").val("sound/mario_coin.mp3");

            }
        }
        else {
          jQuery("#HTML5Audio").hide();
          jQuery("#OldSound").html('<embed src="sound/smw_save_menu.wav" autostart=false width=1 height=1 id="LegacySound" enablejavascript="true" >');

        }

I need to playing .Wav sound after success some stuff.I tried this one but its not working in IE7,IE8 and Safari whats wrong here?

I'm thinking the HTML that goes into your #OldSound container needs to be closer to something like this:

var flashAudioHTML =
'<object data="sound/smw_save_menu.wav"  width="1" height="1" other_attrs...>' +
    '<embed src="sound/smw_save_menu.wav" width="1" height="1" other_attrs...>' +
'</object>';
jQuery("#OldSound").html( flashAudioHTML );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM