f-video.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. })()