如何在 Action Script 3 中使用 FLVPlayback 播放之前检查 FLV 文件是否存在?
我对动作脚本非常陌生,我正在使用 FLVPlayback
类来播放我的 FLV 文件。
如果我尝试播放尚不存在的 FLV 文件,则会收到“VideoError: 1000”,并显示消息无法连接到服务器或在服务器上找到 FLV
。
我想在通过 FLVPlayback 播放 FLV 之前使用文件 URL 或路径检查 FLV 文件是否存在。任何人都可以建议一种方法来做到这一点。
谢谢
I'm very new to the Action Scripting, I'm using the FLVPlayback
class to play my FLV files.
If I'm trying to play a FLV file which is not existed yet then I am getting a "VideoError: 1000" with message of Unable to make connection to server or to find FLV on server
.
I want to check for the FLV file existence using the file URL or path, before playing that FLV by FLVPlayback. Can anybody please suggest a way to do that.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
安全捕获错误的唯一方法是监听 fl.video.VideoEvent.STATE_CHANGE 事件并采取相应措施。以下是有关如何执行此操作的一些代码片段:
有关可能的 VideoState 常量的完整列表,请访问 fl.video.VideoState。
The only way to catch the error safely is to listen for the fl.video.VideoEvent.STATE_CHANGE event and act accordingly. Here's a little code snippet on how to do so:
For a full list of possible VideoState constants, visit fl.video.VideoState.
我认为您也许可以使用 stateChange 事件。可能的事件类型之一是 VideoState.CONNECTION_ERROR 另一个是 VideoState.DISCONNECTED 也可能有效。
尝试一下。
如果这些不起作用,我能想到的唯一方法是在尝试加载 flv 之前对它执行 HEAD 或 GET 请求。只有成功响应才会通过正常方法触发视频加载。我不记得 Flash 是否支持 HEAD 请求,但如果支持的话那肯定是更好的选择。
如果 Flash 不支持 HEAD 请求,那么您最好使用一个简单的服务器端脚本,该脚本可以在实际请求之前验证 flv 是否存在。这样您就可以使用简单的 GET 请求,而不必检索整个文件。
内联思维
我只是在想,使用 GET 的另一种可能的解决方案是在 bytesLoaded > 时立即取消加载。 1K(例如),或类似的东西。只要您检查的大小大于您收到的 404 响应,您就应该能够假设 flv 正在加载。
I think you may be able to make use of the stateChange event. One of the possible event types is VideoState.CONNECTION_ERROR and another is VideoState.DISCONNECTED which may also work.
Try giving that a shot.
If those don't work, the only way I can think of would be to either do a HEAD or GET request for the flv before you attempt to load it. Only a successful response would trigger the video loading through the normal method. I don't remember whether Flash supports HEAD requests, but if it does that would certainly be the better option.
If Flash does not support HEAD requests then you may be better off having a simple, server-side script that could verify the existence of the flv before you actually request if. That way you can use a simple GET request without having to retrieve the whole file.
INLINE THINKING
I am just thinking, another possible solution using GET would be to cancel the load as soon as bytesLoaded > 1K (for example), or something like that. As long as you are checking for a size greater than the 404 response you are getting, you should be able to assume the flv is being loaded.