我以有角度的形式获取视频或音频文件
(change)="fileSelected($event)
.html格式和
attachedFile = <File>event.target.files[0]
具有名称,类型和大小的.ts文件中的。如何获得音频/视频持续时间?
答案 0 :(得分:1)
您可以根据所选文件类型动态创建音频或视频元素,然后获取其他信息。这是代码...
fileSelected($event) {
attachedFile = <File>event.target.files[0]
let duration:any;
//here you can check the file type for attachedFile either video or audio
var video = document.createElement('video');
video.preload = 'metadata';
video.onloadedmetadata = function() {
window.URL.revokeObjectURL(video.src);
duration = video.duration; // here you could get the duration
}
video.src = URL.createObjectURL(attachedFile);
}
答案 1 :(得分:0)
尝试以下代码,
attachedFile.addEventListener('timeupdate', (event) => {
// Your code.
});