注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

东东的博客

江南烟雨,同大家一起分享

 
 
 

日志

 
 

android播放器(music player)源码分析5(在线播放功能)  

2011-04-06 15:41:29|  分类: android相关 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

根据上一篇文章中对百度MP3页面的解析,生成如下格式的xml文档。

Xml代码  1.<?xml version="1.0" encoding="UTF-8" standalone="no" ?>   
2.- <Result> 
3.- <Catagory cID="0"> 
4.  歌手排行   
5.  <SubCatagory Rank="1" Rex="<td><span>(.*?)\\.</span><a href=\"(.*?)\".*?>(.*?)</a></td>" Url="http://list.mp3.baidu.com/top/top200.html" cID="0" cName="歌手排行" cValue="歌手TOP200" />   
6.  <SubCatagory Rank="2" Rex="<td><span>(.*?)\\.</span><a href=\"(.*?)\".*?>(.*?)</a></td>" Url="http://list.mp3.baidu.com/top/rihangeshou.html" cID="0" cName="歌手排行" cValue="日韩歌手" />   
7.  <SubCatagory Rank="3" Rex="<td><span>(.*?)\\.</span><a href=\"(.*?)\".*?>(.*?)</a></td>" Url="http://list.mp3.baidu.com/top/oumeigeshou.html" cID="0" cName="歌手排行" cValue="欧美歌手" />   
8.  </Catagory> 
9.- <Catagory cID="1"> 
10.  歌曲排行   
11.  <SubCatagory Rank="2" Rex="<td class="tdc">.*?title='(.*?)'>.*?<td class="tdd">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/top100.html" cID="1" cName="歌曲排行" cValue="新歌TOP100" />   
12.  <SubCatagory Rank="3" Rex="<td class="tdc">.*?>(.*?)</.*?<td class="tdd">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/top500.html" cID="1" cName="歌曲排行" cValue="歌曲TOP500" />   
13.  <SubCatagory Rank="4" Rex="<td class=\"tdb\">.*?>(.*?)</a.*?<td class=\"tdc\"><.*?>(.*?)</" Url="http://list.mp3.baidu.com/top/bangping.html" cID="1" cName="歌曲排行" cValue="中文金曲榜" />   
14.  <SubCatagory Rank="5" Rex="<td class=\"tdc\">.*?title='(.*?)'>.*?<td class=\"tdd\">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/rihan.html" cID="1" cName="歌曲排行" cValue="日韩流行风" />   
15.  <SubCatagory Rank="6" Rex="<td class=\"tdc\">.*?title='(.*?)'>.*?<td class=\"tdd\">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/oumei.html" cID="1" cName="歌曲排行" cValue="欧美金曲" />   
16.  <SubCatagory Rank="7" Rex="<td class=\"tdc\">.*?title='(.*?)'>.*?<td class=\"tdd\">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/movie.html" cID="1" cName="歌曲排行" cValue="影视金曲" />   
17.  <SubCatagory Rank="8" Rex="<td class=\"tdc\">.*?title='(.*?)'>.*?<td class=\"tdd\">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/duichang.html" cID="1" cName="歌曲排行" cValue="热门对唱" />   
18.  <SubCatagory Rank="9" Rex="<td class=\"tdc\">.*?title='(.*?)'>.*?<td class=\"tdd\">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/yaogun.html" cID="1" cName="歌曲排行" cValue="摇滚歌曲榜" />   
19.  <SubCatagory Rank="10" Rex="<a href=\".*?>(.{1,5})-(.{1,10})</a></td>" Url="http://list.mp3.baidu.com/top/minyue.html" cID="1" cName="歌曲排行" cValue="中国民乐" />   
20.  <SubCatagory Rank="11" Rex="<td class=\"tdc\">.*?title='(.*?)'>.*?<td class=\"tdd\">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/junlvminge.html" cID="1" cName="歌曲排行" cValue="流金岁月" />   
21.  </Catagory> 
22.- <Catagory cID="2"> 
23.  音乐分类   
24.  <SubCatagory Rank="3" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&rf=idx&tn=baidump3&ct=134217728&lf=&rn=&word=%BE%AD%B5%E4%C0%CF%B8%E8&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="经典老歌" />   
25.  <SubCatagory Rank="4" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&rf=idx&tn=baidump3&ct=134217728&lf=&rn=&word=%CD%F8%C2%E7%B8%E8%C7%FA&lm=-1rf=bangdang" cID="2" cName="音乐分类" cValue="网络歌曲" />   
26.  <SubCatagory Rank="5" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=dj%CE%E8%C7%FA&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="DJ舞曲" />   
27.  <SubCatagory Rank="6" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%C7%E1%D2%F4%C0%D6&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="轻音乐" />   
28.  <SubCatagory Rank="7" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%C9%CB%B8%D0&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="伤感" />   
29.  <SubCatagory Rank="8" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%BC%C5%C4%AF&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="寂寞" />   
30.  <SubCatagory Rank="9" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%CF%EB%BF%DE&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="想哭" />   
31.  <SubCatagory Rank="10" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%B7%C7%D6%F7%C1%F7&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="非主流" />   
32.  <SubCatagory Rank="11" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=90%BA%F3&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="90后" />   
33.  <SubCatagory Rank="12" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=80%BA%F3&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="80后" />   
34.  <SubCatagory Rank="13" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%D0%A3%D4%B0%C3%F1%D2%A5&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="校园民谣" />   
35.  <SubCatagory Rank="14" Rex="" Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%C3%F1%B8%E8&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="民歌" />   
36.  <SubCatagory Rank="15" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%CF%E0%C9%F9&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="相声" />   
37.  <SubCatagory Rank="16" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%B6%F9%B8%E8&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="儿歌" />   
38.  </Catagory> 
39.- <Catagory cID="3"> 
40.//.......................略 
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
- <Result>
- <Catagory cID="0">
  歌手排行
  <SubCatagory Rank="1" Rex="<td><span>(.*?)\\.</span><a href=\"(.*?)\".*?>(.*?)</a></td>" Url="http://list.mp3.baidu.com/top/top200.html" cID="0" cName="歌手排行" cValue="歌手TOP200" />
  <SubCatagory Rank="2" Rex="<td><span>(.*?)\\.</span><a href=\"(.*?)\".*?>(.*?)</a></td>" Url="http://list.mp3.baidu.com/top/rihangeshou.html" cID="0" cName="歌手排行" cValue="日韩歌手" />
  <SubCatagory Rank="3" Rex="<td><span>(.*?)\\.</span><a href=\"(.*?)\".*?>(.*?)</a></td>" Url="http://list.mp3.baidu.com/top/oumeigeshou.html" cID="0" cName="歌手排行" cValue="欧美歌手" />
  </Catagory>
