Video Strip Audio Toggle - Code Correction Help

I needed an option to toggle the sound on and off for a video strip, and as this is not standard, I had to code it in.

The way I did it was to load video strip as usual, but hidden on the page is an audio player that plays the video audio as an .mp3 on.ready. As the audio loads before the video, I needed to add a setTimeout function to the approximate delay. The volume of the audio player is linked to a slide switch where on = 100 and off = 0 volume.

In the editor preview, this all works as it’s supposed to, and I can toggle the sound, but on my test version of the site ( https://breakscape.wixsite.com/website-1 this relates to the main video strip at the top), the toggle only works if you click it right at the start. (I think this has something to do with the setTimeout?).

My code is below, if someone is able to have a look at it and let me know what might be going wrong it would be much appreciated! I’m a little stuck on this one.

export function switch1_change(event) {
    if ($w('#switch1').checked) {
        $w('#audioPlayer1').volume = 100;
        
        } else {
            $w('#audioPlayer1').volume = 0;
            
            }
        }
        
$w.onReady(function () {
    setTimeout(function () {
        $w('#audioPlayer1').play()
    }, 1200);
    $w('#audioPlayer1').volume = 0;
    $w('#switch1').checked = false
})