vue通过腾讯视频url获取真实的video标签

野性酷女 2021-12-11 05:41 761阅读 0赞

直接上代码:

  1. mounted() {
  2. let match = /vid=([^&]*)/.exec(this.article.source_url);
  3. if (match && match.length > 0) {
  4. let vid = match[1];
  5. let self = this;
  6. jsonp("http://vv.video.qq.com/getinfo?vids="+vid+"&platform=101001&charge=0&otype=json",null,(err,data)=>{
  7. let ul = data.vl.vi;
  8. if (ul.length >0) {
  9. let fn = ul[0].fn;
  10. let vkey = ul[0].fvkey;
  11. let uis = ul[0].ul.ui;
  12. self.sources = [];
  13. if (uis.length >0) {
  14. uis.forEach((item,index)=>{
  15. let url = item.url;
  16. let source = {
  17. src: url+fn+"?vkey="+vkey,
  18. type: fn.indexOf("mp4")? "video/mp4": fn.indexOf("ogg") ? "video/ogg":"video/unknown"
  19. };
  20. self.sources.push(source);
  21. });
  22. }
  23. }
  24. });
  25. }

},

得到的都是分段的数据,组装起来最终得到:

  1. <template>
  2. <video controls="controls" :poster="article.cover" controlslist="nodownload" preload="meta" x5-playsinline="true" playsinline="true" webkit-playsinline="true" id="videoid" @play="read">
  3. <source v-for="(item,key) in sources" :key="key" :src="item.src" :type="item.type">
  4. </video>

发表评论

表情:
评论列表 (有 0 条评论,761人围观)

还没有评论,来说两句吧...

相关阅读

    相关 如何提取视频cookie?

    什么是cookie?cookie就相当于一个身份证,比如说张三,中国有很多人叫张三,假设有一天你去坐高铁。那么你只需要拿出身份证,进站前刷一下就可以进去了。所以,其它的张...