如何用Angular 2播放mp3? [英] How to play mp3 with Angular 2?
本文介绍了如何用Angular 2播放mp3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个小型离子/角度应用程序,我从远程服务器加载动态mp3文件并按下按钮播放它或者如果选中它我会自动播放。我尝试使用简单的< audio>< / audio>
,但我不确定这是否适合这种方式......
I want to write a small ionic/angular application where I load a dynamic mp3 file from a remote server and play it for pressing a button OR if it is checked I play it automaticly. I tried to use the simple <audio></audio>
but i am not sure if this is the good way for this...
代码:
html
<audio id="player">
<source id="source" src="http://remote.address.com/example.mp3"></source>
</audio>
javascript
play(){
var audio= document.getElementById('player');
audio.play();
}
推荐答案
你可以创建一个新的音频Javascript代码中的元素...不在HTML中
You can create a new Audio element in the Javascript code ... not in HTML
例如:
var audio = new Audio();
audio.src = "http://remote.address.com/example.mp3";
audio.load();
audio.play();
这篇关于如何用Angular 2播放mp3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文