Mobile app version of vmapp.org
Login or Join
Shelton105

: Using in Firefox with JavaScript I am trying to implement background music on a website using the audio object, which is controlled by a JavaScript, I have posted a question about this before,

@Shelton105

Posted in: #Audio #Firefox #Html5 #Javascript

I am trying to implement background music on a website using the audio object, which is controlled by a JavaScript, I have posted a question about this before, @LazyOne explained that IIS will not serve unknown MIME types, and neither will the VS development server.

I have now uploaded the site to an IIS 7 server, the MIME type for ogg is in place and when the site in accessed the server returns a 206 partial content (mozilla.org mentions that 206 responses are normal and expected for ogg files) and assessing the file directly works fine in Firefox (i.e. if you go to domain.com/music/file.ogg, it plays in the browser). and the file plays fine in the background if the autoplay attribute is set, but it does not play via JavaScript.

Here is the JavaScript in question and relevant html:

audioMusic.volume = 0.15;

function playMusic(){
audioMusic.play();
}

function stopMusic(){
audioMusic.pause();
}


Relevant html:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>

<a href="javascript:void(0)" onclick="playMusic()">on</a>
<a href="javascript:void(0)" onclick="stopMusic()">off</a>

<audio id="audioMusic" loop="loop" preload="auto">
<source src="/Music/music.ogg" type="audio/ogg" />
<source src="/Music/music.mp3" type="audio/mp3" />
</audio>

<script type="text/javascript" src="/Scripts/music.js"></script>
</body>
</html>


More interesting facts:


the playMusic() function is called in firefox, if you add an alert
at the beginning it does off, but it is not able to execute:
audioMusic.play()
I have also tried document.getElementById("audioMusic").play();
Both document.getElementById("audioMusic").play() and
audioMusic.play() work in Chrome and IE, but not in firefox
I am using Firefox 5.0.1 (the latest)


Question: how to control the audio element via JavaScript in Firefox?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Shelton105

2 Comments

Sorted by latest first Latest Oldest Best

 

@Bethany197

Well, I still don't know exactly why Firefox didn't want play that file, but if anyone is having the same issue - I ended up using jPlayer. You can download it from: www.jplayer.org/
TODO:

Place the jPlayer files in your scripts folder, then you can use this html page to implement the player on your website: pastebin.com/mhdt2m7W
Make sure to change the file names and directories as needed, namely the music file location and the location of your scripts folder.

Good luck.

10% popularity Vote Up Vote Down


 

@Hamaas447

Have you tested your HTML with W3C validator? validator.w3.org/
Also, I believe you have to use a normal object tag to play music in firefox 5. So If I were you that would be what I would test (after having valid HTML)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme