How can someone embed a YouTube video into a website in a way that will automatically redirect to a locally stored copy of the video if the video becomes unavailable from YouTube?
For example, I would like to do something like this:
How can someone embed a YouTube video into a website in a way that will automatically redirect to a locally stored copy of the video if the video becomes unavailable from YouTube?
For example, I would like to do something like this:
Using the answer posted here, by using jQuery, you can first check if YouTube is reachable by the client and then if it is not reachable, load the video from an alternative source. You can use the following piece of code:
$.ajax({url: "https://www.youtube.com",
type: "HEAD",
timeout:1000,
statusCode: {
200: function (response) { //YouTube is reachable.
$("#iframeid").attr("src", "https://www.youtube.com/watch?v=videoid");
},
400: function (response) { //YouTube is unreachable.
$("#iframeid").attr("src", "https://www.example.com/videos/video.mp4");
}
}
});