利用事件对视频流进行控制
video.addEventListener('loadstart', () => {
console.log('1.loadstart');
console.log('duration', video.duration);
})
video.addEventListener('durationchange', () => {
console.log('2.durationchange');
console.log('duration', video.duration);
})
video.addEventListener('loadedmetadata', () => {
console.log('3.loadedmetadata');
console.log('duration', video.duration);
})
video.addEventListener('loadeddata', () => {
console.log('4.loadeddata');
})
video.addEventListener('progress', () => {
console.log('progress');
})
video.addEventListener('canplay', () => {
console.log('5.canplay');
})
video.addEventListener('play', () => {
console.log('play');
})
video.addEventListener('playing', () => {
console.log('playing');
})
video.addEventListener('pause', () => {
console.log('pause');
})
video.addEventListener('seeking', () => {
console.log('seeking');
})
video.addEventListener('seeked', () => {
console.log('seeked');
})
video.addEventListener('ended', () => {
console.log('ended');
})
video.addEventListener('error', () => {
console.log('error');
})
video.addEventListener('timeupdate', () => {
let current = video.currentTime;
console.log('timeupdate', current);
})
快进快退
function adjustVideo(val) {
myVideo.currentTime += val
}
pre.addEventListener('click', () => {
adjustVideo(-5);
})
next.addEventListener('click', () => {
adjustVideo(5);
})
音量增减 - 开始是0.5;如何越界检测
function adjustVol(val) {
if(myVideo.volume < 1){
myVideo.volume += val
}
}
va.addEventListener('click', () => {
if(myVideo.volume < 1){
adjustVol(0.1);
}
})
vs.addEventListener('click', () => {
if(myVideo.volume > 0){
adjustVol(-0.1);
}
})