I have a component which play an mp3 file, and it gets the played file name from its parent. Here is the code:
export class PlayComponent implements OnChanges {
@Input() fileToPlay:string;
ngOnChanges(arg){
console.log(arg.fileToPlay);
}
}
and the html is:
<div *ngIf="fileToPlay!=''">
<audio controls autoplay class="playa" di="audio">
<source [src]="fileToPlay" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</div>
It works fine for first play. The value of fileToPlay
may change and i want to play the new file on real time, but it always play the first file name.
How can i fix it?
Audio pause() Method The pause() method halts (pauses) the currently playing audio. Tip: This method is often used together with the play() method.
HTML Audio - Methods, Properties, and EventsThis allows you to load, play, and pause audios, as well as set duration and volume. There are also DOM events that can notify you when an audio begins to play, is paused, etc. For a full DOM reference, go to our HTML Audio/Video DOM Reference.
To embed audio in HTML, we use the <audio> tag. Before HTML5, audio cannot be added to web pages in the Internet Explorer era. To play audio, we used web plugins like Flash.
I know this is old but I had the same problem and the only thing that worked for me was putting the src in the audio not the source:
<audio controls src={{filetoplay}}></audio>
couldn't find anything on google so figured it out myself, hope it helps someone
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With