vue通过腾讯视频url获取真实的video标签
直接上代码:
mounted() {
let match = /vid=([^&]*)/.exec(this.article.source_url);
if (match && match.length > 0) {
let vid = match[1];
let self = this;
jsonp("http://vv.video.qq.com/getinfo?vids="+vid+"&platform=101001&charge=0&otype=json",null,(err,data)=>{
let ul = data.vl.vi;
if (ul.length >0) {
let fn = ul[0].fn;
let vkey = ul[0].fvkey;
let uis = ul[0].ul.ui;
self.sources = [];
if (uis.length >0) {
uis.forEach((item,index)=>{
let url = item.url;
let source = {
src: url+fn+"?vkey="+vkey,
type: fn.indexOf("mp4")? "video/mp4": fn.indexOf("ogg") ? "video/ogg":"video/unknown"
};
self.sources.push(source);
});
}
}
});
}
},
得到的都是分段的数据,组装起来最终得到:
<template>
<video controls="controls" :poster="article.cover" controlslist="nodownload" preload="meta" x5-playsinline="true" playsinline="true" webkit-playsinline="true" id="videoid" @play="read">
<source v-for="(item,key) in sources" :key="key" :src="item.src" :type="item.type">
</video>
还没有评论,来说两句吧...