0
votes

the following code works as intended on all browsers except Safari (using version 5.1.7 for windows 7).

var texto01 = document.getElementById("texto01");
texto01.onkeyup = function(tecla){
    if(tecla.keyCode == 13){    //If Enter is keyup
        if((valorAnt[0] != texto01.value) && (texto01.value != "")){    //Check to see if answer has changed and field is not empty
            valorAnt[0] = texto01.value;    //Since value has change, set it to be new previous answer
            if(texto01.value == "5747"){    //Correct answer user has to type
                ctx.clearRect(739, 57, 35, 35);
                ctx.drawImage(bienImg, 739, 57);    //Tick image
                var cBien = Math.ceil(Math.random()*2); //There are two audio files that can be played if answer is correct
                var cSonidoB = "bien" + cBien;
                document.getElementById(cSonidoB).play();   //play the "random" audio for right answer
            }
            else{ //Answer is wrong
                ctx.clearRect(739, 57, 35, 35);
                ctx.drawImage(malImg, 739, 57); //X mark image
                var cMal = Math.ceil(Math.random()*3);  //There are three audio files that can be played if answer is wrong
                var cSonidoM = "mal" + cMal;
                document.getElementById(cSonidoM).play();   //play the "random" audio for wrong answer
            }
        }
    }
}//texto01

All audio tags are declared like this:

<audio id = "mal1" preload = "auto"> 
    <source src="Sounds/mal01.ogg" type="audio/ogg"></source>
    <source src="Sounds/mal01.mp3" type="audio/mpeg"></source>
</audio>

I have tried the following with no success: 1) Put the MP3 source before the OGG. 2) Changed the type to "audio/mp3" 3) Remove the "random" part of choosing which audio to play and straight up assign an audio ID to play.

1

1 Answers

0
votes

maybe you have to add some code in .htaccess like the following:

AddType audio/mpeg mp3
AddType audio/mp4 m4a
AddType audio/ogg ogg
AddType audio/ogg oga
AddType audio/webm webma
AddType audio/wav wav

AddType video/mp4 mp4
AddType video/mp4 m4v
AddType video/ogg ogv
AddType video/webm webm
AddType video/webm webmv

AddType audio/mpeg .mp3
AddType audio/mp4 .m4a
AddType audio/ogg .ogg
AddType audio/ogg .oga
AddType audio/webm .webma
AddType audio/wav .wav

AddType video/mp4 .mp4
AddType video/mp4 .m4v
AddType video/ogg .ogv
AddType video/webm .webm
AddType video/webm .webmv