English 中文(简体)
是否在 html5 视频播放器中设置视频源
原标题:detecting if video source is set in html5 video player

在我的申请中,我需要确保用户在继续其他动作之前,将视频设置为我的 html5 视频播放器的来源。 所以我尝试了这个方法(在Firefox使用Firebug):

当用户为视频播放器设置源时

vp = $( #myvideoplayer )
vp.attr( src )  --> "blob:5c254454-6c4e-4b69-b381-9ad60d6b1c4a"

当没有为视频设置源时

vp.attr( src )  --> undefined

我能否用这个来检测用户是否设置了视频源?

if(vp.attr( src ) != undefined){
   let_user_do_next_action();
}

还有什么更好的办法吗?

p.s:

我正使用 HTML5 文件输入部件设定视频源如下 。 (由于某种原因, 仅对 Firefox 使用此功能, 因为 Chrome 不允许 depateObjecturL window.webkiturL 获取 < code> 。 )

var file = $( #fileselect ).get(0).files[0];
if (file==undefined){
    alert( no file chosen );
}
var myURL = window.URL || window.webkitURL;
var fileURL = myURL.createObjectURL(file);
if(fileURL){
    player = $( #myvideoplayer );
    player.src=fileURL;
    player.load();
}
return;
最佳回答

该代码应该有效, 或者如果您想要防伪, 请检查 < code> typeof vp. attr ( src) = = “ 未定义” 。 如果您不使用 jQuery, 您可能想要检查 < code> element. hasAttribitte (“ rc”)

关于window.webkiturL.capideObjecturL ,我认为Chrome在本地重新测试时(例如,在file:// URL上)限制某些东西,而您要么必须在本地主机上设置简单的 HTTP 服务器,要么在本地主机上设置“http://www.chromium.org/ developers/how-tos/run-chromium-wilts" rel=“nofollow” > 启动Crome ,加上 -allow-file-access-fort-firms 。

问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!