WebMIDIAPIShim icon indicating copy to clipboard operation
WebMIDIAPIShim copied to clipboard

Scheduled sends are throttled when page isn't front tab

Open nfroidure opened this issue 12 years ago • 6 comments

Hi,

I made a simple MIDI Karaoke player : http://karaoke.insertafter.com/

The problem i noticed is that when i go to another tab, the song slows down. I think that it's due to the fact that the browser limits setTimeouts for inactive tabs.

Are there a way to avoir that ? Will make the WebMIDIAPI available in WebWorkers avoid the problem ?

nfroidure avatar Sep 14 '13 09:09 nfroidure

Yes, that's the problem with the polyfill - it has to use setTimeout to do timed sends, and setTimeout is throttled by the browser. The natively-implemented Web MIDI API (in Chrome Canary under a flag now) should not have this problem, however. Unfortunately, I don't think I can get the extension used by the polyfill to work inside a worker, so I'd have to do a multi-stage system, using a worker only to get the setTimeout calls on time but then just postMessage()ing back to the main thread to dispatch. I'll keep this on the stack, but I doubt I'll get to it soon in the polyfill.

cwilso avatar Sep 15 '13 15:09 cwilso

I'll test with Chrome Canary and give the feedback here.

nfroidure avatar Sep 15 '13 16:09 nfroidure

Ooops, not available for my platform :( (Linux).

Anyway, as concluded in the issues listed above, a MIDI player will systematically have to rely on setTimeout to send MIDI events progressively to the player. That's what i did with MIDIWebKaraoke. If you use play/pause buttons you'll notice the short delay i had to set up (currently 600ms).

I assume the only way to avoid those holes will be to use the Page Visibility API to increase this delay when the page is hidden (https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API). It make senses since the user will not be able to pause the play when the page is hidden.

I'll update the code later and up this thread. I assume you have a Macn, will you accept to give a try and tell me the result ?

https://github.com/WebAudio/web-midi-api/issues/72 https://github.com/WebAudio/web-midi-api/issues/76

nfroidure avatar Sep 15 '13 16:09 nfroidure

sure.

On Sun, Sep 15, 2013 at 9:42 AM, Nicolas Froidure [email protected]:

Ooops, not available for my platform :( (Linux).

Anyway, as concluded in the issues listed above, a MIDI player will systematically have to rely on setTimeout to send MIDI events progressively to the player. That's what i did with MIDIWebKaraoke. If you use play/pause buttons you'll notice the short delay i had to set up (currently 600ms).

I assume the only way to avoid those holes will be to use the Page Visibility API to increase this delay when the page is hidden ( https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API). It make senses since the user will not be able to pause the play when the page is hidden.

I'll update the code later and up this thread. I assume you have a Macn, will you accept to give a try and tell me the result ?

WebAudio/web-midi-api#72https://github.com/WebAudio/web-midi-api/issues/72 WebAudio/web-midi-api#76https://github.com/WebAudio/web-midi-api/issues/76

— Reply to this email directly or view it on GitHubhttps://github.com/cwilso/WebMIDIAPIShim/issues/33#issuecomment-24474869 .

cwilso avatar Sep 15 '13 17:09 cwilso

I added the PageVisibility test to try to avoid the problem as announced, here is the commit: https://github.com/nfroidure/MIDIPlayer/commit/59759ea9f6a77c0c0491b5fd18a19eb2a70127f3 And here is a test URL: http://rest4.org/github/nfroidure/MIDIPlayer/master/tests/index.html

Let me know if the problem still occurs.

nfroidure avatar Sep 27 '13 12:09 nfroidure

Should really use the worker settimeout workaround here.

cwilso avatar Dec 09 '14 17:12 cwilso