我正在尝试通过此缓存视频
try {
URL oracle = new URL(url);
URLConnection yc = oracle.openConnection();
InputStream in = yc.getInputStream();
File file = new File(getApplicationContext().getCacheDir() ,url);
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() +"/"+ url);
videoView.setVideoPath("chmod 755 "+getCacheDir() +"/"+ url);
}else {
videoView.setVideoURI(Uri.parse(videoUrl));
}
} catch (Exception e) {
// TODO: handle exception
}
videoView.setVideoURI(Uri.parse(videoUrl));
MediaController mc = new MediaController(VideoViewC.this);
videoView.setMediaController(mc);
videoView.requestFocus();
videoView.start();
mc.show();
但我发现 Error java.net.SocketException: Connection reset by peer。
如果您有任何建议,请给我。