当前位置:网站首页>H5c3 advanced - player
H5c3 advanced - player
2022-07-05 22:30:00 【Felikslugger.】
player
Common methods :load() load 、play() Play 、pause() Pause
jQuery There is no way to play the video control 、 To operate video playback , Must use native js Method ——dom Elements
Common properties :
- currentTime Current progress of video playback
- duration: Total time of video 100000/60
- paused: Status of video playback
Common events :
- oncanplay: Event when the user can start playing video / Audio (audio/video) Trigger when
- ontimeupdate: Report the current playback progress through this event
- onended: Triggered at the end of playback —— Reset
Practice
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../css/font-awesome-4.7.0/css/font-awesome.css">
<style> video {
height: 100%; margin: 0 auto; display: none; } .elapse {
width: 0%; height: 20px; background-color: black; } .bar {
width: 100%; height: 100%; border-radius: 3px; cursor: pointer; position: absolute; left: 0; top: 0; opacity: 0; z-index: 999; } </style>
</head>
<body>
<h3 class="playerTitle"> Video player </h3>
<div class="player">
Change here to your own video file
<video src="../html/ Lie without making a draft .mp4"></video>
<div class="controls">
<a href="javascript:;" class="switch fa fa-play"></a>
<a href="javascript:;" class="expand fa fa-pause"></a>
<div class="progress">
<div class="bar"></div>
<div class="loaded"></div>
<div class="elapse"></div>
</div>
<div class="time">
<span class="currentTime">00:00:00</span>
\
<span class="totalTime">00:00:00</span>
</div>
</div>
</div>
<script src="../js/jquery.js"></script>
<script> // adopt jQuery To achieve the function $(function(){
//1. Get the player var video = $("video")[0]; //2. Realize playback and pause $(".switch").click(function(){
// Switch between play and pause if(video.paused){
video.play(); // Remove pause style , Add playback style }else{
video.pause(); // Remove playback style , Add pause style } $(this).toggleClass("fa-play fa-pause"); }); //3. Realize full screen operation $(".expand").click(function(){
// Full screen > Different browsers , Different prefixes if(video.requestFullscreen){
video.requestFullscreen(); } else if(video.webkitRequestFullScreen){
video.webkitRequestFullScreen(); } else if(video.mozRequestFullScreen){
video.mozRequestFullScreen(); } else if(video.msRequestFullScreen){
video.msRequestFullScreen } }); //4. Realize the playback business logic : When the video asking price can be played, the following event will be triggered video.oncanplay=function(){
//1. Set the video file to display video.style.display="block"; //2. Get the total time of current video file , Calculate the hours, minutes and seconds var total = video.duration; //3. Counting time, minutes and seconds // var hour = Math.floor(total/3600); // // repair 0 operation // hour=hour<10?"0"+hour:hour; // var minute = Math.floor(total%3600/60); // minute=minute<10?"0"+minute:minute; // var second = Math.floor(total%60); // second=second<10?"0"+second:second; // Display the calculation results in the designated dom In the elements var result = getResult(total) $(".totalTime").html(result); } // Get the total time and calculate the hours, minutes and seconds function getResult(time){
var hour = Math.floor(time/3600); // repair 0 operation hour=hour<10?"0"+hour:hour; var minute = Math.floor(time%3600/60); minute=minute<10?"0"+minute:minute; var second = Math.floor(time%60); second=second<10?"0"+second:second; // Return results return hour+":"+minute+":"+second; } //5. Realize the business logic in the playback process , When the video is played, it will trigger ontimeupdate event video.ontimeupdate=function(){
//1. Get the current playback event var current = video.currentTime; var result = getResult(current); $(".currentTime").html(result); // Set the current playback progress bar style var percent = current/video.duration*100+"%"; $(".elapse").css("width",percent); } //6. Realize the jump broadcasting of video $(".bar").click(function(e){
//1. Get the current mouse relative to the parent element left value -- Offset value var offset = e.offsetX; //2. Calculate the ratio of the offset value to the total width of the total parent element var percent = offset/$(this).width(); //3. Calculate the video progress value corresponding to this position var current = percent*video.duration; // Set the current video currenTime video.currentTime = current; }) //7. After playing , Reset the state of the player video.onended=function(){
video.currentTime=0; $(".switch").removeClass("fa-pause").addClass("fa-play"); } }); </script>
</body>
</html>
边栏推荐
- boundary IoU 的计算方式
- Performance testing of software testing
- Analysis of the problem that the cookie value in PHP contains a plus sign (+) and becomes a space
- What changes has Web3 brought to the Internet?
- Qtquick3d real time reflection
- A trip to Suzhou during the Dragon Boat Festival holiday
- 数据泄露怎么办?'华生·K'7招消灭安全威胁
- 2022软件测试工程师涨薪攻略,3年如何达到30K
- 70. Climbing Stairs. Sol
- 科技云报道:算力网络,还需跨越几道坎?
猜你喜欢

Interview questions for famous enterprises: Coins represent a given value

Opencv judgment points are inside and outside the polygon

EasyCVR集群部署如何解决项目中的海量视频接入与大并发需求?

Wonderful review of the digital Expo | highlight scientific research strength, and Zhongchuang computing power won the digital influence enterprise award

Postman core function analysis - parameterization and test report

Technology cloud report won the special contribution award for the 10th anniversary of 2013-2022 of the "cloud Ding Award" of the global cloud computing conference

Stored procedures and stored functions

Post-90s tester: "after joining Ali, this time, I decided not to change jobs."

My experience and summary of the new Zhongtai model
![[error record] groovy function parameter dynamic type error (guess: groovy.lang.missingmethodexception: no signature of method)](/img/3e/34b45cd14f0302bb381efd244bc68f.jpg)
[error record] groovy function parameter dynamic type error (guess: groovy.lang.missingmethodexception: no signature of method)
随机推荐
分布式解决方案之TCC
Wonderful review of the digital Expo | highlight scientific research strength, and Zhongchuang computing power won the digital influence enterprise award
Metaverse Ape上线倒计时,推荐活动火爆进行
科技云报道:算力网络,还需跨越几道坎?
A substring with a length of three and different characters in the leetcode simple question
What if the files on the USB flash disk cannot be deleted? Win11 unable to delete U disk file solution tutorial
Cobaltstrike builds an intranet tunnel
Leetcode simple question: find the nearest point with the same X or Y coordinate
What changes has Web3 brought to the Internet?
2022软件测试工程师涨薪攻略,3年如何达到30K
Binary tree (III) -- heap sort optimization, top k problem
Go语言学习教程(十五)
QT creator 7 beta release
U盘的文件无法删除文件怎么办?Win11无法删除U盘文件解决教程
Understand the basic concept of datastore in Android kotlin and why SharedPreferences should be stopped in Android
Go language learning tutorial (XV)
MySQL actual combat 45 lecture learning (I)
All expansion and collapse of a-tree
Business introduction of Zhengda international futures company
Win11 runs CMD to prompt the solution of "the requested operation needs to be promoted"