当前位置:网站首页>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>
边栏推荐
- Leetcode 2119. number reversed twice
- 8 年产品经验,我总结了这些持续高效研发实践经验 · 研发篇
- 从标注好的xml文件中截取坐标点(人脸框四个点坐标)人脸图像并保存在指定文件夹
- B+ tree (4) joint index -- MySQL from entry to proficiency (16)
- 周伟:寻找非共识性投资机会,陪伴延迟满足的创始团队
- Probability theory and mathematical statistics
- The use of asynchronous thread pool in development
- 异步线程池在开发中的使用
- Propagation of transactions
- 我们被一个 kong 的性能 bug 折腾了一个通宵
猜你喜欢

Tianjin emergency response Bureau and central enterprises in Tianjin signed an agreement to deepen the construction of emergency linkage mechanism

Win11+VS2019配置YOLOX

《Kotlin系列》之MVVM架构封装(kotlin+mvvm)

One stroke problem (Chinese postman problem)

panic: Error 1045: Access denied for user ‘root‘@‘117.61.242.215‘ (using password: YES)

重押海外:阿里、京东、顺丰再拼“内力”

ROS2学习(1)ROS2简述

Photoshop(CC2020)未完
![[oauth2] VII. Wechat oauth2 authorized login](/img/1a/3f2b9fc57759a1fa3fda1451492e5c.png)
[oauth2] VII. Wechat oauth2 authorized login
![[flower carving hands-on] interesting and fun music visualization series small project (13) -- organic rod column lamp](/img/d4/7b9c7c99d46661e1be2963a342dd18.jpg)
[flower carving hands-on] interesting and fun music visualization series small project (13) -- organic rod column lamp
随机推荐
JSON数据传递参数&日期型参数传递
图扑 3D 可视化国风设计 | 科技与文化碰撞炫酷”火花“
The last time I heard about eBay, or the last time
[collection of topics that C language learners must know 1] consolidate the foundation and steadily improve
Brief introduction of reflection mechanism
Codeforces Round #810 (Div. 2)【比赛记录】
Dimension disaster dimension disaster suspense
Codeforces round 810 (Div. 2) [competition record]
Huawei computer test ~ offset realizes string encryption
Unicode file parsing methods and existing problems
[flower carving hands-on] interesting and fun music visualization series small project (13) -- organic rod column lamp
Leetcode 217. there are duplicate elements
Time complexity analysis of bubble sorting
How to realize the reality of temporary graphic elements
421. Maximum XOR value of two numbers in the array
时间复杂度和空间复杂度
【着色器实现Overlay重新覆盖变装效果_Shader效果第九篇】
算法--连续数列(Kotlin)
flutter多渠道打包运行
Familiarize you with the "phone book" of cloud network: DNS