2012-06-26 21 views
0

我有一个摄像头记录的意图,当结果是好的,我尝试此视频为byte []转换为发送web服务:录像为byte []

Im做这样的:

if (resultCode == RESULT_OK) { 
        // Video guardado 
        videoUri = data.getData(); 
        if (videoUri != null) { 

         ByteArrayOutputStream out = new ByteArrayOutputStream(); 
         FileInputStream fichero_codificar = null; 
         try { 

          fichero_codificar = new FileInputStream(
            videoUri.getPath()); 

          byte[] buf = new byte[1024]; 
          int n; 
          while (-1 != (n = fichero_codificar.read(buf))) { 
           out.write(buf, 0, n); 
          } 
          byte[] videoByte = out.toByteArray(); 
          strBase64 = Base64.encode(videoByte); 
         } catch (FileNotFoundException e) { 
          e.printStackTrace(); 
         } catch (IOException e) { 
          e.printStackTrace(); 
         } 

但fichero_codificar =新的FileInputStream( videoUri.getPath())

logcat的说我的文件不存在,或补丁心不是propertly。

任何人都有我的问题的例子吗? 谢谢

+0

您是否验证过videoUri实际上是一个文件(文件:前缀)而不是“content:”URI? – tiguchi

回答

0

看起来你找不正确的信息。这里是我使用的相机意图在我的应用程序:

   thumbnail = (Bitmap) data.getExtras().get("data"); 
      try { 

       FileOutputStream out = new FileOutputStream(getPicName(index)); 
       thumbnail.compress(Bitmap.CompressFormat.PNG, 90, out); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 

所以也许尝试连同视频对象,而不是一个位图对象类似的规定。 如果这不起作用,您可以尝试使用.getAbsolutePath()。

是的,它绝对没有做你认为它做的事。我运行了我的调试器,getPath返回:/external/images/media/21,这是一个Uri内容。

+0

以及如何从内容uri获取文件? – rbrlnx