我正在尝试显示视频时长,我从Kaiido给出的答案Get video duration when input a video file中获得了参考。这是代码:
<script>
var myVideos = [];
window.URL = window.URL || window.webkitURL;
document.getElementById('fileUp').onchange = setFileInfo;
function setFileInfo() {
var files = this.files;
myVideos.push(files[0]);
var video = document.createElement('video');
video.preload = 'metadata';
video.onloadedmetadata = function() {
window.URL.revokeObjectURL(video.src);
var duration = video.duration;
var duration = (new Date).clearTime()
.addSeconds(duration)
.toString('H:mm:ss');
myVideos[myVideos.length - 1].duration = duration;
updateInfos();
}
video.src = URL.createObjectURL(files[0]);;
}
function updateInfos() {
var infos = document.getElementById('infos');
infos.textContent = "";
for (var i = 0; i < myVideos.length; i++) {
infos.textContent += myVideos[i].duration + '\n';
}
}
</script>
但是,我想将值插入标签而不是标签中。
我尝试使用输入标签代替前置标签,但这没有用。