2

I have embeded a music in a webpage using this code:

<embed src="upload/gnossiennes.mp3" autostart="true" loop="true" hidden="true"></embed>

Then I am using this javascript code to start/stop it:

<script type="text/javascript">
    function play() {
        document.embeds[0].play();
    }
    function stop() {
        document.embeds[0].stop();
    }
</script> 

<span><a href="#" onClick="play();">START</a></span>
<span><a href="#" onClick="stop();">STOP</a></span>

This works only in IE but not in Chrome, FireFox and Opera. What can be the problem? (this is the only embed in the page so I guess document.embeds[0] is only referring to this embed and shouldnt be the problem, unless this array does not exist in other browsers!

Dumbo
  • 13,555
  • 54
  • 184
  • 288
  • and you have to use `embed` and can't use `audio`? or would be a solution with `audio` also okay? – Neysor Mar 17 '12 at 12:42
  • Well I would use anything that works...I am thinking of cross borwser compatibiity and being able to start / stop the music. – Dumbo Mar 17 '12 at 12:54

1 Answers1

0

Well referencing one <embed> could be fatal for prospective uses of more embed tags. If you simply want to start and stopit then simply create and remove it as a DOM element. Here was a similar question and had the same solution

Community
  • 1
  • 1
jmishra
  • 2,086
  • 2
  • 24
  • 38