I would like to have a html5 video player (basic tag), and call an external xml file in orderto load and play an ad before the main video.
This is currently working but I would like to have the cleanest and most multiplatform as possible:
function callAd() {
$.ajax({
type: "GET",
url: myexternal_file,
success: function(xml){
$(xml).find('MediaFile[type="video/mp4"]').each(function(){
var preroll = $(this)['context']['textContent'];
var video = document.getElementById("video1");
video.src = preroll;
video.load();
});
}
});
}
And as soon as the page loads, call the callAd function with my external xml. How should I proceed whenever the external url isn't acessible?
Thanks
EDIT: Sorry, the question isn't clear. I would like to know how to correctly parse a XML using javascript/jquery and how should I correctly listen for events coming from this function.