我正在尝试通过此
缓存视频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();
但我发现错误java.net.SocketException:连接由peer重置。
如果您有任何建议,请给我。
答案 0 :(得分:1)
我有我的案例问题,它特别包含我的http服务器,如果没有正确验证,只关闭客户端连接,这是我的问:
android-async-http Status code and response to onFailure
由于你的http服务器的特殊性,也许你也拥有它
您是否实施了缓存视频文件?