微企个人网

微企个人网

关于小程序video组件视频url获取方法

小程序真是一步一坑,最近在做一个视频播放组件,需要一些视频的url地址,结果发现直接拿腾讯视频中url根本不行,在网上看了好多帖子说的也不是特别详细,结果自己用了一天时间研究整理了一下,写了一个获取可用url的方法。希望能帮助到大家


先看效果




第一步 :

我们从腾讯视频网站上找到一个视频网页的连接,具体步骤就是打开视频点击分享,那个分享的链接就是我们要的




两个都可以复制下来  复制下来后是这样子 我们只需要src里的这段:


<embed src="https://imgcache.qq.com/tencentvideo_v1/playerv3/TPout.swf?max_age=86400&v=20161117&vid=h056607xye8&auto=0" allowFullScreen = "true" quality = "high" width = "480" height = "400" align = "middle" allowScriptAccess = "always" type = "application/x-shockwave-flash" > </embed> 


第二步 :

我们把上面链接的vid放到以下接口地址上 


http://vv.video.qq.com/getinfo?vid=h056607xye8&platform=101001&charge=0&otype=json


直接访问返回的是


QZOutputJson={"dltype":1,"exem":0,"fl":{"cnt":2,"fi":[{"id":100701,"name":"msd","lmt":0,"sb":1,"cname":"标清;(270P)","br":28,"profile":2,"drm":0,"video":1,"audio":1,"fs":5323273,"sl":1},{"id":2,"name":"mp4","lmt":0,"sb":1,"cname":"高清;(480P)","br":33,"profile":1,"drm":0,"video":1,"audio":1,"fs":4350801,"sl":0}]},"hs":0,"ip":"120.84.169.234","ls":0,"preview":179,"s":"o","sfl":{"cnt":0},"tm":1534563720,"vl":{"cnt":1,"vi":[{"br":28,"ch":0,"cl":{"fc":0,"keyid":"h056607xye8.100701"},"ct":21600,"drm":0,"dsb":0,"fmd5":"48ffbd2a6a51b5123ab39562d52ff4a3","fn":"h056607xye8.m701.mp4","fs":5323273,"fst":5,"fvkey":"602E36F78C39F1BDAD437852D1AD4761454FB879425EA85B20D91AB87F2FEA02216FA619E5F6017F83EAF28C9DDD9C1DB46E5122A42AB9E21B632BF21D6A9150DE28464DAB71EF2BA8B6C63A795E7BB69027B1BB2EA66C76B9080AD6F4923C9ADF08616E6CC3F36B","head":0,"hevc":0,"iflag":0,"level":0,"lnk":"h056607xye8","logo":1,"mst":8,"pl":null,"share":1,"sp":0,"st":2,"tail":0,"td":"179.797","ti":"微信小程序是什么 微信小程序宣传片","tie":0,"type":3,"ul":{"ui":[{"url":"http://ugcbsy.qq.com/uwMRJfz-r5jAYaQXGdGnC2_ppdhgmrDlPaRvaV7F2Ic/","vt":136,"dtc":0,"dt":2},{"url":"http://157.255.154.155/vhot2.qqvideo.tc.qq.com/Ax3eEHRro27R5XwVX92V7HgB5BpHLShvfK_u4luWUVLI/","vt":200,"dtc":0,"dt":2},{"url":"http://ugcsjy.qq.com/uwMRJfz-r5jAYaQXGdGnAWU8PgBpGqZogfytEoZCSHk/","vt":176,"dtc":0,"dt":2},{"url":"http://video.dispatch.tc.qq.com/","vt":0,"dtc":0,"dt":2}]},"vh":272,"vid":"h056607xye8","videotype":0,"vr":0,"vst":2,"vw":480,"wh":1.7647059,"wl":{"wi":[{"id":19,"x":14,"y":14,"w":85,"h":27,"a":100,"md5":"dcc9dc5c478c4100ea2817c5e6020f26","url":"http://puui.qpic.cn/vcolumn_pic/0/logo_qing_xi_color_336_108.png/0","surl":"https://puui.qpic.cn/vcolumn_pic/0/logo_qing_xi_color_336_108.png/0"}]},"uptime":1509094808,"fvideo":0,"fvpint":0}]}};


第三步:

 我们把前面的QZOutputJson=跟最后的 ; 过滤掉,得到一个json字符串了。解析它变成json对象,然后把标红的三个部分组合一下,顺序是 


url + fn + '?vkey=' + fvkey 


例如上面这串,组合下来就是 


https://ugcydzd.qq.com/uwMRJfz-r5jAYaQXGdGnC2_ppdhgmrDlPaRvaV7F2Ic/h056607xye8.m701.mp4?vkey=21BBAAD6135B6FE0353345BECC2CB66CA1395F25DC3D3D395BB2901BAA23DEB402854625B18E37A8D980AD0E7794472608E6537F82D0346BCD8D996D62B2504BD72B30F14A4DFFDCEC0094D575B8550E6D2FA4B0E38994275751FBA27AD481100F1E837199DC1B69


这个地址就可以直接放在小程序的video组件里面播放了。

————————————————


Powered By Z-BlogPHP 1.5.2 Zero

微企个人网版权所有 网站备案号:粤ICP备14014426号-1