当前位置:网站首页>Videojs to canvas pause, play, switch video
Videojs to canvas pause, play, switch video
2022-07-26 13:41:00 【Tangce】

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
#video{
/*display: none;*/
}
</style>
</head>
<body>
<div class="play"> Play </div>
<div class="pause"> Pause </div>
<div class="playPause"> Play or pause video </div>
<div class="change-src"> Switch video </div>
<video id="video" loop width='300' autoplay webkit-playsinline="true" src='http://www.w3school.com.cn/example/html5/mov_bbb.mp4'></video>
<script src="https://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
/*
* video Video turned into canvas( Compatible to IE8+)
* Author: Zijor Created On: 2017-06-25
*
* Usage method :
* var videoCanvas = new VideoToCanvas(videoDom);
*
* Object properties :
* no .
*
* Object method :
* play Play the video
* pause Pause video
* playPause Play or pause video
* change(src) Switch video . Parameters src Video address switched for
*/
var VideoToCanvas = (function(window, document) {
function VideoToCanvas(videoElement) {
if(!videoElement) {return;}
var canvas = document.createElement('canvas');
canvas.width = videoElement.offsetWidth;
canvas.height = videoElement.offsetHeight;
ctx = canvas.getContext('2d');
var newVideo = videoElement.cloneNode(false);
var timer = null;
var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
var cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame;
function drawCanvas() {
ctx.drawImage(newVideo, 0, 0, canvas.width, canvas.height);
timer = requestAnimationFrame(drawCanvas);
}
function stopDrawing() {
cancelAnimationFrame(timer);
}
newVideo.addEventListener('play', function() {
drawCanvas();
},false);
newVideo.addEventListener('pause', stopDrawing, false);
newVideo.addEventListener('ended', stopDrawing, false);
videoElement.parentNode.replaceChild(canvas, video);
this.play = function() {
newVideo.play();
};
this.pause = function() {
newVideo.pause();
};
this.playPause = function() {
if(newVideo.paused) {
this.play();
} else {
this.pause();
}
};
this.change = function(src) {
if(!src) {return;}
newVideo.src = src;
};
this.drawFrame = drawCanvas;
}
return VideoToCanvas;
})(window, document);
var video = document.getElementById('video');
var videoCanvas = new VideoToCanvas(video);
$('.play').on('click',function(){
videoCanvas.play();
});
$('.pause').on('click',function(){
videoCanvas.pause();
})
$('.playPause').on('click',function(){
videoCanvas.playPause();
})
$('.change-src').on('click',function(){
videoCanvas.change('p4-video1.mp4');
})
</script>
</body>
</html>
边栏推荐
- Pytorch学习笔记(一)安装与常用函数的使用
- LeetCode 69. x 的平方根
- Parent class reference to child class (parent class reference points to child class object)
- Tdsql-c serverless: help start-ups achieve cost reduction and efficiency increase
- 冒泡排序的时间复杂度分析
- 时间复杂度和空间复杂度
- SuperMap iclient for leaflet loads Gauss Kruger projection three-dimensional zonation CGCS2000 geodetic coordinate system WMTs service
- 8 年产品经验,我总结了这些持续高效研发实践经验 · 研发篇
- .NET WebAPI 使用 GroupName 对 Controller 分组呈现 Swagger UI
- Leetcode 2119. number reversed twice
猜你喜欢

解决远程主机无法连接mysql数据库的问题

估值15亿美元的独角兽被爆裁员,又一赛道遇冷?

JSON数据传递参数&日期型参数传递

Implementation of SAP ABAP daemon

Oom caused by improper use of multithreading

LCL三相pwm整流器(逆变器)

WPS凭什么拒绝广告?

Multi objective optimization series 1 --- explanation of non dominated sorting function of NSGA2

Pytoch learning notes (III) use, modification, training (cpu/gpu) and verification of the model
![[shaders realize overlay to re cover cross dressing effect _shader effect Chapter 9]](/img/f3/48ca9e1e8889afc0993084d6416575.png)
[shaders realize overlay to re cover cross dressing effect _shader effect Chapter 9]
随机推荐
Algorithm -- continuous sequence (kotlin)
我们被一个 kong 的性能 bug 折腾了一个通宵
Analysis on the current situation and optimization strategy of customer experience management in banking industry
MVVM architecture encapsulation of kotlin series (kotlin+mvvm)
Research status and pain points of deep learning 3D human posture estimation at home and abroad
Sword finger offer (x): rectangular coverage
飞盘,2022年“黑红”顶流
Time complexity analysis of bubble sorting
Parent class reference to child class (parent class reference points to child class object)
Can I take your subdomain? Exploring Same-Site Attacks in the Modern Web
银行业客户体验管理现状与优化策略分析
如何构建以客户为中心的产品蓝图:来自首席技术官的建议
[oauth2] VIII. Configuration logic of oauth2 login -oauth2loginconfigurer and oauth2clientconfigurer
Pytorch学习笔记(三)模型的使用、修改、训练(CPU/GPU)及验证
Sword finger offer (IX): abnormal jumping steps
Win11+vs2019 configuration yolox
Leetcode 2119. number reversed twice
Abstract factory and its improvement examples
421. 数组中两个数的最大异或值
Photoshop(CC2020)未完