Can a videoview play a video stored on internal storage?

前端 未结 6 1501
一向
一向 2020-11-29 04:12

I\'m trying to provide my users with the ability to use either external or internal storage. I\'m displaying both images and videos (of a scientific nature). When storing th

6条回答
  •  伪装坚强ぢ
    2020-11-29 04:35

    I came across this thread with the same problem, I'm downloading my videos from the web to the internal storage, turns out when saving you can specify the RW mode, i.e change from PRIVATE to WORLD_READABLE

    URL url = new URL(_url);
    InputStream input = null;
    FileOutputStream output = null;
    
    try {
    String outputName = "video.mp4";
    
    input = url.openConnection().getInputStream();
    output = c.openFileOutput(outputName, Context.MODE_WORLD_READABLE);
    
    int read;
    byte[] data = new byte[5120]; //5MB byte array
    while ((read = input.read(data)) != -1)
    output.write(data, 0, read);
    
    return true;
    
    } finally {
    if (output != null)
       output.close();
    if (input != null)
       input.close();
        }
    }
    

提交回复
热议问题