Rishabh Rishabh - 5 months ago 8
jQuery Question

html5 video tag setting src programmatically

I need to run a video file for this iam using video element.
The anomaly which iam seeing right now is that if iam setting the src programmatically then the file is not playing.
While the same path if iam directly giving in src then the video is playing.

The Video resides in Videos folder of solution, so i dont think there is any access issues.

Below code directly assigns the src for video - Playing the file.

function ShowModalPopup() {
//$find("mpe").show();
//return false;
var param1 = new Date();
var month = param1.getMonth() + 1;
var day = param1.getDate();
var param2 = (('' + day).length < 2 ? '0' : '') + day + '/' + (('' + month).length < 2 ? '0' : '') + month + '/' + param1.getFullYear() + ' ' + param1.getHours() + ':' + param1.getMinutes() + ':' + param1.getSeconds();
$("#<%= hdnStartDateTime.ClientID %>").val(param2);
var url = $get("<%=lnkVideoLink.ClientID %>").value;
alert(url);
//$get("video").src = url;
$('[id*="MyVdo"]').attr('src', '../../MS_RIT_Training_Videos/REITIworkatTest.mp4');//type='video/mp4'
//$('[id*="MyVdo"]')[0].play();
$find("mpe").show();
return false;
}


Below code programmatically assigning src - Not Playing the video

function ShowModalPopup() {
//$find("mpe").show();
//return false;
var param1 = new Date();
var month = param1.getMonth() + 1;
var day = param1.getDate();
var param2 = (('' + day).length < 2 ? '0' : '') + day + '/' + (('' + month).length < 2 ? '0' : '') + month + '/' + param1.getFullYear() + ' ' + param1.getHours() + ':' + param1.getMinutes() + ':' + param1.getSeconds();
$("#<%= hdnStartDateTime.ClientID %>").val(param2);
var url = $get("<%=lnkVideoLink.ClientID %>").value;
alert(url);
//$get("video").src = url;
// $('[id*="MyVdo"]').attr('src', '../../MS_RIT_Training_Videos/REITIworkatTest.mp4');//type='video/mp4'
$('[id*="MyVdo"]').attr('src', url);//type='video/mp4'
//$('[id*="MyVdo"]')[0].play();
$find("mpe").show();
return false;
}


For Kenneth :

enter image description here

Alert:

enter image description here

Answer

Are you sure the URLs are the same (hardcoded and the one you get from the element)?

also you can try to load the video programmatically after you set it

$('[id*="MyVdo"]')[0].load();