Collapse a video once it has finished playing

Wondering if someone could help with this code, I have been struggling with it for a while (as a beginner).
I want to collapse or hide a video once it has finished playing. Previously I had been using a timer to set events however my concern (and what I’ve noticed happen) is that if the video fails to load quickly it collapses before ending.
From what I can gather the onEnded event function seems to only work with a simple Single video player as opposed to a ProGallery, which I had been using because it means you can play a video automatically, with sound unlike the single video player which is initially muted. Maybe there could be a way round this if by setting the gallery items via code instead of the Editor (help with this would be much appreciated additionally, otherwise I can work with the a single video player?

Anyway, the code I’ve tried is:

$w . onReady (()=> {
$w ( ‘#videoplayer1’ ).onEnded((=>{
$w ( ‘#videoplayer1’ ).hide()
});

Also as the hide function should be setting hidden property to ‘true’, I have tried both with the video player set as hidden from the start and not.

Apologies, I really recognise I’m probably approaching this from the amateur angle- just really want to get it to work. All the code I’ve written on timer works- I think its the introduction of an event function that has confused me.

Thanks soooo much in advance!

SOLVED:

$w . onReady ( async function () { console . log ( “Page is ready!” );
$w ( “#videoplayer1” ). onEnded (( event ) => {
$w ( “#videoplayer1” ). hide ( ‘fade’ ); $w ( “#videoPlayer1” ). collapse ();
});
});