javascript - 如何确定音频文件扩展名可能是什么(Chrome,Android)?

标签 javascript android google-chrome audio format

在Android上的Chrome(最新版本,两者)中从网页读取音频文件时,碰巧<input type="file" accept="audio/*">中的文件名缺少文件扩展名。

我需要确定它是否真的是音频文件,以及它可能具有的扩展名。

有没有简单的方法可以做到这一点?

编辑:如果我用例如Google的文件查找,则文件具有正确的文件扩展名。但是我目前正在尝试解决Android上的Chrome浏览器中的一些错误。 (如果时间不长,我将有时间提交另一个错误报告。)

最佳答案

您可以从input的文件列表中检查文件的类型

let fileinput = document.querySelector('input[type="file"]');
let button = document.querySelector('button');

button.addEventListener('click', function(){
  if(fileinput.files !== null){
    if(/audio\/*/.test(fileinput.files[0]['type']) === true){
    let getExtension = fileinput.files[0]['name'].split('.');
      alert(`This is an audio file and the extension for this file is ${getExtension[getExtension.length - 1]}`)
    }else{
    alert('Nope')
}
  }else{
  alert('Pick a file')
  }

})
<input type="file" multiple="false" accept="audio/*">

<button>Is this a Audio File ?</button>

关于javascript - 如何确定音频文件扩展名可能是什么(Chrome,Android)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61480472/

相关文章:

javascript - 我怎样才能修复动画速度?

javascript - 如何检查 JSON Array 对象是否包含 Key

javascript - 如何在重新排序 DOM 后重新绘制和重新组织 Isotope 容器中的元素?

android - 为什么 popBackStack() 方法没有删除我的 fragment ?

android - 谷歌地图代码中的 BadParcelableException

javascript - Websocket连接错误: returns 101,但不升级

android - 检测 GridView 滚动速度 - Android

javascript - 检查 elem 是否是鼠标悬停在 Google 结果页面上的超链接

c - 在 C/Go 中从 Google Chrome 获取标签页信息

javascript - Chrome 的 DateParsing 问题