player.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div>
  3. <div class="player-container">
  4. <div id="glplayer" class="glplayer"></div>
  5. </div>
  6. <div class="timeline__container">
  7. <span>TimeLine</span>
  8. <span id="ptsLabel" class="timeline" ref="timelineRef">00:00:00/00:00:00</span>
  9. </div>
  10. <div class="player__button" role="button" @click="resumeHandler">RESUME</div>
  11. <div class="player__button" role="button" @click="pauseHandler">PAUSE</div>
  12. </div>
  13. </template>
  14. <script>
  15. import "./lib/h265/decoder/missile.js";
  16. import { defineComponent, onMounted, onUnmounted, ref } from "vue";
  17. import {
  18. createPlayerServer,
  19. executePlayerServer,
  20. destoryPlayerServer,
  21. } from "./lib/util";
  22. /**
  23. * By default we define a constant vairiable should without vue module
  24. */
  25. const H265JS_DEFAULT_PLAYER_CONFIG = {
  26. player: "glplayer",
  27. width: 960,
  28. height: 540,
  29. token:
  30. "base64:QXV0aG9yOmNoYW5neWFubG9uZ3xudW1iZXJ3b2xmLEdpdGh1YjpodHRwczovL2dpdGh1Yi5jb20vbnVtYmVyd29sZixFbWFpbDpwb3JzY2hlZ3QyM0Bmb3htYWlsLmNvbSxRUTo1MzEzNjU4NzIsSG9tZVBhZ2U6aHR0cDovL3h2aWRlby52aWRlbyxEaXNjb3JkOm51bWJlcndvbGYjODY5NCx3ZWNoYXI6bnVtYmVyd29sZjExLEJlaWppbmcsV29ya0luOkJhaWR1",
  31. extInfo: {
  32. moovStartFlag: true,
  33. },
  34. };
  35. export default defineComponent({
  36. props: {
  37. src: String,
  38. },
  39. setup(props) {
  40. const timelineRef = ref(null);
  41. let playerObject = null;
  42. const resolveConfig = (conf) => Object.assign(H265JS_DEFAULT_PLAYER_CONFIG, conf);
  43. onMounted(() => {
  44. playerObject = createPlayerServer(props.src, resolveConfig());
  45. executePlayerServer(playerObject, timelineRef.value);
  46. });
  47. onUnmounted(() => destoryPlayerServer(playerObject));
  48. const playAction = (action) => {
  49. if (action === "pause" && playerObject.isPlaying()) {
  50. console.log("[Action]: Pause");
  51. playerObject.pause();
  52. return;
  53. }
  54. if (action === "resume" && !playerObject.isPlaying()) {
  55. console.log("[Action]: Resume");
  56. playerObject.play();
  57. return;
  58. }
  59. };
  60. const resumeHandler = () => playAction("resume");
  61. const pauseHandler = () => playAction("pause");
  62. return { resumeHandler, pauseHandler, timelineRef };
  63. },
  64. });
  65. </script>
  66. <style scoped>
  67. .header-line {
  68. height: 30px;
  69. }
  70. ul {
  71. margin: 0;
  72. padding: 0;
  73. }
  74. ul li {
  75. list-style-type: none;
  76. padding: 5px 0;
  77. }
  78. ul li a {
  79. text-decoration: none;
  80. }
  81. .player-container {
  82. width: 960px;
  83. height: 540px;
  84. }
  85. .player__button {
  86. border: 1px solid black;
  87. width: 80px;
  88. border-radius: 5px;
  89. text-align: center;
  90. margin: 10px 0;
  91. cursor: pointer;
  92. }
  93. .timeline__container {
  94. margin: 5px 0;
  95. }
  96. .timeline__container span:nth-child(2) {
  97. margin-left: 10px;
  98. }
  99. </style>