D
D
Denis Bukreev2017-09-24 20:32:17
JavaScript
Denis Bukreev, 2017-09-24 20:32:17

Why don't native events fire on HTML5 video?

So it goes.
I set videos to load only metadata
8429554918d3488184fcd92b8f681500.png
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 () {});

There is a lot of code there in the end, but the bottom line is this: when window.onload, in a loop, I go through the blocks, find videos in them and assign this listener to them.
Why does everything work fine locally, but on a remote server - an ass?
How to properly track that the vidos is ready to play?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Bukreev, 2017-09-26
@denisbookreev

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);
});

It works in Chrome, Firefox, Opera, Safari, and IE is still slow-paced and poisons us, front-ends, life.

I
Ilya Gerasimov, 2017-09-24
@Omashu

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 question

Ask a Question

731 491 924 answers to any question