stamat / youtube-background

ESM / jQuery plugin for creating video backgrounds from YouTube, Vimeo or video file links.
https://stamat.github.io/youtube-background/
MIT License
173 stars 54 forks source link

Update Video URL after Initialization #52

Closed Tarek-Adra closed 10 months ago

Tarek-Adra commented 1 year ago

there's any option to update the video URL, I tried to change data-vbg attribute and call jQuery('[data-vbg]').youtube_background() without any luck

stamat commented 10 months ago

@Tarek-Adra hey man, thanks for reaching out and sorry for a year long wait for a reply. Hopefuly you've found the solution by yourself.

What you can do is search for the iframe of the player, or the video element within the element wiht data-vbg and change it's source attribute.

This is a great idea to have the reinitializer function. I'll leave this issue open so I can add it.

stamat commented 10 months ago

@Tarek-Adra hey man! I've made the update as of v1.1.0 and added the functonality to the code so you can change the URL on the fly, if the URL is from the same video provider as the previously initialised URL.

To do so you'll have to get the data-vbg-uid attribute value and then get the instance of your video background in a global variable if you are using jQuery window.VIDEO_BACKGROUNDS.index[uid].serSource(URL). This will programatically change the source.

If you want to use a vimeo link and previously you used youtube, then you'll need to destroy the instance window.VIDEO_BACKGROUNDS.index[uid].destroy() first and then change the 'data-vbg' atrtibute and reinitialize it window.VIDEO_BACKGROUNDS.add($('.YOUR-ELEMENT')[0]).

You can see how these functions were implemented in the demo.

In the v1.1.1 I'll add the setStart and setEnd time and video-background-destroyed event, since I forgot about it... And I'll try to complete the documentation!

Cheers! ☺️