Closed Bug 816041 Opened 12 years ago Closed 2 years ago

HTML5 audio doesn't pause for short sounds

Categories

(Core :: Audio/Video: Playback, defect, P2)

8 Branch
x86_64
Windows 7
defect

Tracking

()

RESOLVED INACTIVE

People

(Reporter: misiur66, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: regression, Whiteboard: [games:p?])

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.25 Safari/537.17

Steps to reproduce:

http://jsfiddle.net/LrC9n/1/ - simple (short) sounds player on element hover. After facing this bug, I've tried also creating multiple Audio instances instead of pausing and changing source of this one - it didn't help, because pause didn't occur. 


Actual results:

When the audio is too short, and there is less than 1 second to end of audio the pause doesn't occur at all (even though paused property is set to true), and the sounds are overlapping.


Expected results:

The currently played sound should pause at all times when called audio.pause() (like in webkit based browsers).
Regression window(m-c)
Good:
http://hg.mozilla.org/mozilla-central/rev/e899fed03195
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0a1) Gecko/20110710 Firefox/8.0a1 ID:20110712003921
Bad:
http://hg.mozilla.org/mozilla-central/rev/699ee4c1a495
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0a1) Gecko/20110712 Firefox/8.0a1 ID:20110712015625
Pushlog:
http://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=e899fed03195&tochange=699ee4c1a495

Regression window(m-i)
Good:
http://hg.mozilla.org/integration/mozilla-inbound/rev/6c328da30bed
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0a1) Gecko/20110711 Firefox/8.0a1 ID:20110711194529
Bad:
http://hg.mozilla.org/integration/mozilla-inbound/rev/c8afe7ab83e7
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0a1) Gecko/20110711 Firefox/8.0a1 ID:20110711224743
Pushlog:
http://hg.mozilla.org/integration/mozilla-inbound/pushloghtml?fromchange=6c328da30bed&tochange=c8afe7ab83e7
Suspected : Bug 592833
Blocks: 592833
Component: Untriaged → Video/Audio
Keywords: regression
Product: Firefox → Core
Version: 20 Branch → 8 Branch
Status: UNCONFIRMED → NEW
Ever confirmed: true
Marking as blocking gecko-games since this is a common use case in gamedev.
Blocks: gecko-games
I wrote a HTML5 drum machine emulator, here, http://thedecibelkid.com/?45 - works fine in chrome but this bug prevents it from working in firefox!
I'm not sure what problem you hear, I'm hearing the same output between Chromium stable and Firefox Nightly. If you could describe in more depth the problem you are experiencing, it would be great.
Flags: needinfo?(hardacreric)
try this, should hear 3 quick sounds then a pause. On my build i only hear two - first and third, with the bug killing off the middle one. http://thedecibelkid.com/?45#4z161z16zc30zc34zc32
Flags: needinfo?(hardacreric)
Basically if the sample is longer than the retrigger then firefox ignores it, insisting it has to play to the end before allowing you to restart from the beginning. Code is like this:

function play(a)
{
   a.pause(); 
   a.currentTime=0;
   a.play();
}
You should test using a nightly build [1]. I can't reproduce on my machine.

[1]: http://nightly.mozilla.org/
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20130326 Firefox/22.0 ID:20130326030941 CSet: 456cb08f8509

I can reproduce just fine. It may be platform dependent.
From a high level, if currentTime represents seconds then is there some kind of rounding issue where at some point in the pipeline? e.g. if the currentTime is actually at 0.3 seconds it's easy to see that that rounds down to 0, so maybe some code (in an effort not to waste cycles doing work that has already been done) is not seeking because it's "close enough"?
Ric,

No rounding happens when seeking.

The right way to do what you want to do to clone the node you want to play when you want to play it:

>  function play(element) {
>    element.cloneNode(false).play()
>  }

This is fast in Gecko (it has been fastpathed), and allows you to trigger a sample before the end of the same sample. This is a technique that has been use with success by a lot of video game developers.
the correct way to play a sound from position zero is to clone it and play the clone? as opposed to just saying "go to position zero"...
Not saying that we don't have a bug, just saying what works. I've checked on other machines and I cannot repro on Linux, but can repro on Windows and MacOS. Not sure if it is because my Linux machine is way beefier that the two others.
OK, that does work, but it appears (Win64) that the clones aren't being garbage collected as the memory usage of firefox keeps increasing (only page open, no other requests or resources loading)
The GC should happen eventually, unless you're still storing references to the audio elements somewhere (like you have an event listener still attached for example).

You can force the audio element to release its decoder by removing the "src" attribute and then calling "load()". A good time to do this would be in the ended listener, i.e.:

audioElementClone.addEventListener("ended", function(e){e.target.removeAttribute("src"); e.target.load(); }, false);
"Eventually?" I stopped watching it after it added 50MB in process explorer. No events, literally doing what padnot suggested above.

All this event attachment sounds like a lot of effort and maintenance when I already have an object there that I'd like to set to position zero.
Assignee: cpearce → nobody
Attached file short_audio.html
I can reproduce this bug on both Window 8 and Ubuntu 13.10. I tested firefox 30, 36, and 37.0a1. All these 3 version firefox has this bug.

I made a page in the attachment file to test this bug. The page plays a 0.5 second wav file and pauses the audio at 0.1 second. It works well on Chrome, but fails to pause the audio on Firefox.

Step to reproduce:

* open the attachment html file and click the "Test" button.

Expected:

* The audio is paused at 0.1 second.

Actual:

* The UI of audio controls appears paused at 0.1 second, but sound keeps going.
Assignee: nobody → xyuan
Status: NEW → ASSIGNED
Component: Audio/Video → Audio/Video: Playback
Whiteboard: [games:p2] → [games:p?]
Rank: 15
Priority: -- → P2

The bug assignee didn't login in Bugzilla in the last 7 months.
:jimm, could you have a look please?
For more information, please visit auto_nag documentation.

Assignee: xyuan → nobody
Status: ASSIGNED → NEW
Flags: needinfo?(jmathies)
Status: NEW → RESOLVED
Closed: 2 years ago
Flags: needinfo?(jmathies)
Resolution: --- → INACTIVE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: