GBRecordDetail.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. <template>
  2. <div style="width: 100%">
  3. <div class="page-header">
  4. <div class="page-title">
  5. <el-page-header @back="goBack" :content="$t('menu.record')"></el-page-header>
  6. </div>
  7. </div>
  8. <el-container>
  9. <el-aside width="300px">
  10. <div class="record-list-box-box">
  11. <!-- -->
  12. <el-date-picker size="mini" v-model="chooseDate" type="date" value-format="yyyy-MM-dd" :placeholder="$t('date')"
  13. @change="dateChange()"></el-date-picker>
  14. <!-- 格式选择 与日期选择框样式对其-->
  15. <el-select style="width: 220px" v-model="filterExt" size="mini" @change="filterExtChangeHandle" :placeholder="$t('filter')">
  16. <el-option
  17. v-for="item in extList"
  18. :key="item.value"
  19. :label="item.label"
  20. :value="item.value"
  21. >
  22. </el-option>
  23. </el-select>
  24. <div class="record-list-box" v-loading="recordsLoading" :style="recordListStyle">
  25. <ul v-if="detailFiles.length >0" class="infinite-list record-list">
  26. <li v-for="item in detailFiles" class="infinite-list-item record-list-item">
  27. <el-tag @click="checkedFile(item)" :type="chooseFile == item?'danger':''">
  28. <i class="el-icon-video-camera"></i>
  29. <span class="icon" :class="'icon-'+item.extName">{{item.extName}}</span>
  30. {{ moment(item.startTime).format('HH:mm:ss') }}-{{ moment(item.endTime).format('HH:mm:ss') }}
  31. </el-tag>
  32. <i style="color: #409EFF;margin-left: 5px;" class="el-icon-download" @click="downloadRecord(item)"></i>
  33. </li>
  34. </ul>
  35. </div>
  36. <div size="mini" v-if="detailFiles.length ==0" class="record-list-no-val">{{ $t('noData') }}</div>
  37. </div>
  38. </el-aside>
  39. <el-main style="padding-bottom: 10px;">
  40. <div class="playBox" :style="playerStyle">
  41. <player ref="recordVideoPlayer"
  42. :videoUrl="videoUrl"
  43. :error="videoError"
  44. :message="videoError"
  45. :hasAudio="hasAudio"
  46. style="max-height: 100%"
  47. v-if="activePlayer === 'jessibuca'"
  48. fluent autoplay live></player>
  49. <rtc-player
  50. v-if="activePlayer === 'webrtc'"
  51. ref="webrtc"
  52. @eventCallback="webrtcPlayEventHandle"
  53. :videoUrl="videoUrl"
  54. :error="videoError"
  55. :message="videoError"
  56. :hasAudio="hasAudio"
  57. />
  58. </div>
  59. <div class="player-option-box">
  60. <div>
  61. <el-radio-group
  62. v-model="activePlayer"
  63. size="medium"
  64. @input="playerChangeHandle"
  65. >
  66. <el-radio-button
  67. v-for="(item,i) in playerList"
  68. :key="item.key + i"
  69. :label="$t(`video.play.${item.key}.title`)">
  70. {{ $t(`video.play.${item.key}.title`) }}
  71. </el-radio-button>
  72. </el-radio-group>
  73. <el-button-group>
  74. <el-time-picker
  75. size="mini"
  76. is-range
  77. align="left"
  78. v-model="timeRange"
  79. value-format="yyyy-MM-dd HH:mm:ss"
  80. range-separator="-"
  81. :start-placeholder="$t('video.startTime')"
  82. :end-placeholder="$t('video.endTime')"
  83. @change="timePickerChange"
  84. :placeholder="$t('video.timeRange')">
  85. </el-time-picker>
  86. </el-button-group>
  87. <el-button-group>
  88. <el-button size="mini" class="iconfont icon-zanting"
  89. :title="$t('play')"
  90. @click="gbPause()"></el-button>
  91. <el-button size="mini" class="iconfont icon-kaishi"
  92. :title="$t('pause')"
  93. @click="gbPlay()"></el-button>
  94. <el-dropdown size="mini" :title="$t('playMultiples')" @command="gbScale">
  95. <el-button size="mini">
  96. {{ $t('playMultiples') }} <i class="el-icon-arrow-down el-icon--right"></i>
  97. </el-button>
  98. <el-dropdown-menu slot="dropdown">
  99. <el-dropdown-item command="0.25">0.25</el-dropdown-item>
  100. <el-dropdown-item command="0.5">0.5</el-dropdown-item>
  101. <el-dropdown-item command="1.0">1</el-dropdown-item>
  102. <el-dropdown-item command="2.0">2</el-dropdown-item>
  103. <el-dropdown-item command="4.0">4</el-dropdown-item>
  104. </el-dropdown-menu>
  105. </el-dropdown>
  106. <el-button size="mini" class="iconfont icon-xiazai1" :title="$t('download')"
  107. @click="downloadRecord()"></el-button>
  108. </el-button-group>
  109. </div>
  110. <el-slider
  111. class="playtime-slider"
  112. v-model="playTime"
  113. id="playtimeSlider"
  114. :disabled="detailFiles.length === 0"
  115. :min="sliderMIn"
  116. :max="sliderMax"
  117. :range="true"
  118. :format-tooltip="playTimeFormat"
  119. @change="playTimeChange"
  120. :marks="playTimeSliderMarks">
  121. </el-slider>
  122. <div class="slider-val-box">
  123. <div class="slider-val" v-for="item of detailFiles"
  124. :style="'width:' + getDataWidth(item) + '%; left:' + getDataLeft(item) + '%'"></div>
  125. </div>
  126. </div>
  127. </el-main>
  128. </el-container>
  129. <recordDownload ref="recordDownload"></recordDownload>
  130. </div>
  131. </template>
  132. <script>
  133. import uiHeader from '../layout/UiHeader.vue'
  134. import player from './common/jessibuca.vue'
  135. import moment from 'moment'
  136. import recordDownload from './dialog/recordDownload.vue'
  137. import handle from "@/until/handle";
  138. import RtcPlayer from "@components/dialog/rtcPlayer.vue";
  139. import mpegTsVideo from "@components/common/mpegtsVideo.vue";
  140. import h265WebJessibuca from "@components/common/h265webJessibuca.vue";
  141. import H265WebJs from "@components/common/h265webJs.vue";
  142. import {webrtcEvent} from "@/map/eventMap";
  143. import {strFill} from "@/until/str";
  144. import {checkWebrtcHevcSupport} from "../until/browser";
  145. const playList = [
  146. {
  147. key: "webrtc",
  148. text: "webrtc 播放器",
  149. description: "延迟较低的播放器,需要浏览器支持",
  150. support: checkWebrtcHevcSupport()? ['h264', 'h265'] : ['h264'],
  151. audioSupport: ['opus', 'pcma', 'pcmu'],
  152. disable: false
  153. },
  154. {
  155. key: "jessibuca",
  156. text: "265 jessibuca播放器",
  157. description: "用于播放265格式视频",
  158. support: ['h264', 'h265'],
  159. audioSupport: ['aac'],
  160. disable: false
  161. },
  162. ];
  163. const playerProtocol = {
  164. webrtc: ["rtc", "rtcs"],
  165. jessibuca: ["ws_flv", "wss_flv"],
  166. };
  167. let playTimeSliderMarks = {};
  168. for (let i = 0 ; i < 24 ; i++)
  169. {
  170. playTimeSliderMarks[i * 3600] = `${strFill(i, 2)}:00`;
  171. }
  172. export default {
  173. name: 'app',
  174. components: {
  175. H265WebJs, h265WebJessibuca, mpegTsVideo,
  176. RtcPlayer,
  177. uiHeader, player, recordDownload
  178. },
  179. data() {
  180. return {
  181. activePlayer: '',
  182. playerList: playList,
  183. fps: 15,
  184. deviceId: this.$route.params.deviceId,
  185. channelId: this.$route.params.channelId,
  186. recordsLoading: false,
  187. streamId: "",
  188. hasAudio: true,
  189. allDetailFiles: [],
  190. // detailFiles: [],
  191. chooseDate: null,
  192. videoUrl: null,
  193. chooseFile: null,
  194. streamInfo: null,
  195. app: null,
  196. mediaServerId: null,
  197. ssrc: null,
  198. sliderMIn: 0,
  199. sliderMax: 86400,
  200. autoPlay: true,
  201. taskUpdate: null,
  202. tabVal: "running",
  203. recordListStyle: {
  204. height: this.winHeight + "px",
  205. overflow: "auto",
  206. margin: "10px auto 10px auto"
  207. },
  208. playerStyle: {
  209. "margin": "0 auto 20px auto",
  210. "height": this.winHeight + "px",
  211. },
  212. winHeight: window.innerHeight - 240,
  213. playTime: null,
  214. timeRange: null,
  215. startTime: null,
  216. endTime: null,
  217. playTimeSliderMarks: playTimeSliderMarks,
  218. extList: [],
  219. filterExt: null,
  220. };
  221. },
  222. computed: {
  223. detailFiles() {
  224. let ext = this.filterExt;
  225. if(!ext){
  226. return this.allDetailFiles;
  227. }
  228. if(ext === 'all') {
  229. return this.allDetailFiles;
  230. }
  231. return this.allDetailFiles.filter((item) => {
  232. return item.extName === ext;
  233. })
  234. }
  235. },
  236. mounted() {
  237. this.recordListStyle.height = this.winHeight + "px";
  238. this.playerStyle["height"] = this.winHeight + "px";
  239. this.chooseDate = moment().format('YYYY-MM-DD')
  240. this.dateChange();
  241. if(!this.activePlayer){
  242. this.activePlayer = this.playerList[0].key;
  243. }
  244. },
  245. beforeDestroy() {
  246. console.log('准备销毁页面')
  247. this.stopPlayRecord();
  248. this.stopDownloadRecord();
  249. },
  250. destroyed() {
  251. this.$destroy('recordVideoPlayer');
  252. },
  253. methods: {
  254. async dateChange() {
  255. let err, res;
  256. let recordList = [];
  257. if (!this.chooseDate) {
  258. return;
  259. }
  260. this.setTime(this.chooseDate + " 00:00:00", this.chooseDate + " 23:59:59");
  261. this.recordsLoading = true;
  262. // this.detailFiles = [];
  263. let url = '/api/gb_record/query/'
  264. url += `${this.deviceId}/${this.channelId}`;
  265. url += `?startTime=${this.startTime}`;
  266. url += `&endTime=${this.endTime}`;
  267. [err, res] = await handle(this.$axios.axios({
  268. method: 'get',
  269. url: url
  270. }))
  271. this.recordsLoading = false;
  272. if (err) {
  273. this.$message({
  274. showClose: true,
  275. message: err.message,
  276. type: "error",
  277. });
  278. return;
  279. }
  280. if (res.data.code !== 0) {
  281. this.$message({
  282. showClose: true,
  283. message: res.data.msg,
  284. type: "error",
  285. });
  286. }
  287. // 创建一个set集合
  288. let extSet = new Set();
  289. recordList = res.data.data.recordList;
  290. // 遍历获取文件后缀名
  291. recordList.forEach((item) => {
  292. // item.name = item.fileName;
  293. item.extName = this.getExtName(item.name);
  294. extSet.add(item.extName);
  295. })
  296. this.allDetailFiles = recordList;
  297. // 将set集合转换为数组
  298. this.extList = Array.from(extSet).map((item) => {
  299. return {
  300. label: item,
  301. value: item
  302. }
  303. });
  304. // 首位添加 所有格式
  305. this.extList.unshift({
  306. label: "all",
  307. value: "all"
  308. });
  309. this.filterExt = "all";
  310. console.log(this.detailFiles);
  311. },
  312. getExtName(fileName){
  313. let tmpSplit = fileName.split(".");
  314. let extName = tmpSplit[tmpSplit.length - 1];
  315. return extName;
  316. },
  317. moment: function (v) {
  318. return moment(v)
  319. },
  320. setTime: function (startTime, endTime) {
  321. this.startTime = startTime;
  322. this.endTime = endTime;
  323. let start = (new Date(this.startTime).getTime() - new Date(this.chooseDate + " 00:00:00").getTime()) / 1000;
  324. let end = (new Date(this.endTime).getTime() - new Date(this.chooseDate + " 00:00:00").getTime()) / 1000;
  325. console.log(start)
  326. console.log(end)
  327. this.playTime = [start, end];
  328. this.timeRange = [startTime, endTime];
  329. },
  330. videoError: function (e) {
  331. console.log("播放器错误:" + JSON.stringify(e));
  332. },
  333. checkedFile(file) {
  334. this.chooseFile = file;
  335. this.setTime(file.startTime, file.endTime);
  336. // 开始回放
  337. this.playRecord()
  338. },
  339. playRecord: function () {
  340. if (this.streamId !== "") {
  341. this.stopPlayRecord(() => {
  342. this.streamId = "";
  343. this.playRecord();
  344. })
  345. } else {
  346. this.$axios.axios({
  347. method: 'get',
  348. url: '/api/playback/start/' + this.deviceId + '/' + this.channelId + '?startTime=' + this.startTime + '&endTime=' +
  349. this.endTime
  350. }).then(async (res) => {
  351. if (res.data.code === 0) {
  352. this.streamInfo = res.data.data;
  353. await this.queryMediaInfo(true);
  354. console.log(`streamInfo`);
  355. console.log(this.streamInfo);
  356. this.app = this.streamInfo.app;
  357. this.streamId = this.streamInfo.stream;
  358. this.mediaServerId = this.streamInfo.mediaServerId;
  359. this.ssrc = this.streamInfo.ssrc;
  360. // 根据tracks 选择播放器
  361. this.videoUrl = this.getUrlByStreamInfo(this.streamInfo);
  362. } else {
  363. this.$message({
  364. showClose: true,
  365. message: res.data.msg,
  366. type: "error",
  367. });
  368. }
  369. });
  370. }
  371. },
  372. gbPlay() {
  373. console.log('前端控制:播放');
  374. this.$axios.axios({
  375. method: 'get',
  376. url: '/api/playback/resume/' + this.streamId
  377. }).then((res) => {
  378. this.$refs["recordVideoPlayer"].play(this.videoUrl)
  379. });
  380. },
  381. gbPause() {
  382. console.log('前端控制:暂停');
  383. this.$axios.axios({
  384. method: 'get',
  385. url: '/api/playback/pause/' + this.streamId
  386. }).then(function (res) {
  387. });
  388. },
  389. gbScale(command) {
  390. console.log('前端控制:倍速 ' + command);
  391. this.$axios.axios({
  392. method: 'get',
  393. url: `/api/playback/speed/${this.streamId}/${command}`
  394. }).then(function (res) {
  395. });
  396. },
  397. downloadRecord: function (row) {
  398. if (!row) {
  399. let startTimeStr = moment(new Date(this.chooseDate + " 00:00:00").getTime() + this.playTime[0] * 1000).format("YYYY-MM-DD HH:mm:ss");
  400. let endTimeStr = moment(new Date(this.chooseDate + " 00:00:00").getTime() + this.playTime[1] * 1000).format("YYYY-MM-DD HH:mm:ss");
  401. console.log(startTimeStr);
  402. console.log(endTimeStr);
  403. row = {
  404. startTime: startTimeStr,
  405. endTime: endTimeStr
  406. }
  407. }
  408. if (this.streamId !== "") {
  409. this.stopPlayRecord(() => {
  410. this.streamId = "";
  411. this.downloadRecord(row);
  412. })
  413. } else {
  414. this.$axios.axios({
  415. method: 'get',
  416. url: '/api/gb_record/download/start/' + this.deviceId + '/' + this.channelId + '?startTime=' + row.startTime + '&endTime=' +
  417. row.endTime + '&downloadSpeed=4'
  418. }).then((res) => {
  419. if (res.data.code === 0) {
  420. let streamInfo = res.data.data;
  421. this.$refs.recordDownload.openDialog(this.deviceId, this.channelId, streamInfo.app, streamInfo.stream, streamInfo.mediaServerId);
  422. } else {
  423. this.$message({
  424. showClose: true,
  425. message: res.data.msg,
  426. type: "error",
  427. });
  428. }
  429. });
  430. }
  431. },
  432. stopDownloadRecord: function (callback) {
  433. this.$refs["recordVideoPlayer"].pause();
  434. this.videoUrl = '';
  435. this.$axios.axios({
  436. method: 'get',
  437. url: '/api/gb_record/download/stop/' + this.deviceId + "/" + this.channelId + "/" + this.streamId
  438. }).then((res) => {
  439. if (callback) callback(res)
  440. });
  441. },
  442. stopPlayRecord: function (callback) {
  443. this.$refs["recordVideoPlayer"].pause();
  444. this.videoUrl = '';
  445. this.$axios.axios({
  446. method: 'get',
  447. url: '/api/playback/stop/' + this.deviceId + "/" + this.channelId + "/" + this.streamId
  448. }).then(function (res) {
  449. if (callback) callback()
  450. });
  451. },
  452. getDataWidth(item) {
  453. let timeForFile = this.getTimeForFile(item);
  454. let result = (timeForFile[2]) / ((this.sliderMax - this.sliderMIn) * 1000)
  455. return result * 100
  456. },
  457. getDataLeft(item) {
  458. let timeForFile = this.getTimeForFile(item);
  459. let differenceTime = timeForFile[0].getTime() - new Date(this.chooseDate + " 00:00:00").getTime()
  460. return parseFloat((differenceTime - this.sliderMIn * 1000) / ((this.sliderMax - this.sliderMIn) * 1000)) * 100;
  461. },
  462. getUrlByStreamInfo(streamInfo) {
  463. if (this.enableDebug) {
  464. console.log("获取基础拉流地址");
  465. console.log(streamInfo);
  466. }
  467. if (!streamInfo) {
  468. return '';
  469. }
  470. if(!this.activePlayer){
  471. this.activePlayer = this.playerList[0].key;
  472. }
  473. let playerData = playerProtocol[this.activePlayer];
  474. if (location.protocol === "https:") {
  475. this.videoUrl = streamInfo[playerData[1]]
  476. } else {
  477. this.videoUrl = streamInfo[playerData[0]]
  478. }
  479. if (this.enableDebug) {
  480. console.log(`播放url: ${this.videoUrl}`);
  481. }
  482. console.log(`播放url: ${this.videoUrl}`);
  483. console.log(this.videoUrl)
  484. return this.videoUrl;
  485. },
  486. timePickerChange: function (val) {
  487. this.setTime(val[0], val[1])
  488. },
  489. playTimeChange(val) {
  490. console.log(val)
  491. let startTimeStr = moment(new Date(this.chooseDate + " 00:00:00").getTime() + val[0] * 1000).format("YYYY-MM-DD HH:mm:ss");
  492. let endTimeStr = moment(new Date(this.chooseDate + " 00:00:00").getTime() + val[1] * 1000).format("YYYY-MM-DD HH:mm:ss");
  493. this.setTime(startTimeStr, endTimeStr)
  494. this.playRecord();
  495. },
  496. setSliderFit() {
  497. if (this.sliderMIn === 0 && this.sliderMax === 86400) {
  498. if (this.detailFiles.length > 0) {
  499. let timeForFile = this.getTimeForFile(this.detailFiles[0]);
  500. let lastTimeForFile = this.getTimeForFile(this.detailFiles[this.detailFiles.length - 1]);
  501. let timeNum = timeForFile[0].getTime() - new Date(this.chooseDate + " " + "00:00:00").getTime()
  502. let lastTimeNum = lastTimeForFile[1].getTime() - new Date(this.chooseDate + " " + "00:00:00").getTime()
  503. this.playTime = parseInt(timeNum / 1000)
  504. this.sliderMIn = parseInt(timeNum / 1000 - timeNum / 1000 % (60 * 60))
  505. this.sliderMax = parseInt(lastTimeNum / 1000 - lastTimeNum / 1000 % (60 * 60)) + 60 * 60
  506. this.playTime = [this.sliderMIn, this.sliderMax];
  507. }
  508. } else {
  509. this.sliderMIn = 0;
  510. this.sliderMax = 86400;
  511. }
  512. },
  513. getTimeForFile(file) {
  514. let startTime = new Date(file.startTime);
  515. let endTime = new Date(file.endTime);
  516. return [startTime, endTime, endTime.getTime() - startTime.getTime()];
  517. },
  518. playTimeFormat(val) {
  519. let h = parseInt(val / 3600);
  520. let m = parseInt((val - h * 3600) / 60);
  521. let s = parseInt(val - h * 3600 - m * 60);
  522. let hStr = h;
  523. let mStr = m;
  524. let sStr = s;
  525. if (h < 10) {
  526. hStr = "0" + hStr;
  527. }
  528. if (m < 10) {
  529. mStr = "0" + mStr;
  530. s
  531. }
  532. if (s < 10) {
  533. sStr = "0" + sStr;
  534. }
  535. return hStr + ":" + mStr + ":" + sStr
  536. },
  537. goBack() {
  538. window.history.go(-1);
  539. },
  540. filterExtChangeHandle(){
  541. let ext = this.filterExt;
  542. if(!ext){
  543. return
  544. }
  545. if(ext === 'all') {
  546. this.detailFiles = this.detailFiles;
  547. }
  548. },
  549. findPlayer(videoType, audioType)
  550. {
  551. // 先尝试寻找到所有支持对应协议的播放器
  552. let arr = this.playerList.filter(item => {
  553. return item.support.includes(videoType)
  554. })
  555. console.log(arr);
  556. console.log(arr);
  557. console.log(arr);
  558. console.log(arr);
  559. // 从中找到同时支持
  560. let res_player = arr.find(item => {
  561. // 判断播放器是否同时支持 视频与音频
  562. return item.audioSupport.includes(audioType);
  563. })
  564. if (!res_player)
  565. {
  566. res_player = arr[0]
  567. }
  568. return res_player;
  569. },
  570. async queryMediaInfo(isFirst) {
  571. let info = this.streamInfo
  572. let url = `/zlm/${info.mediaServerId}/index/api/getMediaInfo`
  573. url += `?vhost=__defaultVhost__`
  574. url += `&schema=rtsp`
  575. url += `&app=${info.app}`
  576. url += `&stream=${info.stream}`
  577. url += this.shareCode ? `&shareCode=${this.shareCode}` : ''
  578. let [err, res] = await handle(this.$axios.axios({
  579. method: 'get',
  580. url: url
  581. }));
  582. if (err) {
  583. console.error(err);
  584. this.$message.warning("流媒体信息获取失败")
  585. return;
  586. }
  587. console.log(res);
  588. if (res.data.code !== 0) {
  589. this.tracksNotLoaded = true;
  590. this.$message({
  591. showClose: true,
  592. message: '获取编码信息失败,',
  593. type: 'warning'
  594. });
  595. return;
  596. }
  597. if (res.data.tracks) {
  598. this.tracks = res.data.tracks;
  599. if (this.tracks) {
  600. console.log(`---------tracks----------`)
  601. // 根据我们摄像头默认fps值来进行配置播放器
  602. let fps = 15;
  603. let isH265 = false;
  604. let isPCMAudio = false;
  605. for (const tracksElement of this.tracks) {
  606. console.log(tracksElement);
  607. if (tracksElement.fps) {
  608. fps = tracksElement.fps;
  609. }
  610. console.log(`${tracksElement.codec_id_name}:code ${tracksElement.codec_id_name ? 'is h265' : 'not h265'}`)
  611. if (tracksElement.codec_id_name && tracksElement.codec_id_name.includes("265")) {
  612. isH265 = true;
  613. }
  614. if (tracksElement.codec_id_name && tracksElement.codec_id_name.includes("PCM"))
  615. {
  616. isPCMAudio = true;
  617. // console.log("audio")
  618. }
  619. }
  620. this.fps = fps;
  621. if (isFirst) {
  622. // g711 264
  623. // g711 265
  624. let _Player = this.findPlayer(isH265?'h265':'h264',
  625. isPCMAudio?'pcma':'aac');
  626. if (_Player) {
  627. console.log(`切换为${_Player.key}播放器`);
  628. this.activePlayer = _Player.key;
  629. } else {
  630. console.log("使用默认播放器");
  631. this.activePlayer = playList[0].key;
  632. }
  633. }
  634. }
  635. } else {
  636. console.log('没有编码信息');
  637. }
  638. },
  639. playerChangeHandle() {
  640. console.log('切换播放器');
  641. this.$nextTick(() => {
  642. // todo 切换url
  643. this.videoUrl = this.getUrlByStreamInfo(this.streamInfo);
  644. })
  645. },
  646. webrtcPlayEventHandle(type, e) {
  647. // 添加同类型防抖
  648. if (this.enableDebug) {
  649. console.log('playEventHandle');
  650. console.log(type, e);
  651. }
  652. if (this.playEventHandleTimer) {
  653. clearTimeout(this.playEventHandleTimer);
  654. }
  655. this.playEventHandleTimer = setTimeout(() => {
  656. this.webrtcEventExecute(type, e);
  657. }, 300);
  658. },
  659. webrtcEventExecute(type, e) {
  660. // 防抖,防止多次触发
  661. if (type === webrtcEvent.apiFail.code) {
  662. this.$notify.error({
  663. title: this.$t('notification.noStreamInfo'),
  664. dangerouslyUseHTMLString: true,
  665. message: this.$t('notification.zlmFailMsg', {msg: e.message, url: this.videoUrl}),
  666. duration: 0
  667. });
  668. this.videoError = true;
  669. this.videoUrl = '';
  670. } else if (type === webrtcEvent.played.code) {
  671. this.$message.success(this.$t('notification.playSuccess'));
  672. } else if (type === webrtcEvent.sdpFail.code) {
  673. console.log(e);
  674. this.$notify.error({
  675. title: this.$t('notification.sdpFail'),
  676. duration: 14500
  677. })
  678. }
  679. },
  680. }
  681. };
  682. </script>
  683. <style scoped>
  684. .icon{
  685. font-size: 12px;
  686. margin-right: 5px;
  687. }
  688. .icon-mp4{
  689. color: #25cb8e;
  690. }
  691. .icon-h265{
  692. color: #ef7b05;
  693. }
  694. .icon-h264{
  695. color: #407300;
  696. }
  697. </style>
  698. <style>
  699. .el-slider__runway {
  700. background-color: rgba(206, 206, 206, 0.47) !important;
  701. }
  702. .el-slider__bar {
  703. background-color: rgba(153, 153, 153, 0) !important;
  704. }
  705. .playtime-slider {
  706. position: relative;
  707. z-index: 100;
  708. }
  709. .data-picker-true {
  710. }
  711. .data-picker-true:after {
  712. content: "";
  713. position: absolute;
  714. width: 4px;
  715. height: 4px;
  716. background-color: #606060;
  717. border-radius: 4px;
  718. left: 45%;
  719. top: 74%;
  720. }
  721. .data-picker-false {
  722. }
  723. .slider-val-box {
  724. height: 6px;
  725. position: relative;
  726. top: -22px;
  727. }
  728. .slider-val {
  729. height: 6px;
  730. background-color: #007CFF;
  731. position: absolute;
  732. }
  733. .record-list-box-box {
  734. width: 250px;
  735. float: left;
  736. }
  737. .record-list-box {
  738. overflow: auto;
  739. width: 220px;
  740. list-style: none;
  741. padding: 0;
  742. margin: 0;
  743. margin-top: 0px;
  744. padding: 1rem 0;
  745. background-color: #FFF;
  746. margin-top: 10px;
  747. }
  748. .record-list {
  749. list-style: none;
  750. padding: 0;
  751. margin: 0;
  752. background-color: #FFF;
  753. }
  754. .record-list-no-val {
  755. position: absolute;
  756. color: #9f9f9f;
  757. top: 50%;
  758. left: 110px;
  759. }
  760. .record-list-item {
  761. padding: 0;
  762. margin: 0;
  763. margin: 0.5rem 0;
  764. cursor: pointer;
  765. }
  766. .record-list-option {
  767. width: 10px;
  768. float: left;
  769. margin-top: 39px;
  770. }
  771. .player-option-box {
  772. padding: 0 20px;
  773. }
  774. </style>