devicePlayer.vue 12 KB

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