Help us understand the problem. What is going on with this article?

Angularアプリで効果音を出す

More than 1 year has passed since last update.

Webアプリで独自の効果音を出したい話。
HTML内にタグを追記することなく、Typescript側だけで対応可。

dialog.component.ts
export class DialogComponent implements OnInit {

//コンポーネントのメンバとしてHTMLAudioElementを作成
    private SoundWarning: HTMLAudioElement = new Audio('sound/warning1.mp3');

//コンポーネントの呼出段階で音源ファイルを読み込んでおく
    ngOnInit() {
        this.SoundWarning.load();
    }

//メソッドが実行された時に音を鳴らす
    openDialog(DialogMessage){
        ....
        this.SoundWarning.play();
        ....
    }
}

効果音ならす部分をサービス化するとか、もう少し凝ったこと出来るけど次回に回して、とりあえず忘備録。

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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした