Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 audio IE9 error: Unexpected call to method or property access

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

When I start the page I get an error: Unexpected call to method or property access.

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'm calling my audio tag in javascript like that:

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

Then I'm pausing it because I have a mute button and I need to pause all songs on my page in order for mute to work.

musicGame.pause();

This is where IE9 throws an error.

Any ideas what could be wrong?

like image 408
JanHocevar Avatar asked Aug 17 '12 09:08

JanHocevar


1 Answers

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

Try setting your preload attribute since IE9 might have issues with the preload attribute, so try and set 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 (e.g. length) is fetched; It also allows the browser to just download enough of the file to fetch metadata like size, dimensions, and duration.

Sometimes preload="auto" might work, but you will have to test!?

You might have to specify your audio source in the audio elements src attribute instead, without a child source element

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

Also are using the right DOCTYPE for HTML5?

<!DOCTYPE html>

And are using 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] have you also tried to just use?

document.getElementById("musicGame");

Some useful resource links:

  • https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio
  • https://msdn.microsoft.com/en-us/library/gg589529%28v=vs.85%29.aspx
  • https://msdn.microsoft.com/en-us/library/hh772923%28v=vs.85%29.aspx
like image 145
Jonathan Marzullo Avatar answered Nov 15 '22 01:11

Jonathan Marzullo