Play sound in Angular 4

前端 未结 7 1546
暗喜
暗喜 2020-12-12 22:17

I\'m working on an Electron app with Angular 4. I want to play sound on some specific action. Is there any module or code for that? It can be in the angular 4 o

7条回答
  •  孤城傲影
    2020-12-12 22:51

    updated: I had the same problem and used ViewChild reference with ElementRef to solve this.

    app.component.ts

    @ViewChild('audioOption') audioPlayerRef: ElementRef;
    
    onAudioPlay(){
      this.audioPlayerRef.nativeElement.play();
    }
    

    app.component.html

       
    

提交回复
热议问题