第一个Windows Phone 8 程序开发
前段时间在用WP8的【喜马拉雅客户端】听播客节目在使用过程中有些不足,心想自己动手做做。刚好最近在微博上看到msp的昌伟哥哥通过Fiddler抓包将iphone应用移植到WP8上了,参考他的文章
WP8开发实例-兔小贝儿歌iphone版移植到WP8实现(1)说做就做,利用周末的时间以及下班后休息时间开始了WP8的探索之旅,差不多一周的时间完成了大部分工作。仅以此来记录下我的开发过程。
在整个过程中使用了Free Telerik UI Controls for Windows 8 and Windows Phone 下拉刷新DataBoundListBox控件,并添加了一些动画效果,Windows Phone Toolkit 以及 json2csharp 将获取到的json转为对象,加快开发,另外数据库采用了SQLite。
一、数据抓取
利用Fiddler抓取到的json数据
搜索专题API:
其中keyword 是搜索关键字,pageId是返回分页数id,pageCount是每页数据条数。
json数据
{ "responseHeader": { "status": 0, "QTime": 13, "params": { "sort": "album_relation desc", "start": "0", "q": " '非常不着调'", "qf": "title^100 intro^5", "searchMessage": "{\"domain\":2,\"uid\":9315765,\"keyword\":\"非常不着调\",\"uuid\":\"7b04841945244cb7917fbf2718ac9c3b\",\"time\":\"20140519143526000\",\"from\":\"mobile\"}", "wt": "json", "fq": "", "defType": "dismax", "rows": "5" } }, "response": { "numFound": 866, "start": 0, "docs": [{ "category_id": 4, "cover_path": "http://fdfs.xmcdn.com/group3/M09/26/E3/wKgDsVMOAg_ijDyWAAaIFerBEYs765_mobile_small.jpg", "intro": "其实,我是一个很正直的人。新浪微博@主播掉掉。腾讯微博@掉掉。微信公众平台:diaodiao28613。贴吧:黄金第二档吧。各种联系方式,你再找不到我我就……", "user_source": "1", "id": 222885, "title": "非常不着调", "updated_at": 1397289600000, "created_at": 1384936334000, "uid": 1084167, "is_v": "true", "nickname": "掉掉", "avatar_path": "http://fdfs.xmcdn.com/group1/M00/14/5F/wKgDrlFcTZWRkIugAAA-ymQu-Kw034_mobile_small.jpg", "tracks": 51 }, { "category_id": 4, "cover_path": "http://fdfs.xmcdn.com/group4/M01/36/66/wKgDs1NECbSilfvoAACkxDpj6A0391_mobile_small.jpg", "intro": "", "user_source": "1", "id": 249020, "title": "非常溜+7", "updated_at": 1397125162000, "created_at": 1396967906000, "uid": 3945648, "is_v": "true", "nickname": "佳期", "avatar_path": "http://fdfs.xmcdn.com/group3/M04/78/2F/wKgDslKNmSOze4O1AACAsZnfl28226_mobile_small.jpg", "tracks": 12 }, { "category_id": 6, "intro": " 如果你喜欢探险,请记住最珍贵的宝藏并不是金子,而是只有善于观察和等待的人才能发现真正的宝藏,伊莎贝对探险生活充满了向往,她跟随探险家爸爸到一个热带孤岛上寻找宝藏,但伊莎贝和她的爸爸是两种截然不同的探险家——爸爸对古老的、静止不动的宝藏感兴趣,而伊莎贝喜欢活泼运动的大自然,爸爸不停地测量、挖掘,却徒劳无功,而伊莎贝在无意中发现了惊人的宝藏. ", "cover_path": "http://fdfs.xmcdn.com/group3/M0A/3C/D1/wKgDslMYHsrBK2eSAASMbcHJZ1k593_mobile_small.jpg", "user_source": "2", "id": 15970, "title": "非常小公主", "updated_at": 1395306582000, "created_at": 1370998123000, "uid": 1000273, "is_v": "true", "nickname": "少儿故事", "avatar_path": "http://fdfs.xmcdn.com/group1/M00/03/E0/wKgDrVDAWVCT6fnMAAR5t72dsIw715_mobile_small.jpg", "tracks": 23 }, { "category_id": 1, "intro": "《伯凡非常道》是中央人民广播电台经济之声播出的一档财经时事评论类节目,由21商业评论主编吴伯凡为大家评述自己独到鲜明的观点!21商业评论主编吴伯凡,《冬吴相对论》的主持人之一。", "cover_path": "http://fdfs.xmcdn.com/group2/M02/48/12/wKgDsFH02I2iMfzQAAEYAoIwumg350_mobile_small.png", "user_source": "2", "id": 194638, "title": "伯凡非常道", "updated_at": 1396378129000, "created_at": 1375004719000, "uid": 1860534, "is_v": "true", "nickname": "酷学课堂", "avatar_path": "http://fdfs.xmcdn.com/group2/M01/22/42/wKgDr1HJLJnjbROaAADUDrm_qlo232_mobile_small.jpg", "tracks": 47 }, { "uid": 1000095, "nickname": "百态人生", "is_v": "true", "category_id": 9, "cover_path": "http://fdfs.xmcdn.com/group1/M00/02/9C/wKgDrlCscFygWxCzAAcyT2FLTLA271_mobile_small.jpg", "intro": "每一个女孩都希望她是公主,每一个女人都希望她是皇后。 红颜祸水?红颜之所以成为祸水,那是因为男人要想蹬这浑水。人天生就是喜欢美丽的事物,只是程度不一样。每个人的需求都是不一样的。美丽可爱的女人谁都喜欢。如果没有人去追捧又哪来的祸水呢?就像你要吃臭豆腐,吃了却拉肚子,于是你怪这臭豆腐存在质量问题。我说不是,是你的肚子有问题,我吃了为什么就没拉呢? 女人往往忘记这样一点:她们的全部的教育无非是教她们意志坚强,抵抗外界的诱惑——但是她们耗费毕生的精力去挑拨外界的诱惑。 有两种男人最爱谈女人:女性蔑视者和女性崇拜者。两者的共同点是欲望强烈。历来关于女人的最精彩的话都是从他们口中说出的。那种对女性持公允折中立场的人说不出什么精彩的话,女人也不爱听,她们很容易听出公允折中背后的欲望乏弱。", "user_source": "2", "id": 782, "title": "红颜往事-正说历代非常女性", "updated_at": 1400125713000, "created_at": 1353478276000, "avatar_path": null, "tracks": 39 }] }, "highlighting": { "222885": {}, "249020": {}, "15970": {}, "194638": {}, "782": {} } }
然后根据json建立album对象,由于没有特殊字段和关系,这里直接用json2csharp进行生成,结果如下:
public class Album { public int category_id { get; set; } public string cover_path { get; set; } public string intro { get; set; } public string user_source { get; set; } public int id { get; set; } public string title { get; set; } public object updated_at { get; set; } public object created_at { get; set; } public int uid { get; set; } public string is_v { get; set; } public string nickname { get; set; } public string avatar_path { get; set; } public int tracks { get; set; } }
同样的方法得到track音频API与json数据以及对象
albumId是专辑id222885,pageId是当前页数id,per_pageCount是每页数据条数
http://mobile.ximalaya.com/mobile/others/ca/album/track/222885/True/1/5?device=WP
Json数据:
{ "ret": 0, "album": { "albumId": 222885, "categoryId": 4, "categoryName": "综艺娱乐", "title": "非常不着调", "coverOrigin": "http://fdfs.xmcdn.com/group3/M09/26/E3/wKgDsVMOAg_ijDyWAAaIFerBEYs765.jpg", "coverSmall": "http://fdfs.xmcdn.com/group3/M09/26/E3/wKgDsVMOAg_ijDyWAAaIFerBEYs765_mobile_small.jpg", "coverLarge": "http://fdfs.xmcdn.com/group3/M09/26/E3/wKgDsVMOAg_ijDyWAAaIFerBEYs765_mobile_meduim.jpg", "coverWebLarge": "http://fdfs.xmcdn.com/group3/M09/26/E3/wKgDsVMOAg_ijDyWAAaIFerBEYs765_web_large.jpg", "createdAt": 1384936334000, "updatedAt": 1400317151000, "uid": 1084167, "nickname": "掉掉", "isVerified": true, "avatarPath": "http://fdfs.xmcdn.com/group1/M00/14/5F/wKgDrlFcTZWRkIugAAA-ymQu-Kw034_mobile_small.jpg", "intro": "其实,我是一个很正直的人。新浪微博@主播掉掉。腾讯微博@掉掉。微信公众平台:diaodiao28613。贴吧:黄金第二档吧。各种联系方式,你再找不到我我就……", "introRich": "其实,我是一个很正直的人。新浪微博@主播掉掉。腾讯微博@掉掉。微信公众平台:diaodiao28613。贴吧:黄金第二档吧。各种联系方式,你再找不到我我就……", "tags": "流行,笑话,脱口秀,掉掉,非常不着调", "tracks": 51, "shares": 0, "hasNew": false, "isFavorite": false, "playTimes": 7163957, "lastUptrackAt": 1400313600000, "status": 1, "serializeStatus": 0 }, "tracks": { "list": [{ "trackId": 2720177, "playUrl64": "http://fdfs.xmcdn.com/group5/M01/0B/F1/wKgDtlN0Ynjx0wtxAJLc3oIuh94669.mp3", "playUrl32": "http://fdfs.xmcdn.com/group5/M01/0B/E5/wKgDtVN0YoGQ1mPSAElugJVwP-Q644.mp3", "downloadUrl": "http://fdfs.xmcdn.com/group5/M01/0B/E5/wKgDtVN0YlmCuYtxAEwyYPRvieM898.aac", "title": "【非常不着调】51-谁在12级龙卷风下抽烟啊", "duration": 1203.040, "processState": 2, "createdAt": 1400313600000, "coverSmall": "http://fdfs.xmcdn.com/group5/M02/0B/F0/wKgDtlN0YiOD6cwRAAaIFerBEYs560_mobile_small.jpg", "coverLarge": "http://fdfs.xmcdn.com/group5/M02/0B/F0/wKgDtlN0YiOD6cwRAAaIFerBEYs560_mobile_large.jpg", "uid": 1084167, "nickname": "掉掉", "smallLogo": "http://fdfs.xmcdn.com/group1/M00/14/5F/wKgDrlFcTZWRkIugAAA-ymQu-Kw034_mobile_small.jpg", "userSource": 1, "albumId": 222885, "albumTitle": "非常不着调", "albumImage": "http://fdfs.xmcdn.com/group3/M09/26/E3/wKgDsVMOAg_ijDyWAAaIFerBEYs765_mobile_small.jpg", "orderNum": 0, "opType": 1, "isPublic": true, "likes": 1464, "playtimes": 41657, "comments": 351, "shares": 0, "status": 1 }, { "trackId": 2681536, "playUrl64": "http://fdfs.xmcdn.com/group5/M00/00/1C/wKgDtVNslGWh2S5VAIjkNqpQmNA426.mp3", "playUrl32": "http://fdfs.xmcdn.com/group5/M02/00/1D/wKgDtlNslGSx4_7SAERyLHg3o1A647.mp3", "downloadUrl": "http://fdfs.xmcdn.com/group5/M02/00/1D/wKgDtlNslFjxeVo-AEcGRNIl8nw369.aac", "title": "【非常不着调】50-打架来说擎天柱最狠了", "duration": 1121.380, "processState": 2, "createdAt": 1400054400000, "coverSmall": "http://fdfs.xmcdn.com/group5/M02/00/1D/wKgDtlNslGDgRjx0AAFkFXk9oYA156_mobile_small.jpg", "coverLarge": "http://fdfs.xmcdn.com/group5/M02/00/1D/wKgDtlNslGDgRjx0AAFkFXk9oYA156_mobile_large.jpg", "uid": 1084167, "nickname": "掉掉", "smallLogo": "http://fdfs.xmcdn.com/group1/M00/14/5F/wKgDrlFcTZWRkIugAAA-ymQu-Kw034_mobile_small.jpg", "userSource": 1, "albumId": 222885, "albumTitle": "非常不着调", "albumImage": "http://fdfs.xmcdn.com/group3/M09/26/E3/wKgDsVMOAg_ijDyWAAaIFerBEYs765_mobile_small.jpg", "orderNum": 1, "opType": 1, "isPublic": true, "likes": 1921, "playtimes": 68457, "comments": 534, "shares": 0, "status": 1 }, { "trackId": 2681529, "playUrl64": "http://fdfs.xmcdn.com/group5/M02/00/1D/wKgDtlNslBPRN7lPAJgXpGn8Dv0998.mp3", "playUrl32": "http://fdfs.xmcdn.com/group5/M02/00/1D/wKgDtlNslADiO5PwAEwL46a9pI8097.mp3", "downloadUrl": "http://fdfs.xmcdn.com/group5/M02/00/1B/wKgDtVNsk_LDXXHcAE7pm8T0XpM693.aac", "title": "【非常不着调】49-你们那怎么叫出租车?", "duration": 1245.910, "processState": 2, "createdAt": 1399708800000, "coverSmall": "http://fdfs.xmcdn.com/group5/M00/00/1C/wKgDtlNsk9vBZG2YAAaIFerBEYs907_mobile_small.jpg", "coverLarge": "http://fdfs.xmcdn.com/group5/M00/00/1C/wKgDtlNsk9vBZG2YAAaIFerBEYs907_mobile_large.jpg", "uid": 1084167, "nickname": "掉掉", "smallLogo": "http://fdfs.xmcdn.com/group1/M00/14/5F/wKgDrlFcTZWRkIugAAA-ymQu-Kw034_mobile_small.jpg", "userSource": 1, "albumId": 222885, "albumTitle": "非常不着调", "albumImage": "http://fdfs.xmcdn.com/group3/M09/26/E3/wKgDsVMOAg_ijDyWAAaIFerBEYs765_mobile_small.jpg", "orderNum": 2, "opType": 1, "isPublic": true, "likes": 2639, "playtimes": 116404, "comments": 687, "shares": 0, "status": 1 }, { "trackId": 2576631, "playUrl64": "http://fdfs.xmcdn.com/group3/M09/5A/EC/wKgDsVNYe0HwqQvnAJF6lKuk-F8392.mp3", "playUrl32": "http://fdfs.xmcdn.com/group3/M09/5A/ED/wKgDsVNYe5ygtjlxAEi9W4WaRT0994.mp3", "downloadUrl": "http://fdfs.xmcdn.com/group3/M09/5A/EC/wKgDsVNYezKjMd6PAEt6petib8U450.aac", "title": "【非常不着调】48-游戏女发大招了", "duration": 1191.730, "processState": 2, "createdAt": 1399104000000, "coverSmall": "http://fdfs.xmcdn.com/group4/M02/46/D4/wKgDs1NYeuuzmtRwAAaIFerBEYs059_mobile_small.jpg", "coverLarge": "http://fdfs.xmcdn.com/group4/M02/46/D4/wKgDs1NYeuuzmtRwAAaIFerBEYs059_mobile_large.jpg", "uid": 1084167, "nickname": "掉掉", "smallLogo": "http://fdfs.xmcdn.com/group1/M00/14/5F/wKgDrlFcTZWRkIugAAA-ymQu-Kw034_mobile_small.jpg", "userSource": 1, "albumId": 222885, "albumTitle": "非常不着调", "albumImage": "http://fdfs.xmcdn.com/group3/M09/26/E3/wKgDsVMOAg_ijDyWAAaIFerBEYs765_mobile_small.jpg", "orderNum": 3, "opType": 1, "isPublic": true, "likes": 2943, "playtimes": 160506, "comments": 695, "shares": 0, "status": 1 }, { "trackId": 2570451, "playUrl64": "http://fdfs.xmcdn.com/group3/M0A/59/96/wKgDslNXJObSqSGKAJXsihgwHDM452.mp3", "playUrl32": "http://fdfs.xmcdn.com/group3/M0A/59/D1/wKgDsVNXJNGCV6EoAEr2Vhs5MLo802.mp3", "downloadUrl": "http://fdfs.xmcdn.com/group3/M0A/59/D1/wKgDsVNXJMGylPJNAE3JUtmrNbg817.aac", "title": "【非常不着调】47-我小时候有个梦想,养老虎", "duration": 1228.120, "processState": 2, "createdAt": 1398844800000, "coverSmall": "http://fdfs.xmcdn.com/group4/M01/49/12/wKgDtFNXJH2xOKaYAAaIFerBEYs813_mobile_small.jpg", "coverLarge": "http://fdfs.xmcdn.com/group4/M01/49/12/wKgDtFNXJH2xOKaYAAaIFerBEYs813_mobile_large.jpg", "uid": 1084167, "nickname": "掉掉", "smallLogo": "http://fdfs.xmcdn.com/group1/M00/14/5F/wKgDrlFcTZWRkIugAAA-ymQu-Kw034_mobile_small.jpg", "userSource": 1, "albumId": 222885, "albumTitle": "非常不着调", "albumImage": "http://fdfs.xmcdn.com/group3/M09/26/E3/wKgDsVMOAg_ijDyWAAaIFerBEYs765_mobile_small.jpg", "orderNum": 4, "opType": 1, "isPublic": true, "likes": 2447, "playtimes": 137545, "comments": 576, "shares": 0, "status": 1 }], "pageId": 1, "pageSize": 5, "maxPageId": 11, "totalCount": 51 }, "msg": "0" }
详细的专辑:Albumdetail
public class AlbumDetail { public int albumId { get; set; } public int categoryId { get; set; } public string categoryName { get; set; } public string title { get; set; } public string coverOrigin { get; set; } public string coverSmall { get; set; } public string coverLarge { get; set; } public string coverWebLarge { get; set; } public long createdAt { get; set; } public long updatedAt { get; set; } public int uid { get; set; } public string nickname { get; set; } public bool isVerified { get; set; } public string avatarPath { get; set; } public string intro { get; set; } public string introRich { get; set; } public string tags { get; set; } public int tracks { get; set; } public int shares { get; set; } public bool hasNew { get; set; } public bool isFavorite { get; set; } public int playTimes { get; set; } public long lastUptrackAt { get; set; } public int status { get; set; } public int serializeStatus { get; set; } }
音频:
public class Track { public int trackId { get; set; } public string playUrl64 { get; set; } public string playUrl32 { get; set; } public string downloadUrl { get; set; } public string title { get; set; } public double duration { get; set; } public int processState { get; set; } public object createdAt { get; set; } public string coverSmall { get; set; } public string coverLarge { get; set; } public int uid { get; set; } public string nickname { get; set; } public string smallLogo { get; set; } public int userSource { get; set; } public int albumId { get; set; } public string albumTitle { get; set; } public string albumImage { get; set; } public int orderNum { get; set; } public int opType { get; set; } public bool isPublic { get; set; } public int likes { get; set; } public int playtimes { get; set; } public int comments { get; set; } public int shares { get; set; } public int status { get; set; } }
二、APP设计
因为第一次尝试WP8开发,所以功能尽量简单,APP功能如下:
- 提供搜索专辑
- 提供添加到收藏功能
- 后台连续播放功能
- 下载功能(未实现)
- 播放进度提示 (拖拽进度未实现)
- 已播放提示
参考MVVM开发模式,自己也进行了尝试,完成了此次开发。详细的开发记录将在后续发上来。哈哈24k纯屌丝,无聊的时候听听喜马拉雅的段子来了和非常不着调、今晚80脱口秀。
主要页面截图: