2015-01-12 9 views
0

Google은 google +/picasa에서 비디오를 다운로드하여 sdcard에 저장해야합니다. 이 문제를 해결할 수 있도록 도와 주시겠습니까? 구글 URI에서 byte[]로 변환 +/Picasa를google +/picasa android에서 비디오 다운로드

enter image description here

byte[]는 파일에 저장됩니다

InputStream videoStream = getActivity().getContentResolver().openInputStream(videoUri); 
byte bytes[] = ByteStreams.toByteArray(videoStream); 
videoFile = new File("abcd.mp4"); 
FileOutputStream out = new FileOutputStream(videoFile); 
out.write(bytes); 
out.close(); 
+0

지금까지 시도한 것을 보여주십시오. – Vishwanath

+0

수정 된 코드를 확인하십시오. 이제 비디오는 sdcard에 저장되지만 재생되지 않습니다 ... :( – Krishna

답변

0

는 당신이 시도 할 수있는 하나

public String DownloadFromUrl(String DownloadUrl, String fileName) { 

File SDCardRoot = null; 
try { 
    SDCardRoot = Environment.getExternalStorageDirectory(); 
    File files = new File(SDCardRoot+fileName); 
    int sizeoffile; 
    if(!files.exists()) 
    { 
     File root = android.os.Environment.getExternalStorageDirectory();    

     File dir = new File (root.getAbsolutePath()); 
     if(dir.exists()==false) { 
      dir.mkdirs(); 
     } 

     URL url = new URL(DownloadUrl); 
     File file = new File(dir, fileName); 

     /* Open a connection to that URL. */ 
     URLConnection ucon = url.openConnection(); 
     sizeoffile = ucon.getContentLength(); 
     Log.d("SIZEOFFILE: ", sizeoffile+" BYTE"); 
     /* 
     * Define InputStreams to read from the URLConnection. 
     */ 
     InputStream is = ucon.getInputStream(); 
     BufferedInputStream bis = new BufferedInputStream(is); 

     /* 
     * Read bytes to the Buffer until there is nothing more to read(-1). 
     */ 
     ByteArrayBuffer baf = new ByteArrayBuffer(5000); 
     int current = 0; 
     while ((current = bis.read()) != -1) { 
      baf.append((byte) current); 
     } 
     /* Convert the Bytes read to a String. */ 
     FileOutputStream fos = new FileOutputStream(file); 
     fos.write(baf.toByteArray()); 
     fos.flush(); 
     fos.close(); 
    } 
} 
catch (IOException e) { 
    e.getMessage(); 
} 

return SDCardRoot+fileName; } 
0
Finally i found the solution. 



Uri videoUri = data.getData(); 
        File videoFile = null; 
        final InputStream imageStream; 
        try { 
         imageStream = getActivity().getContentResolver().openInputStream(videoUri); 
         byte bytes[] = ByteStreams.toByteArray(imageStream);//IStoByteArray(imageStream); 
         videoFile = new File(Environment.getExternalStorageDirectory()+ "/"+System.currentTimeMillis()+".mp4"); 
         videoFile.createNewFile(); 
         FileOutputStream out = new FileOutputStream(videoFile); 
         out.write(bytes); 
         out.close(); 
        } catch (FileNotFoundException e) { 
         e.printStackTrace(); 
        }catch (Exception ee){ 
         ee.printStackTrace(); 
        } 
0

I 있다 최근에이 문제가 발생했습니다.

내가받은 것은 비디오가 아닌 그림입니다.

하지만 페이스 북이 (Google +의) 사진을 통해 공유 한 온라인 비디오를 성공적으로 재생하는 이유를 알지 못했습니다.

는 그때 때때로 그들은 현재 제공하고있는 파일이 contentUri의 MediaStore.Images.Media.DISPLAY_NAME 섹션에서 원래의 확장자를 가진 GIF 것을 발견했다.

Eeek!