简体   繁体   English

从google + / picasa android下载视频

[英]video download from google+/picasa android

We have a requirement to download video from google+/picasa and store it into sdcard. 我们需要从google + / picasa下载视频并将其存储到sdcard中。 Can you please any one help me to solve this issue? 能否请任何人帮助我解决此问题? google+/picasa google + / picasa

在此处输入图片说明

Converting from URI to byte[] , then byte[] is stored to file: URI转换为byte[] ,然后将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();

Can you try that one : 你能尝试一下吗:

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

I have recently encountered this. 我最近遇到了这个。

I first discovered that what I'm receiving is a picture rather than a video. 我首先发现我收到的是图片而不是视频。

But I didn't understand why Facebook is successfully playing the online video I shared via (Google+'s) Photo. 但是我不明白为什么Facebook成功地播放了我通过(Google+的)照片分享的在线视频。

I then occasionally discovered that the file they're currently giving is a GIF with the original extension in the MediaStore.Images.Media.DISPLAY_NAME section of the contentUri. 然后,我偶尔发现他们当前提供的文件是contentUri的MediaStore.Images.Media.DISPLAY_NAME部分中具有原始扩展名的GIF

Eeek! eek!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM