如何在 Action Script 3 中使用 FLVPlayback 播放之前检查 FLV 文件是否存在?

发布于 2024-09-12 04:06:03 字数 246 浏览 2 评论 0原文

我对动作脚本非常陌生,我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谢绝鈎搭 2024-09-19 04:06:03

安全捕获错误的唯一方法是监听 fl.video.VideoEvent.STATE_CHANGE 事件并采取相应措施。以下是有关如何执行此操作的一些代码片段:

import fl.video.FLVPlayback;
import fl.video.VideoEvent;
import fl.video.VideoState;

var videoPlayer:FLVPlayback;
videoPlayer.addEventListener( VideoEvent.STATE_CHANGE, onVideoStateChange );
/** Bad source  **/
videoPlayer.source = "http://www.helpexamples.com/flash/video/caption_video_error.flv";
/** Good source **/
//videoPlayer.source = "http://www.helpexamples.com/flash/video/caption_video.flv";

function onVideoStateChange( evt:VideoEvent ):void
{
    var videoPlayer:FLVPlayback = evt.target as FLVPlayback;
    switch( evt.state )
    {
        case VideoState.CONNECTION_ERROR:
            trace( 'Connection error' );
            /**
             * Once you hit this event, you should run some logic to do one or more of the following:
             *   1. Show an error message to the user
             *   2. Try to load another video
             *   3. Hide the FLVPlayback component
             */
            break;
        default:
            trace( 'Player is: ' + evt.state );
    }
}

有关可能的 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:

import fl.video.FLVPlayback;
import fl.video.VideoEvent;
import fl.video.VideoState;

var videoPlayer:FLVPlayback;
videoPlayer.addEventListener( VideoEvent.STATE_CHANGE, onVideoStateChange );
/** Bad source  **/
videoPlayer.source = "http://www.helpexamples.com/flash/video/caption_video_error.flv";
/** Good source **/
//videoPlayer.source = "http://www.helpexamples.com/flash/video/caption_video.flv";

function onVideoStateChange( evt:VideoEvent ):void
{
    var videoPlayer:FLVPlayback = evt.target as FLVPlayback;
    switch( evt.state )
    {
        case VideoState.CONNECTION_ERROR:
            trace( 'Connection error' );
            /**
             * Once you hit this event, you should run some logic to do one or more of the following:
             *   1. Show an error message to the user
             *   2. Try to load another video
             *   3. Hide the FLVPlayback component
             */
            break;
        default:
            trace( 'Player is: ' + evt.state );
    }
}

For a full list of possible VideoState constants, visit fl.video.VideoState.

路弥 2024-09-19 04:06:03

我认为您也许可以使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文