LoginSignup
1
0

More than 3 years have passed since last update.

JavaScriptで音声ファイル確認&再生

Posted at
const soundPlay = function(url) {
    // オブジェクト生成
    var soundObj = new Audio();

    soundObj.onerror = function() {
        // エラー時の処理
        alert("再生できませんでした");
    }
    // URL設定
    soundObj.src = url;
    // 再生(できないときはエラーに行く)
    soundObj.play();
}

使い方

soundPlay("assets/sound/temp.mp3");
1
0
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
1
0