【问题标题】:HTML 5 Audio Player and Android/iOSHTML 5 音频播放器和 Android/iOS
【发布时间】:2011-12-06 19:25:42
【问题描述】:

我的问题是:HTML5 音频播放器可以播放设备中的文件吗?因此,如果用户从网站下载音频文件并将其保存在设备上,播放器能否以离线方式(无互联网)读取和播放该文件?播放器位于 WebApp 中。

谢谢 新人

【问题讨论】:

  • 没有人有想法吗?

标签: android ios html5-audio web-applications


【解决方案1】:

Android 和 iPhone 有基于 WebKit 的浏览器,应该支持File API

您可以要求用户打开文件,并使用 File API 将其读取为 DataURL,如上所述。

<input type="file" id="file" />

<script>
  player = new Audio();

  function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    var reader = new FileReader();

      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
           player.src = e.target.result;
           player.play()            
        };
      })(f);

      // Read in the image file as a data URL.
      reader.readAsDataURL(f);
    }
  }
</script>

document.getElementById('file').addEventListener('change', handleFileSelect, false);

【讨论】:

    【解决方案2】:

    iOS 不支持“文件”输入。另外,iOS 无法将媒体文件作为数据 URL 加载,只能播放真实的 URL 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-02
      相关资源
      最近更新 更多