as3将视频转换为byteArray

时间:2014-03-11 22:51:08

标签: actionscript-3 file video path bytearray

我正在尝试使用as3 api(FacebookMobile.uploadVideo)将视频上传到Facebook,该视频接受fieleReferancebyteArray视频。 a跟随示例@ http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7d54.html创建byteArray我在解压缩字节数组时出现2058错误(这可能是因为我dident压缩它但在示例中没有adobe)。 如果我发表评论,我会从Facebook收到#353 You must select a video file to upload错误。 字节数组代码:

public function UICompleteHandler(event:MediaEvent):void
{
    trace("Welcome back from the camera");
    var media:MediaPromise = event.data;
    trace("file info "+media.file.url  + " - " + media.relativePath + " - " + media.mediaType);
    filePath = media.file.url;
    trace("Object encoding is: " + inBytes.objectEncoding + "\n\n" + "order file: \n\n");
    readFileIntoByteArray(filePath, inBytes); 
    trace("length 1:   "+inBytes.length);
    trace("position 1: "+inBytes.position);
    inBytes.position = 0; // reset position to beginning 

    //inBytes.uncompress(CompressionAlgorithm.DEFLATE); 

    trace("position 2:  "+inBytes.position);
    inBytes.position = 0;    //reset position to beginning 
}
private function readFileIntoByteArray(fileName:String, data:ByteArray):void 
{ 
     var inFile:File = new File(fileName);
     trace ("file to byte array  "+  inFile.url);
     trace ("file name var : "+fileName);

     inStream.open(inFile , FileMode.READ);
     inStream.readBytes(data); 
     inStream.close(); 
}

处理上传代码:

public function handleUpload(ev:TouchEvent)
{
    trace ("posting to facebook - FileName: "+  accessCamera.fileName + " - FilePath: " + accessCamera.filePath);
    var params:Object ={  
        title:'test upload on FB api',
        description:'test upload on FB api',
        fileName: accessCamera.fileName,
        video: accessCamera.inBytes
    }

    trace ("params.video = "+params.video);

    FacebookMobile.uploadVideo('me/videos', onComplete, params);
}

private function onComplete( result:Object, fail:Object ):void {
    trace("facebook post onComplete called" );
    if (result)
    {
        //result.id is id of post that was just posted
        trace ("great");
    }
    else if (fail)
    {
        trace("post Failed");  
        trace('code: '+fail.error.code); 
        trace('message: '+fail.error.message);
        trace('type: '+fail.error.type); 
    }
}

当我追踪params.video时,我得到一堆随机字符。问题似乎是facebook dosnt看起来像bytearray(如果我甚至成功完全创建它)作为视频。

0 个答案:

没有答案