Let users share their videos live.
Since v4.16 the text-input feature is non-existent, therefore this example is not practically doable. However, we are not removing this page as the example could still be useful to curious users.
let image = parcel.getFeatureById('video_object')
let input = parcel.getFeatureById('text_input')
function validateYouTubeUrl(url) {
if (url != undefined || url != '') {
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|\?v=)([^#\&\?]*).*/;
var match = url.match(regExp);
if (match && match[2].length == 11) {
return true;
} else {
alert('not valid');
return false;
}
}
}
feature.on('click',e=>{
const newurl = input.text
if(validateYouTubeUrl(newurl)){
image.set({url:newurl})
}
})
Go to your parcel settings and check the grid box.
What it does
Once the youtube url entered and the button pressed, the function validateYouTubeUrl
is called to check the validity of the URL. If it's a good youtube URL then the video is changed and you can start playing it.