我正在试着用这个缓存视频
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: Connection reset by peer。
如果你有任何建议,请给我。
发布于 2013-11-29 20:22:48
我有我的案例问题,特别是我的http服务器,如果没有正确的身份验证,它只是关闭了客户端连接,这是我的问题:
android-async-http Status code and response to onFailure
也许你也有它,由于你的httpserver的特性
你实现缓存视频文件了吗?
https://stackoverflow.com/questions/14213187
复制相似问题