Get the App
SLTechnology News&Howtos  ›  Development  › 

How to get the duration of video in vue project

Shulou Source: shulou.com Published: 2022-05-31 23:59:14 09月28日 Update

This article mainly explains "how to get the video duration in the vue project". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to obtain the video duration in the vue project".

Vue acquires video duration

The input parameter is the video file object

The code for js is as follows:

GetVideoDuration (file) {var url = URL.createObjectURL (file); var audioElement = new Audio (url); var self = this; var result; audioElement.addEventListener ("loadedmetadata", function () {/ / the video duration value will not be obtained until the execution of this anonymous function completes to generate result = audioElement.duration; / / get the duration in seconds, decimal, 182.36 self.ruleForm.videoDuration = parseInt (result); / / convert to int value}) } vue-video-player get playback time npm install vue-video-player-S global reference import VideoPlayer from 'vue-video-player'import' vue-video-player/src/custom-theme.css'import 'video.js/dist/video-js.css'Vue.use (VideoPlayer) local reference import {videoPlayer} from' vue-video-player'import 'video.js/dist/video-js.css' export default {components: {videoPlayer} } html methods get playback time this.$nextTick (() = > {setTimeout () = > {let du = document.getElementById ("vjs_video_3_html5_api") / / get video var hour = parseInt ((du.duration) / 3600) under the component Var minute = parseInt ((du.duration% 3600) / 60); var second = parseInt (du.duration% 60) Let result =''if (hour > 0) {result = this.formatTimeStr (hour) +':'+ this.formatTimeStr (minute) +':'+ this.formatTimeStr (second)} else {result = this.formatTimeStr (minute) +':'+ this.formatTimeStr (second)} Return result / / transformed components Second}, 200)}) formatTimeStr (val) {if (val > 9) {return val} else {return'0' + val}}, thank you for reading. This is the content of "how to get the video duration in the vue project". After the study of this article I believe you have a deeper understanding of how to obtain the duration of the video in the vue project, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Duration video project learning content time code global function parameter object decimal that is local idea situation component file article more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux macOS Huawei Apple Shulou Technology