Answer the question
In order to leave comments, you need to log in
Why don't native events fire on HTML5 video?
So it goes.
I set videos to load only metadata
Using the js API, I try different methods to determine that video data has loaded:
// этот локально отлично срабатывает, на удаленном сервере уже выборочно (обычно 2 из 5 видоса, иногда 0)
it.player.addEventListener('loadeddata', function () {});
// аналогично loadeddata, но сильно хуже
it.player.addEventListener('loadedmetadata', function () {});
// аналогично, но срабатывает многократно
it.player.addEventListener('canplaythrough', function () {});
Answer the question
In order to leave comments, you need to log in
There is a solution!
it.player = it.$player.find('video')[0];
let playPromise = it.player.play(); // оказывается, что .play() работает как обещание (Promise())
// когда видео готово к воспроизведению
playPromise.then(_ => {
it.player.pause();
// все, можно делать с видео что душе угодно
}).catch(error => {
console.log('не загружается: ' + error);
});
Most likely because scripts are loaded faster locally and events are normally hung, everything is a little worse with loading and the event is processed before we hang an event on it, I see no other explanation. The decision if it loaded to do what they wanted, otherwise we hang up the event and listen
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question