neko/src/component/internal/video.ts

32 lines
888 B
TypeScript
Raw Normal View History

2020-11-09 09:19:46 +13:00
import Vue from 'vue'
2020-11-29 09:47:16 +13:00
import { Video } from '../types/state'
2020-11-09 09:19:46 +13:00
export function register(el: HTMLVideoElement, state: Video) {
el.addEventListener('canplaythrough', () => {
Vue.set(state, 'playable', true)
})
el.addEventListener('playing', () => {
Vue.set(state, 'playing', true)
})
el.addEventListener('pause', () => {
Vue.set(state, 'playing', false)
})
el.addEventListener('emptied', () => {
Vue.set(state, 'playable', false)
Vue.set(state, 'playing', false)
})
el.addEventListener('error', () => {
Vue.set(state, 'playable', false)
Vue.set(state, 'playing', false)
})
el.addEventListener('volumechange', (value) => {
2020-11-30 00:06:01 +13:00
Vue.set(state, 'muted', el.muted)
2020-11-09 10:02:00 +13:00
Vue.set(state, 'volume', el.volume)
2020-11-09 09:19:46 +13:00
})
2020-11-09 10:02:00 +13:00
// Initial state
2020-11-30 00:06:01 +13:00
Vue.set(state, 'muted', el.muted)
2020-11-09 10:02:00 +13:00
Vue.set(state, 'volume', el.volume)
Vue.set(state, 'playing', !el.paused)
2020-11-09 09:19:46 +13:00
}