LoginSignup
3
1

More than 5 years have passed since last update.

メモ:type=fileで指定した音声ファイルの再生

Last updated at Posted at 2016-04-03
<input type="file" class="fileSelector">
document.querySelector('.fileSelector').addEventListener('change', function(event) {
    var file = event.target.files[0];
    if (!(file instanceof File)) {
        window.alert('Please upload file.');
    } else if (file.type.indexOf('audio') === -1) {
        window.alert('Please upload audio file.');
    } else {
      var src = window.URL.createObjectURL(file);
      var audio = new Audio( src );
      audio.play();
    }
}, false);
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1