Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 8 - When src changes programatically HTML video element does not change the video

I have a MP4 video playing in the background in my web app. However when I update the bindings and change the video source the video stays the same

<video autoplay loop>
    <source [src]="videoSrc" type="video/mp4">
</video>
{{videoSrc}}

My TS code:

this.videoSrc = "video.mp4";
...
interval(10000).subscribe(x => {
  this.videoSrc = "otherVideo.mp4";
});

Why aren't the bindings being updated?

like image 788
Jebathon Avatar asked Feb 20 '26 09:02

Jebathon


1 Answers

You should bind the src property in the video tag instead of binding the source tag.

<video autoplay loop muted playsinline="true" webkit-playsinline="true" [src]="videoSrc" type="video/mp4">
</video>

Check this stakblitz https://stackblitz.com/edit/angular-ivy-hlqbza

like image 158
Roides Javier Cruz Lara Avatar answered Feb 23 '26 00:02

Roides Javier Cruz Lara



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!