如何使用 URLloader 将 byteArray 中的 FLV 格式数据发送到 php 脚本? [英] How to send a FLV format data in byteArray using URLloader to a php script?

查看:21
本文介绍了如何使用 URLloader 将 byteArray 中的 FLV 格式数据发送到 php 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建具有捕获/记录其游戏玩法的功能的 Flash 游戏,用户可以稍后查看,如重播.

Im creating flash game that have the functionality to capture/record its gameplay that can be viewed later by the user, like a replay.

至于现在,我已经能够记录游戏并将其写入 ByteArray 变量中的 flv 格式.

As for now Im already able to record the game and write it into a flv format in a ByteArray variable.

我现在正在做的是如何将 ByteArray(视频文件)发送到 php 脚本并将其保存到 Web 服务器.

What Im working right now is how to send that ByteArray(the video file) to a php script and save it to a web server.

我遇到了 Flash 中的 URLLoader,它可以发送数据,而 php 将通过 POST 方法接收它.不幸的是,包含 flv 数据的 ByteArray 必须首先正确编码,以便 php 读取它.我从网络中的示例中发现了这一点,它执行相同的操作,只是它仅发送 JPEG ByteArray 而不是使用 JPEGENCODER 的 FLV 格式.

I've run into the URLLoader in flash where it can send the data and php will receive it thru the POST method. Unfortunately, the ByteArray containing the flv data must be first correclty encoded for php to read it. I figured this out from the example in the net where it does the same thing only that it is only sending a JPEG ByteArray instead of a FLV format using the JPEGENCODER.

是否有任何现有类,例如用于 FLV 格式或任何视频格式的 JpegEncoder?或者像我自己创建编码器这样的解决方法?

Is there any existing class like the JpegEncoder for FLV format or any Video formats? Or any work around like creating the encoder my self?

提前谢谢各位.

这是我当前发送 ByteArray 的代码

here is my current code to send the ByteArray

            //send byteArray to a php script
        var request:URLRequest = new URLRequest(url);
        request.method = URLRequestMethod.POST;

        //need to correctly encode first the ByteArray in FLV format
        //....

        request.data = fs; //FLV byteArray  
        var loader:URLLoader = new URLLoader();
        trace(request.data);

推荐答案

刚刚想通了.

我现在可以在 php 脚本中成功发送 flv byteArray,然后 php 接收它并将其保存为本地系统中的 flv 文件,然后使用 zend 框架将其上传到 youtube 服务器.

I can now successfully send the flv byteArray in a php script where then the php receives it and save it as flv file in local system and uploading it in the youtube server using zend framework.

这是我的 Flash 代码.

here's my code in flash.

            //send byteArray to a php script
        var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
        var request:URLRequest = new URLRequest(url);

        request.requestHeaders.push (header);
        request.method = URLRequestMethod.POST;

        request.data = fs; //FLV byteArray  
        var loader:URLLoader = new URLLoader();
        trace(request.data);
        loader.load(request)

以及接收并保存为flv文件的scipt:

and the scipt that receives and save it as a flv file:

        $im =  $GLOBALS["HTTP_RAW_POST_DATA"];
    $fp = fopen("testVid.flv", 'w');    
    fwrite($fp, $im);
    fclose($fp);

事实证明,我真的不需要像 JPEGEncoder 所做的那样对 byteArray 进行编码.虽然我在 Flash 和 php 方面还是很新的.我不知道这是否是我能拥有的最佳实践.一个建议将不胜感激.谢谢各位.

It turns out that I really dont need to encode the byteArray like what the JPEGEncoder is doing. Im still very new in flash and php though. And I have no idea if this is the best practice I can have. An advice would be greatly appreciated. Thanks guys.

这篇关于如何使用 URLloader 将 byteArray 中的 FLV 格式数据发送到 php 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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