HTTP链接下载音乐文件问题? 好像你的URL和connection之间没啥关系啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 试试这个: /* 判断传入的地址是否为URL */ if (!URLUtil.isNetworkUrl(strPath)) { mMediaPlayer01.setDataSource(strPath); } else { if(bIsReleased == false) { /* 创建URL对象 */ URL myURL = new URL(strPath); URLConnection conn = myURL.openConnection(); conn.connect(); /* 取得URLConnection的InputStream */ InputStream is = conn.getInputStream(); if (is == null) { throw new RuntimeException("stream is null"); } /* 创建新的临时文件 */ File myTempFile = File.createTempFile("temp", "."+getFileExtension(strPath)); currentTempFilePath = myTempFile.getAbsolutePath(); FileOutputStream fos = new FileOutputStream(myTempFile); byte buf[] = new byte[128]; do { int numread = is.read(buf); if (numread <= 0) { break; } fos.write(buf, 0, numread); }while (true); } LZ的文件路径不对吧File musicFile = new File("/sdcard/");这个只是一个目录吧 没有创建文件,/sdcard/mp3.mp3.还有byte[] bt = new byte[is.available()];这种做法不是很安全,这可能会导致文件读取不完整。最好的做法是每次读取1K,byte[] bt = new byte[1024] 编译android 4.0.3的时候出现错误。 请教一个数据库的问题 android权限问题 水货行货大不相同 - 我对android权限机制的一些想法,热烈欢迎大家斧正 提问:如何去掉listview之间的黑线 多个ListView数据显示完整,不用滚动条 如何判断虚拟键盘状态 Cursor.close()后程序跳转的问题 关于安卓 一键刷机的原理 字符串转16进制串问题,在线等,急急急! 用什么工具开发? 新人求教!!
if (!URLUtil.isNetworkUrl(strPath))
{
mMediaPlayer01.setDataSource(strPath);
}
else
{
if(bIsReleased == false)
{
/* 创建URL对象 */
URL myURL = new URL(strPath);
URLConnection conn = myURL.openConnection();
conn.connect();
/* 取得URLConnection的InputStream */
InputStream is = conn.getInputStream();
if (is == null)
{
throw new RuntimeException("stream is null");
}
/* 创建新的临时文件 */
File myTempFile = File.createTempFile("temp", "."+getFileExtension(strPath));
currentTempFilePath = myTempFile.getAbsolutePath();
FileOutputStream fos = new FileOutputStream(myTempFile);
byte buf[] = new byte[128];
do
{
int numread = is.read(buf);
if (numread <= 0)
{
break;
}
fos.write(buf, 0, numread);
}while (true);
}
File musicFile = new File("/sdcard/");这个只是一个目录吧