How would you go on creating a repeat button?

I hope this question hasn’t been asked too many times! I have been scouring the forums but haven’t found a clear example of this kind of situation though similar cases are reported.

I have been trying to figure out the logic of creating a simple (or so I thought) repeat button for audio file to be used on an online experiment. But all of my iterations have failed, so I am asking what is the recommended/best/easiest way to do it? I have 4 video and I have a single audio file which changes for each trial and participant has to choose (by clicking the video) which is the most suitable for the audio so I want them to be able to repeat it as many times as they want. This is the python code which is on the each frame part converted automatically to JS

response = event.getKeys(keyList=['space'])
if 'space' in response: 
    if not a_sound.isPlaying:
        playcol = 'grey'
        sound_playing = True
        playbackCount += 1
        a_sound.play()
if a_sound.isPlaying:
    playcol = 'red'
elif a_sound.isFinished:
    playcol = 'green'
    response.remove('space') 

and begin routine

playbackCount = 0  # Initialize a counter
playcol = 'red'

The playcol is there as an indicator to see the audio play through and I was also trying also to have a mouse option but that works even less reliably than the keyboard. I am able to repeat the sound in the beginnign by quickly hitting space before the first audio play ends but then it stops. In the offline version there isn’t such time window and offline version also shows that the color changes as expected in the offline version, but in online version the polygon dissappears so it is currently disabled.
Thank you for your help!