Playing video from app cache dir

本秂侑毒 提交于 2019-12-05 17:24:33

It's probably a permission issue. Here is a working snipped:

InputStream in = connection.getInputStream();

File file = new File(getApplicationContext().getCacheDir() ,fileName);

if(!file.exists()){
    file.setReadable(true);

    file.createNewFile();


    if (file.canWrite()){

        FileOutputStream out = new FileOutputStream(file);   

        byte[] buffer = new byte[1024];
        int len1 = 0;
        while ( (len1 = in.read(buffer)) > 0 ) {
            out.write(buffer,0, len1);
        }

        out.close();
    }

    in.close();

    Runtime.getRuntime().exec("chmod 755 "+getCacheDir() +"/"+ fileName);                       

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!