关于MediaPlayer seekTo的缓存位置问题 MediaPlayer通过一个Http Url访问网络上的一个MP3,比如:http:/xxx.com/1.mp3使用seekTo跳转到一个没有缓存的位置时,是从这个指定的位置开始缓存,还是从之前缓存的位置继续缓存到这个位置后再继续缓存?如果是后者,之前未缓存的数据如何再加载? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 URL url=new URL("http:/xxx.com/1.mp3")HttpURLConnection conn=(HttpURLConnction) url.openConnection();conn.setConnectTimeout(5*1000);conn.setRequestMethod("GET");if(conn.getResponseCode()!=200)throw new RuntimeException(“请求url失败");InputStream is=conn.getInputStream();readAsFile(is,"1.mp3");public static void readAsFile(inputStream inSream,File file)throws Exception{FileOutputStreaw outStreaw=new FileOutputStreaw(file);byte[] buffer=new byte[1024];int len=-1;while((len=inSreaw.read(buffer))!=-1){outStreaw.write(buffer,0,len);}outStreaw.close();inSream.close();} android中 组件 和 线程 的关系 !!! Android使用Socket通信 “科学上网”客户端 ndk的安装时setup.exe总是到快一半时停止了 这个"语音识别程序" 指的是什么? 是android的还是第三方的? android中如何实现GPS定位和文件共享啊 请教Android在3G网络中调用Http接口问题 为什么我在edittext输入的中文在控制台打印出来都是???这样的 是不是没转为UTF-8 sdk manager 无法更新 android开发中如何为progressbar添加动画效果 如何实现真正的随机选择时间??? android drm问题
HttpURLConnection conn=(HttpURLConnction) url.openConnection();
conn.setConnectTimeout(5*1000);
conn.setRequestMethod("GET");
if(conn.getResponseCode()!=200)throw new RuntimeException(“请求url失败");
InputStream is=conn.getInputStream();
readAsFile(is,"1.mp3");
public static void readAsFile(inputStream inSream,File file)throws Exception{
FileOutputStreaw outStreaw=new FileOutputStreaw(file);
byte[] buffer=new byte[1024];
int len=-1;
while((len=inSreaw.read(buffer))!=-1){
outStreaw.write(buffer,0,len);
}
outStreaw.close();
inSream.close();
}