具有AutoPlay阻止源文件夹的HTML5视频无法重命名 [英] HTML5 Video with AutoPlay block source folder from being renamed

查看:127
本文介绍了具有AutoPlay阻止源文件夹的HTML5视频无法重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个奇怪的问题.我有一个网页,用户可以上传视频,并且上传完成后,视频可以在小屏幕上的HTML5视频上播放(使用标记中的自动播放").同样,在上传之后,用户可以单击按钮来保存他们上传的内容,从而重命名包含视频的文件夹.但是,如果他们单击保存按钮的速度过快,则IIS会提示该文件夹不可用(用于重命名).但是,如果他们等待播放视频的时间大约为20秒,它将重命名该文件夹.另外,如果视频未在自动播放"中,则可以正常运行.

I have encountered a strange issue. I have a webpage where users can upload a video and the video plays on a HTML5 video (using "autoplay" in the tag) on a small screen after the upload is completed. Also, after the upload, the user can click a button to save what they have uploaded, whereby the folder containing the video is renamed. However, if they click save button too quickly, IIS gives an error that the folder is unavailable (for renaming). But if they wait about 20 seconds into the video playing, it renames the folder okay. Also, if the video is not on "autoplay", it works okay.

起初,我虽然必须在缓冲视频,但是我编写了一些JavaScript来显示控制台中的事件,不,它不是在缓冲...它只是在播放并提供timeupdates(这是正常的).为了演示,这是两种情况下事件输出的图像,即是否带有自动播放".

Initially, I though the video must be buffering, so I wrote some javascript to reveal the events in the console and, no, it is not buffering...it's just playing and giving timeupdates (which is normal). To demonstrate, here is an image of the event output of both scenarios, i.e., with/without "autoplay".

我想弄清楚HTML5视频正在做什么,以阻止将该文件夹重命名,以便用户可以立即保存上载的视频(并重命名该文件夹),而不必等待...或者至少,向用户提供一条消息,等待特定的时间,然后再单击按钮进行保存.感谢您的帮助.

I would like to figure out what the HTML5 video is doing to block the folder from being renamed so that the user can save the uploaded video (and rename the folder) immediately, without having to wait...or, at least, provide a message to the user to wait for a particular amount of time before clicking the button to save it. Any help is appreciated.

我试图暂停视频并删除源,就像这样...

I have tried to pause the video and remove the source, like this...

vid.pause();
vid.src = '';

...当用户单击保存"按钮时,该按钮不起作用.

...when the user clicks the save button, but it didn't work.

推荐答案

我找到了答案……这很棘手.当我显示所有正在控制台中执行的视频事件时,我发现IE和Chrome报告"networkStatus"属性和"suspend"事件的方式有所不同.具体来说:

I found the answer...and it was tricky. When I showed all of the video events being executed in the console, I found that IE and Chrome report the "networkStatus" property and the "suspend" event differently. To be specific:

  • IE:当视频加载完毕且 开始自动播放.您只能知道 通过检查"networkStatus"属性来释放源文件(必须 等于1).因此,我们需要:networkStatus == 1(挂起"的数目将为零).
  • Chrome浏览器:报告网络状态== 1之前的事件 源文件夹被释放...不信任它.您必须检查 发生了多少暂停"事件的计数(必须更大) 大于1)或已发生多少个可搜索"事件(至少其中之一)的计数.因此,我们希望:挂起"的数量大于1(无论networkStatus,它应该已经是1).
  • IE: does not report "onsuspend" events when the video loads up and starts playing on autoplay. You can only know that the folder of the source file is freed by checking the "networkStatus" property (must equal 1). So, we want: networkStatus==1 (and number of "suspend"s will be zero).
  • Chrome: reports networkStatus == 1 on events before the folder of the source is freed...don't trust it. You must check for a count of how many "onsuspend" events have occurred (must be greater than 1) or count of how many "seekable" events have occurred (at least one of these). So, we want: number of "suspend"s greater than one (regardless of networkStatus, which should already be one).

因此,总而言之,这是我用来检测何时释放源视频文件的文件夹的逻辑:

So, in summary, here is the logic I used to detect when the folder of the source video file was freed:

var countofsuspends = 0;
vid.onsuspend = function() {countofsuspends += 1;}
if ((vid.networkState == 1)&&((countofsuspends != 1)||(countofseeks > 0))) {} //...do something here...

&&"的第一部分以上是解决IE问题的方法.第二部分是解决Chrome问题.

The first part of the "&&" above is to address the IE issue. The second part is to address the Chrome issue.

希望这可以帮助其他人.

Hope this helps someone else out there.

这篇关于具有AutoPlay阻止源文件夹的HTML5视频无法重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