Of course you have to put it into the onReady-section…like…
$w.onReady(function() {console.log("Page is ready!");
$w("#myVideoPlayer").onEnded((event) => {
let targetID = event.target.id; // "myVideoPlayer"
console.log("Playtime of "+targetID+"has been ended!")
});
});