HTML 5 Audio Player and Android/iOS

十年热恋 提交于 2019-12-12 06:35:58

问题


my question is: Can the HTML5 Audio Player play files from the device. So if the user downloads a audio file from a website and save it on the device can the player read and play this file in offline modus(without internet)? The player is in an WebApp.

thanx newone


回答1:


Android and iPhone has WebKit based browser and should support File API

You can ask user to open file, and read it as DataURL using File API, described above.

<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:


"file" input is not supported in iOS. Also, iOS cannot load media files as data URL, only real URL files can be played.



来源:https://stackoverflow.com/questions/7751987/html-5-audio-player-and-android-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!