HTML5 Audio Error IE9: Unexpected Method Call or Property Access

I have a problem with part of my javascript code in IE9.

When I start the page, I get the error message: An unexpected call to a method or access to properties .

This is my audio tag in html file:

<audio controls loop preload id="musicGame"> <source src="mp3/ambient.ogg" type="audio/ogg" /> <source src="mp3/ambient.mp3" type="audio/mpeg" /> </audio> 

I call my sound tag in javascript as follows:

 musicGame = $('#musicGame')[0]; 

Then I pause it because I have a mute button, and I need to pause all the songs on my page to mute it.

 musicGame.pause(); 

Here, IE9 throws an error.

Any ideas what could be wrong?

+7
source share
3 answers

oog not supported in IE .. mp3 however is supported in IE9 + ..

Try setting your preload attribute since IE9 may have problems with the preload attribute, so try setting it to preload="metadata"

 <audio controls loop preload="metadata" id="musicGame"> <source src="mp3/ambient.ogg" type="audio/ogg" /> <source src="mp3/ambient.mp3" type="audio/mpeg" /> </audio> 
  • metadata : indicates that only audio metadata is selected (e.g. length); It also allows the browser to simply download enough file to extract metadata, such as size, size, and duration.

Sometimes preload="auto" may work, but you will need to check !?

You may need to specify your audio source in the audio elements src attribute, without a source child

 <audio src="mp3/ambient.mp3" controls autoplay loop id="musicGame"> HTML5 audio not supported </audio> 

Also using DOCTYPE rights for HTML5?

 <!DOCTYPE html> 

And do you use the right meta tag for IE9 like this?

 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 

And instead of using $('#musicGame')[0] you also tried to just use?

 document.getElementById("musicGame"); 

Some useful links to resources:

+2
source

Mp3 works, the problem is that IE plays .wav and .ogg

Works in IE9 - Chrome - Safari and firefox

 var sound = new Audio("/pop.mp3"); sound.play(); 
0
source

Add the DOCTYPE <!DOCTYPE html> declaration at the beginning of your html code. It tells the browser how to display the page in standard mode. HTML5 audio will now work in IE9.

0
source

All Articles