craigsapp / performances

Score-audio alignment demo website
https://performances.sapp.org
1 stars 0 forks source link

interaction between audio controls and keypresses #1

Open craigsapp opened 4 years ago

craigsapp commented 4 years ago

on https://performances.sapp.org, the audio playback can be started/stopped (paused) in three ways:

(1) Press the play/pause/stop buttons in the audio controls at the bottom of the page

(2) Press the space bar to start/stop (pause) the audio playback

and

(3) Click on a note to start the recording at a given note.

A problem occurs when changing between methods 1 and 2:


The problem is most likely related to the musicbox.states.playing variable which is set to 1 when playing and 0 when not playing:

https://github.com/craigsapp/musicbox/blob/0766462f/src/scripts/musicbox.js#L31

And/or somehow the audio play/stop callbacks are not called in the same way between the keypress and audio controls interfaces:

https://github.com/craigsapp/musicbox/blob/0766462f/src/scripts/musicbox.js#L1032-L1073

Somehow this setInterval function in playMedia may be involved:

https://github.com/craigsapp/musicbox/blob/0766462f5/src/scripts/musicbox.js#L1042-L1060

craigsapp commented 4 years ago

The problem occurs in Chrome and Opera web browsers, but not in Safari or Firefox browsers. So perhaps it is a bug in the browser and/or the audio controls bypass the user-provided callbacks.

PiotrSzy commented 4 years ago

The problem occurs also in Firefox on Linux.

PiotrSzy commented 4 years ago

This is what is going on:

When the player is focused (i.e. because you clicked play button with a mouse) and space is pressed:

The bug does not occur then you move the focus away from the player before pressing space.

PiotrSzy commented 4 years ago

I am unable find any mean to prevent Firefox from processing space key when player is in focus. So I suggest not processing space in musicbox.js in this case by adding

//let the control handle space key if (document.activeElement === iface) break;

after this line https://github.com/craigsapp/musicbox/blob/0766462f525a0f998353e8fbe71d641842b4f7d8/src/scripts/musicbox.js#L883

However in this case space will not work when the browser doesn't handle it internally.