【问题标题】:convert mp4 video to bytearray as3将 mp4 视频转换为 bytearray as3
【发布时间】:2014-03-31 16:50:12
【问题描述】:

我正在尝试将视频从 Android 应用程序的空气上传到 Facebook。 as3 facebook api 有以下上传视频的方法
facebookMobile.uploadVideo(method:String, callback:Function = null, params:* = null)
params:* (default = null) — An object containing the title, description, fileName (including extension), and video (FileReference or ByteArray)

我正在使用 cameraUi 录制视频,并且正在取回文件的位置。根据 api,我需要使用 fileReferancebyteArray 传递此文件,因为我已经有了文件的位置,我不想要任何类型的浏览功能。我在创建byteArray 时遇到了麻烦(以前从未使用过)。我从 facebook 收到 353 错误:you must select a video file

下面是我创建字节数组的尝试

    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 
        trace (inBytes);

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

【问题讨论】:

    标签: facebook actionscript-3 video air bytearray


    【解决方案1】:

    无需将其转换为ByteArrayFile 是一个仅限 AIR 的类,旨在允许您直接访问文件系统(正如您已经在做的那样)。由于File 扩展FileReference,您可以简单地传递您已经拥有的File 对象。

    【讨论】:

      猜你喜欢
      • 2017-04-05
      • 1970-01-01
      • 2021-12-02
      • 2015-06-14
      • 1970-01-01
      • 1970-01-01
      • 2012-07-20
      • 2012-05-07
      • 2022-11-02
      相关资源
      最近更新 更多