Skip to content Skip to sidebar Skip to footer

Html 5 Audio Player And Android/ios

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 t

Solution 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 = newAudio();

  functionhandleFileSelect(evt) {
    var files = evt.target.files; // FileList objectvar reader = newFileReader();

      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        returnfunction(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);

Solution 2:

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

Post a Comment for "Html 5 Audio Player And Android/ios"