Help with Audio, onEnded

Hello, I am trying to make a button trigger an audio sound and navigate to another page - but don’t want to navigate to the new page until the sound is finished playing.

This is what I’ve got:

import wixLocation from ‘wix-location’ ;

export function button1_click ( event ) {
$w ( ‘#audioPlayer1’ ). play ();
$w ( ‘#audioPlayer1’ ). onEnded (() => {
wixLocation . to ( ‘/page3’ )});
}

The sound is playing, but not navigating to ‘/page3’
Any help would be most appreciated.
Thanks!

I think your OnEnded should be outside of the button1 click event handler.

Many thanks for this!!