根据上一篇文章中对百度MP3页面的解析,生成如下格式的xml文档。
- <?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类,加入以下几个属性
- 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";
- }
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中显示出来并实现点击后在线播放。
现在为止从整体上已经实现了在线播放,还存在以下问题需要解决
- 在线播放会出现中断问题
- 歌词同步
- 接下来UI的实现,例如歌词滚动