2014-03-31 154 views
0

我試圖從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)將mp4視頻轉換爲bytearray as3

我正在使用記錄的CameraUI的視頻和我得到迴文件位置下面的方法。根據api我需要通過使用fileReferancebyteArray這個文件,因爲我已經有了文件的位置,我不想要任何類型的瀏覽功能。我在創建byteArray時遇到了問題(以前從未使用過)。我從臉書獲得353錯誤:you must select a video file

貝婁是我創造的ByteArray

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

回答

1

無需將其轉換爲ByteArrayFile是一個AIR-only類,旨在允許您直接訪問文件系統(就像您已經在做的那樣)。由於File延伸了FileReference,您可以簡單地傳遞您已有的File對象。