angular - 如何以角度形式获取所选文件的音频或视频持续时间
问题描述
以我的角度形式,我通过以下方式获取我的视频或音频文件
(change)="fileSelected($event)
.html 格式和
attachedFile = <File>event.target.files[0]
在具有名称、类型和大小的 .ts 文件中。如何获得音频/视频持续时间?
解决方案
您可以根据所选文件类型动态创建音频或视频元素,然后获取其他信息。这是代码...
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);
}
推荐阅读
- window - 如何在 dolphindb 中将 1 分钟的数据聚合为 30 分钟或 1 小时的平均数据
- flutter - docker image 中的“flutter channel stable”失败:将页面发布到 gitlab 时出现 cirrusci
- https - JWKS 端点是否需要 https / TLS?
- git - 将单个代码库部署到多个客户端
- python - Odoo 14 条码模块使用 get_all_products_by_barcode 方法性能不佳
- eclipse - Cyclone DDS Package 配置文件丢失
- android - 在片段之间重用 ViewModel
- ios - 如何在 Swift 的模态表前呈现 UIAlertController
- django - 新表中的 Django ForeignKey 默认值
- r - x 下标在 mutate 中越界