video.html 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>liveplayer</title>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  7. <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
  8. <script type="text/javascript" src="liveplayer-element.min.js"></script>
  9. <script type="text/javascript">
  10. window.onload = function() {
  11. }
  12. window.addEventListener("message", function(event) {
  13. var data = event.data;
  14. switch (data.cmd) {
  15. case 'switchUrl':
  16. // 处理业务逻辑
  17. console.log("收到消息:"+JSON.stringify(data.params));
  18. var player = document.getElementById('player01');
  19. player.setAttribute("video-url",data.params["path"]);
  20. break;
  21. }
  22. });
  23. function getQueryVariable(variable) {
  24. var query = window.location.search.substring(1);
  25. var vars = query.split("&");
  26. for (var i = 0; i < vars.length; i++) {
  27. var pair = vars[i].split("=");
  28. if (pair[0] == variable) {
  29. return pair[1];
  30. }
  31. }
  32. return (false);
  33. }
  34. function onError(event){
  35. console.log("播放器错误:"+JSON.stringify(event));
  36. }
  37. function sendMsgToParent(cmd,data){
  38. window.parent.postMessage({
  39. cmd: cmd,
  40. params: {
  41. success: true,
  42. data: data
  43. }
  44. }, '*');
  45. }
  46. </script>
  47. </head>
  48. <body>
  49. <live-player id="player01" live="true" stretch="true" show-custom-button="false" autoplay error="onError">
  50. </live-player>
  51. <script>
  52. var videoPath = getQueryVariable("url");
  53. console.log('播放地址:' + videoPath);
  54. var player = document.getElementById('player01');
  55. player.setAttribute("video-url", videoPath);
  56. </script>
  57. </body>
  58. </html>