How to set the playback time in video
This article is about how to set the playback time in video. The editor thinks it is very practical, so I hope you can get something after reading this article. Let's take a look at it with the editor.
1. The shareVideoLink below the common attributes of video tag is the video connection address.
2. Obtain the video playback time. Initialize this method in mounted. When the video starts to play, you can get the real-time time of video playback.
/ * obtain video playback duration * / getVideoTime () {if (document.getElementById ('videoPlayer')) {let videoPlayer = document.getElementById (' videoPlayer'); videoPlayer.addEventListener ('timeupdate', function () {console.log (`current time point is ${videoPlayer.currentTime}, video length is ${videoPlayer.duration}`);}, false)}}
3. Set the video to start playing from a specific point in time. The parameter num in the following method indicates when to start playing the video. For example, click a button to perform the following method:
For example, if 2460198 is returned as milliseconds at the backend, you only need to convert it to seconds. Video will automatically calculate from seconds and assign a value to video label seconds. 2460198 is 246.0198 seconds (s). When we call the following method, we can write this:
This.playBySeconds (2460198amp1000) or this.playBySeconds (2460.198), because 2460.198 seconds is 41.0033001 minutes, so the video will automatically start playing from 41.0033001 minutes, so OK
/ / set the playback point and resume playBySeconds (num) {if (num & & document.getElementById ('videoPlayer')) {let myVideo = document.getElementById (' videoPlayer'); myVideo.play (); myVideo.currentTime = num;}}
Summary of other attributes of video:
Pause to turn on sound