html5视频标签以编程方式设置src [英] html5 video tag setting src programmatically
问题描述
我需要使用视频元素为此iam运行视频文件。
我现在看到的异常是,如果iam以编程方式设置src,那么该文件不会播放。
如果iam直接在src中给出相同的路径,那么视频正在播放。
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.
以下代码直接为视频分配src - 播放文件。
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;
}
下面代码以编程方式分配src - 不播放视频
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;
}
对于Kenneth:
提醒:
推荐答案
你确定这些网址是相同的(硬编码和你得到的网址)元件)?
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();
这篇关于html5视频标签以编程方式设置src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!