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...
code:
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();
}
If you want run sound in Ionic-2 / Angular-2 mobile application .
Follow Ionic 2 guide here
Install:
Usage:
source-1 : https://stackoverflow.com/a/43917441/6786941
You can create a new Audio element in the Javascript code ... not in HTML
for example :
I have tried @reba's answer but it didn't work on mobile browsers or may be there are Autoplay policies which are stopping to play the Audio files. So I have created and
audio
element and modify thesrc
dynamically like,In Angular,
Note: If you don't want to show the audio tag on page, then you can make it
[hidden]