当前位置:网站首页>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>
边栏推荐
- Three "factions" in the metauniverse
- Usage Summary of scriptable object in unity
- Damn, window in ie open()
- Promql demo service
- What about data leakage? " Watson k'7 moves to eliminate security threats
- Solve the problem of "no input file specified" when ThinkPHP starts
- 2022-07-05: given an array, you want to query the maximum value in any range at any time. If it is only established according to the initial array and has not been modified in the future, the RMQ meth
- Kubernetes Administrator certification (CKA) exam notes (IV)
- 鏈錶之雙指針(快慢指針,先後指針,首尾指針)
- Shelved in TortoiseSVN- Shelve in TortoiseSVN?
猜你喜欢
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
Usage Summary of scriptable object in unity
TCC of distributed solutions
如何快速体验OneOS
2022软件测试工程师涨薪攻略,3年如何达到30K
How can Bluetooth in notebook computer be used to connect headphones
【无标题】
Leetcode simple question ring and rod
MySQL actual combat 45 lecture learning (I)
90后测试员:“入职阿里,这一次,我决定不在跳槽了”
随机推荐
Lesson 1: serpentine matrix
The introduction to go language is very simple: String
Common interview questions of JVM manufacturers
How to develop and introduce applet plug-ins
119. Pascal‘s Triangle II. Sol
Performance testing of software testing
Shelved in TortoiseSVN- Shelve in TortoiseSVN?
Damn, window in ie open()
航海日答题小程序之航海知识竞赛初赛
[groovy] groovy dynamic language features (automatic type inference of function arguments in groovy | precautions for function dynamic parameters)
Win11运行cmd提示“请求的操作需要提升”的解决方法
Alternating merging strings of leetcode simple questions
[error record] groovy function parameter dynamic type error (guess: groovy.lang.missingmethodexception: no signature of method)
我把开源项目alinesno-cloud-service关闭了
How can easycvr cluster deployment solve the massive video access and concurrency requirements in the project?
Postman核心功能解析-参数化和测试报告
Platform bus
Unique occurrence times of leetcode simple questions
从 1.5 开始搭建一个微服务框架——日志追踪 traceId
Assign the output of a command to a variable [repeat] - assigning the output of a command to a variable [duplicate]