Test
<br><br> <script src="https://www.youtube.com/iframe_api"></script></head><body> <?php $youtubeVideoUrl = "
https://www.youtube.com/watch?v=oBPfl2nJUfk"; $youtubeVideoId = getYoutubeVideoId($youtubeVideoUrl);
// Function to extract YouTube video ID from URL
function getYoutubeVideoId($url) {
parse_str(parse_url($url, PHP_URL_QUERY), $params);
return isset($params['v']) ? $params['v'] : null;
}
?>
<div id="player"></div> <script> // YouTube iframe API callback function
function onYouTubeIframeAPIReady() {
var player = new YT.Player('player', {
height: '360',
width: '640',
videoId: '<?php echo $youtubeVideoId; ?>',
events: {
'onReady': onPlayerReady,
// 'onStateChange': onPlayerStateChange // Uncomment and customize if you need to handle state changes
}
});
}
// Event handler when the YouTube player is ready
function onPlayerReady(event) {
// Autoplay the video
event.target.playVideo();
}
</script></body>