I am currently working on incorporating an embedded YouTube video into my project. I want to replace the video with an image, and when the image is clicked, the video should start playing. I have successfully implemented this functionality:
<script type="text/javascript>
function start_video() {
var iframe = '<iframe title="YouTube video player" width="590" height="360" src="http://www.youtube.com/embed/nCgQDjiotG0?autoplay=1&rel=0&showinfo=0" frameborder="0" title="none" allowfullscreen></iframe>';
document.getElementById("video_player").innerHTML = iframe;
}
</script>
Here is the HTML code:
<div id="video_player"><img style="cursor: pointer;" onclick="start_video();" src="fake_image.jpg" alt="Play Video" /></div>
However, I am now facing a challenge in stopping the video playback by clicking on another div or element while simultaneously replacing the video with the original image.