index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <div id="videoPreview">
  3. <el-dialog
  4. :visible.sync="diavos"
  5. width="840px"
  6. @opened="isOkBf"
  7. @close="clears"
  8. :show-close="false"
  9. :close-on-click-modal="false"
  10. >
  11. <div slot="title" class="hearders">
  12. <div class="leftTitle">视频预览</div>
  13. <div class="rightBoxs">
  14. <img src="@/assets/images/Close@2x.png" alt @click="clears" />
  15. </div>
  16. </div>
  17. <div>
  18. <div id="player" v-if="listData.sectionType === 1"></div>
  19. <div id="playerzb" v-if="listData.sectionType === 2"></div>
  20. </div>
  21. <span slot="footer" class="dialog-footer">
  22. <el-button @click="clears">取 消</el-button>
  23. </span>
  24. </el-dialog>
  25. </div>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. vodPlayerJs: "https://player.polyv.net/script/player.js",
  32. vid: "",
  33. vidzb: "",
  34. playerJs:
  35. "https://player.polyv.net/resp/live-h5-player/latest/liveplayer.min.js",
  36. vodPlayerJsForTCPlayer:
  37. "https://web.sdk.qcloud.com/player/tcplayer/release/v5.1.0/tcplayer.v5.1.0.min.js",
  38. uidzb: "egsxlptzdq",
  39. fileSetting: {
  40. desc: "i am desc", // 描述
  41. cataid: "1639399775001", // 分类ID 可以后端传递 也可以不写 或写死
  42. tag: "i am tag", // 标签
  43. luping: 0, // 是否开启视频课件优化处理,对于上传录屏类视频清晰度有所优化:0为不开启,1为开启
  44. keepsource: 1 // 是否源文件播放(不对视频进行编码):0为编码,1为不编码
  45. },
  46. diavos: false,
  47. listData: {} //数据
  48. };
  49. },
  50. methods: {
  51. diavosFun(item) {
  52. if (item.sectionType === 1) {
  53. this.vid = item.recordingUrl;
  54. }
  55. if (item.sectionType === 2) {
  56. this.vidzb = item.liveUrl;
  57. }
  58. this.listData = item;
  59. this.diavos = true;
  60. },
  61. isOkBf() {
  62. if (this.listData.sectionType === 1) {
  63. if(this.listData.viewSign == 2) {
  64. this.loadPlayerScript_tencent(this.loadPlayer_tencent);
  65. }else {
  66. this.loadPlayerScript(this.loadPlayer);
  67. }
  68. }
  69. if (this.listData.sectionType === 2) {
  70. this.loadPlayerScriptzb(this.loadPlayerzb);
  71. }
  72. },
  73. loadPlayerScript(callback) {
  74. if (!window.polyvPlayer) {
  75. const myScript = document.createElement("script");
  76. myScript.setAttribute("src", this.vodPlayerJs);
  77. myScript.onload = callback;
  78. document.body.appendChild(myScript);
  79. } else {
  80. callback();
  81. this.player.on("serverError", (...params) => {
  82. this.$message.error(returnTitle(params[1]));
  83. console.log(params);
  84. });
  85. }
  86. },
  87. loadPlayerScript_tencent(callback) {
  88. if (!window.TCPlayer) {
  89. const myScript = document.createElement("script");
  90. myScript.setAttribute("src", this.vodPlayerJsForTCPlayer);
  91. myScript.onload = callback;
  92. document.body.appendChild(myScript);
  93. } else {
  94. callback();
  95. this.player_tencent.on("server", (...params) => {
  96. this.$message.error(returnTitle(params[1]));
  97. console.log(params);
  98. });
  99. }
  100. },
  101. loadPlayer() {
  102. var self = this;
  103. const polyvPlayer = window.polyvPlayer;
  104. self.player = polyvPlayer({
  105. wrap: "#player",
  106. width: 800,
  107. height: 533,
  108. vid: self.vid,
  109. teaser_show: 0,
  110. playsafe: function(vid, next) {
  111. self.$api.obtainpolyvvideosign(vid).then(res => {
  112. next(res.data);
  113. });
  114. }
  115. });
  116. },
  117. loadPlayer_tencent() {
  118. var self = this;
  119. const TCPlayer = window.TCPlayer;
  120. try {
  121. let video = document.querySelector("video");
  122. video.parentNode.removeChild(video);
  123. } catch (error) {
  124. console.log("清除video标签异常");
  125. }
  126. let player_tencent = document.createElement("video");
  127. player_tencent.id = "player-tencent";
  128. document
  129. .getElementById("player")
  130. .insertAdjacentElement("afterend", player_tencent);
  131. self.$api.obtaintcvideosign(self.vid).then(res => {
  132. self.player_tencent = TCPlayer("player-tencent", {
  133. width: 800,
  134. height: 533,
  135. fileID: self.vid,
  136. appID: res.data.appID,
  137. psign: res.data.psign,
  138. licenseUrl: res.data.licenseUrl
  139. });
  140. });
  141. },
  142. /**
  143. * @param {String} 关闭视频窗口-销毁实例
  144. */
  145. clears() {
  146. this.diavos = false;
  147. if (this.listData.sectionType === 1 && this.player) {
  148. this.player.destroy();
  149. }
  150. if (this.listData.sectionType === 1 && this.player_tencent) {
  151. this.player_tencent.dispose();
  152. }
  153. if (this.listData.sectionType === 2 && this.playerzb) {
  154. this.playerzb.destroy();
  155. }
  156. this.listData = {};
  157. },
  158. loadPlayerScriptzb(callback) {
  159. if (!window.polyvLivePlayer) {
  160. const myScript = document.createElement("script");
  161. myScript.setAttribute("src", this.playerJs);
  162. myScript.onload = callback;
  163. document.body.appendChild(myScript);
  164. } else {
  165. callback();
  166. }
  167. },
  168. loadPlayerzb() {
  169. var self = this;
  170. const polyvLivePlayer = window.polyvLivePlayer;
  171. self.playerzb = polyvLivePlayer({
  172. wrap: "#playerzb",
  173. width: 800,
  174. height: 533,
  175. uid: self.uidzb,
  176. vid: self.vidzb
  177. });
  178. }
  179. }
  180. };
  181. </script>
  182. <style lang="less" scoped>
  183. /deep/.el-button {
  184. border-radius: 8px;
  185. }
  186. /deep/.el-dialog {
  187. border-radius: 8px;
  188. .el-dialog__header {
  189. padding: 0;
  190. .hearders {
  191. height: 40px;
  192. display: flex;
  193. align-items: center;
  194. justify-content: space-between;
  195. padding: 0px 18px 0px 20px;
  196. border-bottom: 1px solid #e2e2e2;
  197. .leftTitle {
  198. font-size: 14px;
  199. font-weight: bold;
  200. color: #2f4378;
  201. }
  202. .rightBoxs {
  203. display: flex;
  204. align-items: center;
  205. img {
  206. width: 14px;
  207. height: 14px;
  208. margin-left: 13px;
  209. cursor: pointer;
  210. }
  211. }
  212. }
  213. }
  214. .el-dialog__footer {
  215. padding: 0;
  216. .dialog-footer {
  217. padding: 0px 40px;
  218. height: 70px;
  219. border-top: 1px solid #e2e2e2;
  220. display: flex;
  221. align-items: center;
  222. justify-content: flex-end;
  223. }
  224. }
  225. }
  226. .imgBox {
  227. width: 100%;
  228. // height: 210px;
  229. border: 1px solid #e2e2e2;
  230. border-radius: 8px;
  231. padding: 8px 8px 3px;
  232. display: flex;
  233. flex-direction: column;
  234. align-items: center;
  235. .imgLabel {
  236. flex: 1;
  237. width: 100%;
  238. border: 1px dotted #e2e2e2;
  239. color: #999;
  240. font-size: 14px;
  241. cursor: pointer;
  242. border-radius: 8px;
  243. .msPhoto {
  244. display: flex;
  245. justify-content: center;
  246. align-items: center;
  247. max-width: 100%;
  248. max-height: 270px;
  249. img {
  250. max-width: 100%;
  251. max-height: 270px;
  252. }
  253. }
  254. .imgbbx {
  255. display: flex;
  256. flex-direction: column;
  257. align-items: center;
  258. justify-content: center;
  259. width: 100%;
  260. height: 100%;
  261. i {
  262. font-weight: bold;
  263. margin: 14px 0;
  264. font-size: 24px;
  265. }
  266. }
  267. }
  268. p {
  269. margin: 5px 0px;
  270. }
  271. }
  272. </style>