- <Catagory cID="1">
  歌曲排行
  <SubCatagory Rank="2" Rex="<td class="tdc">.*?title='(.*?)'>.*?<td class="tdd">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/top100.html" cID="1" cName="歌曲排行" cValue="新歌TOP100" />
  <SubCatagory Rank="3" Rex="<td class="tdc">.*?>(.*?)</.*?<td class="tdd">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/top500.html" cID="1" cName="歌曲排行" cValue="歌曲TOP500" />
  <SubCatagory Rank="4" Rex="<td class=\"tdb\">.*?>(.*?)</a.*?<td class=\"tdc\"><.*?>(.*?)</" Url="http://list.mp3.baidu.com/top/bangping.html" cID="1" cName="歌曲排行" cValue="中文金曲榜" />
  <SubCatagory Rank="5" Rex="<td class=\"tdc\">.*?title='(.*?)'>.*?<td class=\"tdd\">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/rihan.html" cID="1" cName="歌曲排行" cValue="日韩流行风" />
  <SubCatagory Rank="6" Rex="<td class=\"tdc\">.*?title='(.*?)'>.*?<td class=\"tdd\">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/oumei.html" cID="1" cName="歌曲排行" cValue="欧美金曲" />
  <SubCatagory Rank="7" Rex="<td class=\"tdc\">.*?title='(.*?)'>.*?<td class=\"tdd\">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/movie.html" cID="1" cName="歌曲排行" cValue="影视金曲" />
  <SubCatagory Rank="8" Rex="<td class=\"tdc\">.*?title='(.*?)'>.*?<td class=\"tdd\">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/duichang.html" cID="1" cName="歌曲排行" cValue="热门对唱" />
  <SubCatagory Rank="9" Rex="<td class=\"tdc\">.*?title='(.*?)'>.*?<td class=\"tdd\">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/yaogun.html" cID="1" cName="歌曲排行" cValue="摇滚歌曲榜" />
  <SubCatagory Rank="10" Rex="<a href=\".*?>(.{1,5})-(.{1,10})</a></td>" Url="http://list.mp3.baidu.com/top/minyue.html" cID="1" cName="歌曲排行" cValue="中国民乐" />
  <SubCatagory Rank="11" Rex="<td class=\"tdc\">.*?title='(.*?)'>.*?<td class=\"tdd\">.*?title='(.*?)'>" Url="http://list.mp3.baidu.com/top/junlvminge.html" cID="1" cName="歌曲排行" cValue="流金岁月" />
  </Catagory>
