devicePlayer.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <div id="devicePlayer">
  3. <el-dialog title="视频播放" top="0" :visible.sync="showVideoDialog" :destroy-on-close="true" @close="stop()">
  4. <LivePlayer v-if="showVideoDialog" ref="videoPlayer" :videoUrl="videoUrl" :error="videoError" :hasaudio="hasaudio" fluent autoplay live ></LivePlayer>
  5. <div id="shared" style="text-align: right; margin-top: 1rem;">
  6. <el-tabs v-model="tabActiveName">
  7. <el-tab-pane label="媒体流信息" name="media">
  8. <div style="margin-bottom: 0.5rem;">
  9. <el-button type="primary" size="small" @click="playRecord(true, '')">播放</el-button>
  10. <el-button type="primary" size="small" @click="startRecord()">录制</el-button>
  11. <el-button type="primary" size="small" @click="stopRecord()">停止录制</el-button>
  12. </div>
  13. <div style="display: flex; margin-bottom: 0.5rem; height: 2.5rem;">
  14. <span style="width: 5rem; line-height: 2.5rem; text-align: right;">播放地址:</span>
  15. <el-input v-model="getPlayerShared.sharedUrl" :disabled="true" v-on:click.native="copySharedInfo(getPlayerShared.sharedUrl)"></el-input>
  16. </div>
  17. <div style="display: flex; margin-bottom: 0.5rem; height: 2.5rem;">
  18. <span style="width: 5rem; line-height: 2.5rem; text-align: right;">iframe:</span>
  19. <el-input v-model="getPlayerShared.sharedIframe" :disabled="true" v-on:click.native="copySharedInfo(getPlayerShared.sharedIframe)"></el-input>
  20. </div>
  21. <div style="display: flex; margin-bottom: 0.5rem; height: 2.5rem;">
  22. <span style="width: 5rem; line-height: 2.5rem; text-align: right;">资源地址:</span>
  23. <el-input v-model="getPlayerShared.sharedRtmp" :disabled="true" v-on:click.native="copySharedInfo(getPlayerShared.sharedRtmp)"></el-input>
  24. </div>
  25. </el-tab-pane>
  26. <!--{"code":0,"data":{"paths":["22-29-30.mp4"],"rootPath":"/home/kkkkk/Documents/ZLMediaKit/release/linux/Debug/www/record/hls/kkkkk/2020-05-11/"}}-->
  27. <el-tab-pane label="录像查询" name="second">
  28. <el-date-picker v-model="videoHistory.startTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="开始时间"
  29. @change="recordList()"></el-date-picker>
  30. <el-date-picker v-model="videoHistory.endTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="结束时间"
  31. @change="recordList()"></el-date-picker>
  32. <el-table :data="videoHistory.searchHistoryResult" style="width: 100%">
  33. <el-table-column label="名称" prop="name" width="150"></el-table-column>
  34. <el-table-column label="文件" prop="filePath" width="300"></el-table-column>
  35. <el-table-column label="开始时间" prop="startTime" width="160"></el-table-column>
  36. <el-table-column label="结束时间" prop="endTime" width="160"></el-table-column>
  37. <el-table-column label="操作">
  38. <template slot-scope="scope">
  39. <el-button type="primary" size="mini" @click="playRecord(false, scope.row)">播放</el-button>
  40. </template>
  41. </el-table-column>
  42. </el-table>
  43. </el-tab-pane>
  44. <!--遥控界面-->
  45. <el-tab-pane label="云台控制" name="third">
  46. <div style="display: flex; justify-content: center;">
  47. <div class="control-wrapper">
  48. <div class="control-btn control-top" @mousedown="ptzCamera(0, 1, 0)" @mouseup="ptzCamera(0, 0, 0)">
  49. <i class="el-icon-caret-top"></i>
  50. <div class="control-inner-btn control-inner"></div>
  51. </div>
  52. <div class="control-btn control-left" @mousedown="ptzCamera(1, 0, 0)" @mouseup="ptzCamera(0, 0, 0)">
  53. <i class="el-icon-caret-left"></i>
  54. <div class="control-inner-btn control-inner"></div>
  55. </div>
  56. <div class="control-btn control-bottom" @mousedown="ptzCamera(0, 2, 0)" @mouseup="ptzCamera(0, 0, 0)">
  57. <i class="el-icon-caret-bottom"></i>
  58. <div class="control-inner-btn control-inner"></div>
  59. </div>
  60. <div class="control-btn control-right" @mousedown="ptzCamera(2, 0, 0)" @mouseup="ptzCamera(0, 0, 0)">
  61. <i class="el-icon-caret-right"></i>
  62. <div class="control-inner-btn control-inner"></div>
  63. </div>
  64. <div class="control-round">
  65. <div class="control-round-inner"><i class="fa fa-pause-circle"></i></div>
  66. </div>
  67. <div style="position: absolute; left: 7.25rem; top: 1.25rem" @mousedown="ptzCamera(0, 0, 2)" @mouseup="ptzCamera(0, 0, 0)"><i
  68. class="el-icon-zoom-in" style="font-size: 1.875rem;"></i></div>
  69. <div style="position: absolute; left: 7.25rem; top: 3.25rem; font-size: 1.875rem;" @mousedown="ptzCamera(0, 0, 1)"
  70. @mouseup="ptzCamera(0, 0, 0)"><i class="el-icon-zoom-out"></i></div>
  71. </div>
  72. </div>
  73. </el-tab-pane>
  74. </el-tabs>
  75. </div>
  76. </el-dialog>
  77. </div>
  78. </template>
  79. <script>
  80. import LivePlayer from '@liveqing/liveplayer'
  81. export default {
  82. name: 'devicePlayer',
  83. props: {},
  84. components: {
  85. LivePlayer
  86. },
  87. computed: {
  88. getPlayerShared: function() {
  89. return {
  90. sharedUrl: window.location.host + '/' + this.videoUrl,
  91. sharedIframe: '<iframe src="' + window.location.host + '/' + this.videoUrl + '"></iframe>',
  92. sharedRtmp: this.videoUrl
  93. };
  94. }
  95. },
  96. created() {
  97. // this.videoHistory.searchHistoryResult = falsificationData.recordData.recordList;
  98. },
  99. data() {
  100. return {
  101. video:'http://lndxyj.iqilu.com/public/upload/2019/10/14/8c001ea0c09cdc59a57829dabc8010fa.mp4',
  102. videoUrl: '',
  103. videoHistory: {
  104. startTime: '',
  105. endTime: '',
  106. searchHistoryResult: [] //媒体流历史记录搜索结果
  107. },
  108. showVideoDialog: false,
  109. normalssrc: '',
  110. ssrc: '',
  111. deviceId: '',
  112. channelId: '',
  113. tabActiveName: 'media',
  114. hasaudio: false
  115. };
  116. },
  117. methods: {
  118. play: function(streamInfo, deviceId, channelId, hasAudio) {
  119. console.log(hasAudio);
  120. this.hasaudio = hasAudio;
  121. // 根据媒体流信息二次判断
  122. if( this.hasaudio && !!streamInfo.tracks && streamInfo.tracks.length > 0) {
  123. var realHasAudio = false;
  124. for (let i = 0; i < streamInfo.tracks; i++) {
  125. if (streamInfo.tracks[i].codec_type == 1) { // 判断为音频
  126. realHasAudio = true;
  127. }
  128. }
  129. this.hasaudio = realHasAudio && this.hasaudio;
  130. }
  131. console.log("111")
  132. console.log(this.hasaudio)
  133. this.ssrc = streamInfo.ssrc;
  134. this.deviceId = deviceId;
  135. this.channelId = channelId;
  136. // this.$refs.videoPlayer.hasaudio = hasAudio;
  137. // this.videoUrl = streamInfo.flv + "?" + new Date().getTime();
  138. this.videoUrl = streamInfo.ws_flv;
  139. this.showVideoDialog = true;
  140. console.log(this.ssrc);
  141. },
  142. stop: function() {
  143. console.log('关闭视频');
  144. this.$refs.videoPlayer.pause();
  145. this.videoUrl = '';
  146. this.showVideoDialog = false;
  147. this.$axios({
  148. method: 'post',
  149. url: '/api/play/' + this.ssrc + '/stop'
  150. }).then(function(res) {
  151. console.log(JSON.stringify(res));
  152. });
  153. this.$axios({
  154. method: 'post',
  155. url: '/api/playback/' + this.ssrc + '/stop'
  156. }).then(function(res) {
  157. console.log(JSON.stringify(res));
  158. });
  159. },
  160. copySharedInfo: function(data) {
  161. console.log('复制内容:' + data);
  162. let _this = this;
  163. this.$copyText(data).then(
  164. function(e) {
  165. _this.$message({
  166. showClose: true,
  167. message: '复制成功',
  168. type: 'success'
  169. });
  170. },
  171. function(e) {
  172. _this.$message({
  173. showClose: true,
  174. message: '复制失败,请手动复制',
  175. type: 'error'
  176. });
  177. }
  178. );
  179. },
  180. recordList: function() {
  181. if (!this.videoHistory.startTime || !this.videoHistory.endTime) {
  182. return;
  183. }
  184. let that = this;
  185. this.$axios({
  186. method: 'get',
  187. url: '/api/record/' + this.deviceId + '/' + this.channelId + '?startTime=' + this.videoHistory
  188. .startTime + '&endTime=' + this.videoHistory.endTime
  189. }).then(function(res) {
  190. console.log(JSON.stringify(res));
  191. }).catch(function(e) {
  192. // that.videoHistory.searchHistoryResult = falsificationData.recordData;
  193. });
  194. },
  195. playRecord: function(isBackLive, rowData) {
  196. let that = this;
  197. if(isBackLive){
  198. this.videoUrl=this.getVideoUrlBySsrc(this.normalssrc);
  199. return;
  200. }
  201. this.$axios({
  202. method: 'get',
  203. url: '/api/playback/' + this.deviceId + '/' + this.channelId + '?startTime=' + rowData.startTime + '&endTime=' +
  204. rowData.endTime
  205. }).then(function(res) {
  206. let ssrc = res.data.ssrc;
  207. that.videoUrl = that.getVideoUrlBySsrc(ssrc);
  208. //that.videoUrl='http://hls.cntv.kcdnvip.com/asp/hls/main/0303000a/3/default/f466089412c04a759c5515dbfcc3ac3d/main.m3u8?maxbr=2048';
  209. });
  210. },
  211. ptzCamera: function(leftRight, upDown, zoom) {
  212. console.log('云台控制:' + leftRight + ' : ' + upDown + " : " + zoom);
  213. let that = this;
  214. this.$axios({
  215. method: 'post',
  216. url: '/api/ptz/' + this.deviceId + '/' + this.channelId + '?leftRight=' + leftRight + '&upDown=' + upDown +
  217. '&inOut=' + zoom + '&moveSpeed=50&zoomSpeed=50'
  218. }).then(function(res) {});
  219. },
  220. //////////////////////播放器事件处理//////////////////////////
  221. videoError:function(e){
  222. console.log("播放器错误:"+JSON.stringify(e));
  223. }
  224. }
  225. };
  226. </script>
  227. <style>
  228. .control-wrapper {
  229. position: relative;
  230. width: 6.25rem;
  231. height: 6.25rem;
  232. max-width: 6.25rem;
  233. max-height: 6.25rem;
  234. margin: 0 auto;
  235. border-radius: 100%;
  236. float: left;
  237. }
  238. .control-btn {
  239. display: flex;
  240. justify-content: center;
  241. position: absolute;
  242. width: 44%;
  243. height: 44%;
  244. border-radius: 5px;
  245. border: 1px solid #78aee4;
  246. box-sizing: border-box;
  247. transition: all 0.3s linear;
  248. }
  249. .control-btn i {
  250. font-size: 20px;
  251. color: #78aee4;
  252. display: flex;
  253. justify-content: center;
  254. align-items: center;
  255. }
  256. .control-round {
  257. position: absolute;
  258. top: 21%;
  259. left: 21%;
  260. width: 58%;
  261. height: 58%;
  262. background: #fff;
  263. border-radius: 100%;
  264. }
  265. .control-round-inner {
  266. position: absolute;
  267. left: 15%;
  268. top: 15%;
  269. display: flex;
  270. justify-content: center;
  271. align-items: center;
  272. width: 70%;
  273. height: 70%;
  274. font-size: 40px;
  275. color: #78aee4;
  276. border: 1px solid #78aee4;
  277. border-radius: 100%;
  278. transition: all 0.3s linear;
  279. }
  280. .control-inner-btn {
  281. position: absolute;
  282. width: 60%;
  283. height: 60%;
  284. background: #fafafa;
  285. }
  286. .control-top {
  287. top: -8%;
  288. left: 27%;
  289. transform: rotate(-45deg);
  290. border-radius: 5px 100% 5px 0;
  291. }
  292. .control-top i {
  293. transform: rotate(45deg);
  294. border-radius: 5px 100% 5px 0;
  295. }
  296. .control-top .control-inner {
  297. left: -1px;
  298. bottom: 0;
  299. border-top: 1px solid #78aee4;
  300. border-right: 1px solid #78aee4;
  301. border-radius: 0 100% 0 0;
  302. }
  303. .control-top .fa {
  304. transform: rotate(45deg) translateY(-7px);
  305. }
  306. .control-left {
  307. top: 27%;
  308. left: -8%;
  309. transform: rotate(45deg);
  310. border-radius: 5px 0 5px 100%;
  311. }
  312. .control-left i {
  313. transform: rotate(-45deg);
  314. }
  315. .control-left .control-inner {
  316. right: -1px;
  317. top: -1px;
  318. border-bottom: 1px solid #78aee4;
  319. border-left: 1px solid #78aee4;
  320. border-radius: 0 0 0 100%;
  321. }
  322. .control-left .fa {
  323. transform: rotate(-45deg) translateX(-7px);
  324. }
  325. .control-right {
  326. top: 27%;
  327. right: -8%;
  328. transform: rotate(45deg);
  329. border-radius: 5px 100% 5px 0;
  330. }
  331. .control-right i {
  332. transform: rotate(-45deg);
  333. }
  334. .control-right .control-inner {
  335. left: -1px;
  336. bottom: -1px;
  337. border-top: 1px solid #78aee4;
  338. border-right: 1px solid #78aee4;
  339. border-radius: 0 100% 0 0;
  340. }
  341. .control-right .fa {
  342. transform: rotate(-45deg) translateX(7px);
  343. }
  344. .control-bottom {
  345. left: 27%;
  346. bottom: -8%;
  347. transform: rotate(45deg);
  348. border-radius: 0 5px 100% 5px;
  349. }
  350. .control-bottom i {
  351. transform: rotate(-45deg);
  352. }
  353. .control-bottom .control-inner {
  354. top: -1px;
  355. left: -1px;
  356. border-bottom: 1px solid #78aee4;
  357. border-right: 1px solid #78aee4;
  358. border-radius: 0 0 100% 0;
  359. }
  360. .control-bottom .fa {
  361. transform: rotate(-45deg) translateY(7px);
  362. }
  363. </style>