Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.
const soundPlay = function(url) {
    // オブジェクト生成
    var soundObj = new Audio();

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

使い方

soundPlay("assets/sound/temp.mp3");
naozo-se
少し時代に取り残されつつある、WEBなエンジニアです。 完全に自分のメモで書き残しています。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away