- <Catagory cID="2">
  音乐分类
  <SubCatagory Rank="3" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&rf=idx&tn=baidump3&ct=134217728&lf=&rn=&word=%BE%AD%B5%E4%C0%CF%B8%E8&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="经典老歌" />
  <SubCatagory Rank="4" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&rf=idx&tn=baidump3&ct=134217728&lf=&rn=&word=%CD%F8%C2%E7%B8%E8%C7%FA&lm=-1rf=bangdang" cID="2" cName="音乐分类" cValue="网络歌曲" />
  <SubCatagory Rank="5" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=dj%CE%E8%C7%FA&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="DJ舞曲" />
  <SubCatagory Rank="6" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%C7%E1%D2%F4%C0%D6&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="轻音乐" />
  <SubCatagory Rank="7" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%C9%CB%B8%D0&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="伤感" />
  <SubCatagory Rank="8" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%BC%C5%C4%AF&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="寂寞" />
  <SubCatagory Rank="9" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%CF%EB%BF%DE&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="想哭" />
  <SubCatagory Rank="10" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%B7%C7%D6%F7%C1%F7&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="非主流" />
  <SubCatagory Rank="11" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=90%BA%F3&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="90后" />
  <SubCatagory Rank="12" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=80%BA%F3&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="80后" />
  <SubCatagory Rank="13" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%D0%A3%D4%B0%C3%F1%D2%A5&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="校园民谣" />
  <SubCatagory Rank="14" Rex="" Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%C3%F1%B8%E8&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="民歌" />
  <SubCatagory Rank="15" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%CF%E0%C9%F9&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="相声" />
  <SubCatagory Rank="16" Rex="t:\"(.*?)\",s:\"(.*?)\",a:\"(.*?)\"," Url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%B6%F9%B8%E8&lm=-1&rf=bangdang" cID="2" cName="音乐分类" cValue="儿歌" />
  </Catagory>
- <Catagory cID="3">
//.......................略
  这里需要重载MediaStore类,加入以下几个属性

Java代码  1.public static final class OnLine{  
2.    public static final String ID = "_id";  
3. 
4.    public static final String URL = "Url";  
5. 
6.    public static final String NAME = "Name";  
7.    public static final String ALBUM = "album";  
8.    public static final String ARTIST = "artist";  
9. 
10.    public static final String CATAGORY_ID = "cID";  
11.    public static final String CATAGORY_NAME = "cName";  
12.    public static final String CATAGORY_VALUE = "cValue";  
13.    public static final String RANK = "Rank";  
14.    public static final String REX = "Rex";  
15. 
16.} 
    public static final class OnLine{
        public static final String ID = "_id";

        public static final String URL = "Url";

        public static final String NAME = "Name";
        public static final String ALBUM = "album";
        public static final String ARTIST = "artist";

        public static final String CATAGORY_ID = "cID";
        public static final String CATAGORY_NAME = "cName";
        public static final String CATAGORY_VALUE = "cValue";
        public static final String RANK = "Rank";
        public static final String REX = "Rex";

    }     这样将在线的MP3资源和播放器源码在数据结构上实现了一一对应,这里的url是每个分类的页面,通过该类中的正则表达式对该页面进行解析得到所有的音乐资源,然后在一个activity中显示出来并实现点击后在线播放。

      现在为止从整体上已经实现了在线播放,还存在以下问题需要解决

1.在线播放会出现中断问题
2.歌词同步
3.接下来UI的实现,例如歌词滚动

转自:http://blog.csdn.net/bigapple88/archive/2011/03/29/6285440.aspx

  评论这张
 
阅读(979)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017