Bug 40266 - Audio src cannot be changed in javascript
Summary: Audio src cannot be changed in javascript
Status: RESOLVED WORKSFORME
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: 420+
Hardware: PC Windows XP
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-07 14:25 PDT by Michel
Modified: 2010-06-09 11:11 PDT (History)
2 users (show)

See Also:


Attachments
simple Html file for test. Need four audio files in the folder (2.77 KB, text/html)
2010-06-08 14:10 PDT, Michel
no flags Details
audio file needed for the html test case (5.50 KB, audio/x-ogg)
2010-06-08 14:12 PDT, Michel
no flags Details
audio file needed for the html test case (5.02 KB, audio/x-ogg)
2010-06-08 14:13 PDT, Michel
no flags Details
audio file needed for the html test case (for Safari) (1.49 KB, audio/x-wav)
2010-06-08 14:13 PDT, Michel
no flags Details
audio file needed for the html test case (for Safari) (1.49 KB, audio/x-wav)
2010-06-08 14:14 PDT, Michel
no flags Details
audio file needed for the html test case (for Safari) (14.55 KB, audio/x-wav)
2010-06-08 14:15 PDT, Michel
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michel 2010-06-07 14:25:42 PDT
Component : no idea
Chrome version : 5.0.375.55

Hi,
Thank you for you great work.

I am making games and I need to play several short sounds.
I first try with :
<audio id="audiochrome">
</audio>

And in the javascript :

var mson=document.getElementById("audiochrome");
mson.src="somesound.ogg"
mson.play();

This works fine the first time, but if I call it again :

var mson=document.getElementById("audiochrome");
mson.src="anothersound.ogg"
mson.play();

The first sound is played instead of "anothersound.ogg"


=========================================================
To workaround the problem, I then created an audio at each new sound :
 // Works on Mac also
 var mson=document.getElementById("audiochrome");
 if (mson) {
    document.body.removeChild(mson);
    // to be clean... 
 }
 mson=document.createElement("audio");
 mson.id="audiochrome";
 mson.src="sound1.ogg";
 document.body.appendChild(mson);

This works fine for exactly 50 times. After that it becomes silent. 
When I try to debug, sounds come back !

So Im stuck !

I would like to be able to say for my games :
"Sounds are supported with IE AND Chome !"
instead of
"Sounds are only supported with IE" ;-)

Is ther any other way ? (I use wav with IE)
Michel
Comment 1 Alexey Proskuryakov 2010-06-08 13:36:21 PDT
Does this happen for you in Safari 5?
Comment 2 Michel 2010-06-08 14:10:43 PDT
Created attachment 58179 [details]
simple Html file for test. Need four audio files in the folder

I give you the test html file hoping I will be able in the next seconds tou give you the 4 audio file that comes with. Sorry if I cannot.
Comment 3 Michel 2010-06-08 14:12:40 PDT
Created attachment 58180 [details]
audio file needed for the html test case
Comment 4 Michel 2010-06-08 14:13:13 PDT
Created attachment 58181 [details]
audio file needed for the html test case
Comment 5 Michel 2010-06-08 14:13:56 PDT
Created attachment 58182 [details]
audio file needed for the html test case (for Safari)
Comment 6 Michel 2010-06-08 14:14:54 PDT
Created attachment 58183 [details]
audio file needed for the html test case (for Safari)
Comment 7 Michel 2010-06-08 14:15:48 PDT
Created attachment 58184 [details]
audio file needed for the html test case (for Safari)
Comment 8 Michel 2010-06-08 14:23:15 PDT
(my answer to your question seems to have dissapear...)

Thanks for your quick answer.
I just downloaded the latest Safari to make the test :
No, Safari 5 behaves correctly. I clicked over 200 times and the sound is still there. Also the first method do work properly and the sound changes everytime .src is changed.
The only thing is that I had to go back to .wav to make it work.
I wonder if .wav will be heared on a Mac and if there is a chance that Chrome will (soon) support .wav... This would prevent me of distributing 2 sets of audio files (1 set in .wav and another set for Chrome .ogg).
Comment 9 Eric Carlson 2010-06-08 21:29:54 PDT
This doesn't work the way you expect in Safari 4 because at the time it was written, the HTML5 spec required a UA to ignore a src attribute change until the "load()" method was called. This part of the spec was changed, so now WebKit loads new files as soon as the src attribute is changed.
Comment 10 Michel 2010-06-09 02:37:36 PDT
Thank you Eric, I must say that execution of the code is veryyyyyyyy loooooong in Safari 5 (PC) and some sounds are skipped if clicked too fast... (I sould say not slow enough) but it works.
I see you are from Apple, do you know if wav are played correctly in Safari on a Mac ? Does it need extra plugin (QT,...) ?

The 'bug' still exist for Chrome (execution is much more faster however) and this is where I reported it.
Comment 11 Eric Carlson 2010-06-09 06:52:20 PDT
(In reply to comment #10)
> I see you are from Apple, do you know if wav are played correctly in Safari on a Mac ? Does it need extra plugin (QT,...) ?
> 
The <audio> (and <video>) elements in Safari on Mac and Windows should play WAV files.

> The 'bug' still exist for Chrome (execution is much more faster however) and this is where I reported it.
>
If the bug is specific t to Chrome you should probably report it in the Chrome bug base. You should probably try a Chrome nightly build first to make sure the version you are testing doesn't just have the old WebKit behavior.
Comment 12 Michel 2010-06-09 11:11:51 PDT
Thanks for everything,
I think this could be closed from the WebKit side as it looks specific to Chrome only.