开发者

How to send a FLV format data in byteArray using URLloader to a php script?

开发者 https://www.devze.com 2023-01-30 10:39 出处:网络
Im creating flash game that have the functionality to capture/record its gameplay that can be viewed later by the user, like a replay.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消