lundi 21 novembre 2016

i've written a javascript code thats runs fine on other browser except safari. safari shows "Undefined is not constructor(evaluating new audio())"

//i've written a javascript code thats runs fine on other browser except safari. safari shows "Undefined is not constructor(evaluating new audio())". i want to play background music on page load

<script>
    var audio, playbtn, mutebtn, seek_bar;
    function initAudioPlayer(){
        audio = new Audio();
        audio.src = "html/audio/di-evantile_behind-your-dream.mp3";
        audio.loop = true;
        audio.play();
        // Set object references
        playbtn = document.getElementById("playpausebtn");
        mutebtn = document.getElementById("mutebtn");
        // Add Event Handling
        playbtn.addEventListener("click",playPause);
        mutebtn.addEventListener("click", mute);
        // Functions
        function playPause(){
            if(audio.paused){
                audio.play();
                playbtn.style.background = "url(html/images/pause.png) no-repeat";
            } else {
                audio.pause();
                playbtn.style.background = "url(html/images/play.png) no-repeat";
            }
        }
        function mute(){
            if(audio.muted){
                audio.muted = false;
                mutebtn.style.background = "url(html/images/speaker.png) no-repeat";
            } else {## Heading ##
                audio.muted = true;
                mutebtn.style.background = "url(html/images/speaker_muted.png) no-repeat";
            }
        }
    }
//play music on page load
    window.addEventListener("load", initAudioPlayer);
    </script>




Aucun commentaire:

Enregistrer un commentaire