下载一首网络歌曲 该歌曲地址获取不到歌曲的大小,但可以正常播放
来源:互联网 发布:网络非法集资案例 编辑:程序博客网 时间:2024/04/28 21:39
有些歌曲的下载地址,无法获得歌曲的大小:但可以正常播放
player.reset();
player.setDataSource(currSoundFileUrl);
System.out.println("yuan网址:" + currSoundFileUrl);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.prepare();
soundLength = player.getDuration();
soundLength有时获取不到歌曲的大小,为0;
这时最好是下载到本地再读取本地歌曲,用完时将歌曲删除:
下面是下载该类歌曲的代码:
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
URL url = new URL("http://218.94.93.115:8002/audioservernews/news/file2/news/tqh/air/download/52579f60c8f27d5f81c3d8b2?rate=wma/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Accept-Encoding", "identity");
int lene = conn.getContentLength();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
int len = -1;
byte[] buf = new byte[1024 * 8];
File file = new File("/mnt/sdcard/hello.wma");
RandomAccessFile raf = new RandomAccessFile(file, "rw");
raf.seek(0);
while((len = bis.read(buf)) != -1){
raf.write(buf, 0, len);
}
System.out.println("hello>>" + lene);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
源码下载
return null;
}
}.execute();
- 下载一首网络歌曲 该歌曲地址获取不到歌曲的大小,但可以正常播放
- 网页上不带下载链接但可播放的歌曲可以如何下载呢?
- 歌曲
- 歌曲
- 歌曲
- 歌曲
- 歌曲
- 歌曲
- 获取网络上歌曲下载链接
- 简单的歌曲播放
- 推荐歌曲 一百首最经典的歌曲下载
- 歌曲一首
- 获取SongTaste歌曲下地地址
- 一首励志的歌曲《我相信》
- 多线程下载网络歌曲&播放歌曲&并用seekbar调节进度&显示歌曲两边的时间
- Karaoke 歌曲播放
- powershell播放小黄人歌曲
- 非常好听但比较难找的歌曲
- C++ 获取机器的mac地址、获取字符串长度、写入日志等常用函数
- iOS7官方推荐图标和图像尺寸
- 有车一族都关心的一个问题
- js控制input输入格式
- 美国证券业托管和清算机构的发展与现状
- 下载一首网络歌曲 该歌曲地址获取不到歌曲的大小,但可以正常播放
- 设计模式原则
- cocos2d-x场景切换时内存过高导致crash 解决方法
- Cocos2d-x如何检测碰撞
- 数据结构-------顺序栈与链栈的实现
- javah 无法访问 com.heshen.HelloWorld Error: 未在命令行中指定任何类。请尝试使用 -help
- JAVA 开发实例 一 移动的小球
- poj 2299 Ultra-QuickSort
- Sales Process Overview