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

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

问题描述

我创建的Flash游戏具有捕获/记录其游戏性的功能,可以在以后由用户查看,如重播。

现在,我已经能够记录游戏,并将其写入一个ByteArray变量的flv格式。

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

我已经在flash里面运行了URLLoader,它可以发送数据,php会通过POST方法接收。不幸的是,包含flv数据的ByteArray必须先经过相关编码才能被PHP读取。我从网上的例子中解释了这一点,它只是发送JPEG ByteArray而不是使用JPEGENCODER的FLV格式。



是有任何现有的类,如FLV格式的JpegEncoder或任何视频格式?或任何工作,如创建编码器我自己?

感谢提前家伙。

这是我目前发送ByteArray的代码

  //将byteArray发送到php脚本
var request:URLRequest = new URLRequest(url );
request.method = URLRequestMethod.POST;

//需要先正确编码FLV格式的ByteArray
// ....

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


解决方案


$ b

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



这是我在闪存中的代码。

  //发送byteArray到一个php脚本
var header:URLRequestHeader = new URLRequestHeader(Content-type, 应用程序/八位字节流);
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(请求)

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

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

事实证明,我真的不需要像JPEGEncoder所做的那样对byteArray进行编码。即使如此,我仍然非常新的Flash和PHP。而且我不知道这是否是我能做的最好的做法。一个建议将不胜感激。谢谢你们。


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

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

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.

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.

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?

Thanks in advance guys.

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);

解决方案

Just figured this out.

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.

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)

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);

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将字节数组中的FLV格式数据发送到PHP脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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