f-video.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* f-video.js */
  2. let F_Video;
  3. (function () {
  4. F_Video = function (url, option) {
  5. const u = window.navigator.userAgent.toLowerCase();
  6. const isAndroid = u.indexOf("android") > -1;
  7. let player = new Object();
  8. let newCanvas = document.createElement("canvas");
  9. let params = {
  10. canvas: newCanvas,
  11. loop: option.loop || false,
  12. autoplay: option.autoplay || false,
  13. onEnded: () => {
  14. option.onEnded && option.onEnded();
  15. player.currentTime = 0;
  16. },
  17. };
  18. newCanvas.style.width = "100%";
  19. newCanvas.style.height = "100%";
  20. newCanvas.style.objectFit = option.objectFit || "cover";
  21. player = new JSMpeg.Player(url.replace(".mp4", ".ts"), {
  22. ...option,
  23. ...params,
  24. });
  25. player.domElement = newCanvas;
  26. // if (isAndroid) {
  27. // let newCanvas = document.createElement("canvas");
  28. // let params = {
  29. // canvas: newCanvas,
  30. // loop: option.loop || false,
  31. // autoplay: option.autoplay || false,
  32. // onEnded: () => {
  33. // option.onEnded && option.onEnded();
  34. // player.currentTime = 0;
  35. // },
  36. // };
  37. // newCanvas.style.width = "100%";
  38. // newCanvas.style.height = "100%";
  39. // newCanvas.style.objectFit = option.objectFit || "cover";
  40. // player = new JSMpeg.Player(url.replace(".mp4", ".ts"), {
  41. // ...option,
  42. // ...params,
  43. // });
  44. // player.domElement = newCanvas;
  45. // } else {
  46. // let newVideo = document.createElement("video");
  47. // newVideo.setAttribute("x5-video-player-type", "h5");
  48. // newVideo.setAttribute("x-webkit-airplay", "true");
  49. // newVideo.setAttribute("airplay", "allow");
  50. // newVideo.setAttribute("playsinline", "");
  51. // newVideo.setAttribute("webkit-playsinline", "");
  52. // newVideo.setAttribute("src", url);
  53. // option.loop && newVideo.setAttribute("loop", "loop");
  54. // !option.autoplay && newVideo.setAttribute("preload", "auto");
  55. // option.autoplay &&
  56. // window.WeixinJSBridge &&
  57. // window.WeixinJSBridge.invoke("getNetworkType", {}, (e) => {
  58. // player.play();
  59. // });
  60. // newVideo.style.width = "100%";
  61. // newVideo.style.height = "100%";
  62. // newVideo.style.objectFit = option.objectFit || "cover";
  63. // player = newVideo;
  64. // player.domElement = newVideo;
  65. // option.onPlay && player.addEventListener("play", option.onPlay);
  66. // option.onPause && player.addEventListener("pause", option.onPause);
  67. // option.onEnded && player.addEventListener("ended", option.onEnded);
  68. // }
  69. return player;
  70. };
  71. })();