分享一段咪咕直播地址播放的代码。保存文件名为:mg.html,调用访问格式:http://www.tvbobo.com/mg.html?id=621826681
后面的ID就是你在咪咕视频那里获取来的直播频道的ID。
注意一点:咪咕直播的地址只能调用出来HTTP的,没办法加载HTTPS,所以只好使用HTTP方式了。
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>直播</title> </head> <body style="margin:0;padding:0;"> <script language="javascript"> var lurl=window.location.href; if(lurl.indexOf('mg.html?id=')>0) lurl=lurl.split('mg.html?id=')[1]; var xmlhttp; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest() } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP") } xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState==4 && xmlhttp.status==200){ var reg=/"url":"(.*?)"/; results = reg.exec(xmlhttp.responseText); var url=results[1].replace("http://h5live.gslb.cmvideo.cn","http://hlsmgsplive.miguvideo.com:8080"); u = encodeURIComponent(url); if (/iPhone|Linux|Android|iPad|iPod|ios|iOS|Windows Phone|Phone|WebOS/i.test(navigator.userAgent)) { document.writeln("<div style='width:100%;height:250px;margin:0;padding:0;float:left;'><video id=\"myvideo\" src=\"\'+u+\'\" controls=\"controls\" poster=\"\/\/i3.letvimg.com\/lc04_live\/201705\/05\/23\/01\/1493996499035new.gif\" autoplay=\"autoplay\" width=\"100%\" height=\"100%\"><\/video></div>"); }else{ document.writeln("<div style='width:100%;height:460px;margin:0;padding:0;float:left;'><embed style='width:100%;height:460px;' name=\'gPlayer\' src=\'http://g.alicdn.com/de/prismplayer-flash/1.2.16/PrismPlayer.swf?vurl="+u+"\' type=\'application/x-shockwave-flash\' allowfullscreen=\'true\'></embed></div>"); } } } var url = 'http://h5.miguvideo.com/playurl/v1/play/playurlh5?contId='+lurl; xmlhttp.open("get", url, true); xmlhttp.send(); </script> </body> </html>上面的代码喜欢的拿去不用谢,喜欢的话,帮忙点击网站https://www.tvbobo.com/给个IP。