单击按钮时播放声音(角度)

时间:2019-03-10 00:33:02

标签: angular audio click

点击链接后,我正在尝试播放声音

这就是我所拥有的,但是,当我将其添加到文件中时,它无法正常工作,并且似乎大大降低了浏览器的速度

HTML:

<a routerLinkActive="active" routerLink="/tomato2" class="tomato" (click)="playAudio()">
  <img class="tomato_1" src="https://freepngimage.com/content/uploads/images/tomato-7866.png" />
</a>

TS:

import { Component } from '@angular/core';
import { Http } from '@angular/http';

@Component({
  selector: 'home',
  templateUrl: './catalog.component.html'
})

export class CatalogViewComponent {
    playAudio(){
      let audio = new Audio();
      audio.src = "http://www.schillmania.com/projects/soundmanager2/demo/mpc/audio/CHINA_1.mp3";
      audio.load();
      audio.play();
      this.playAudio();
    }
}

0 个答案:

没有答案