demo-monitor.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <meta name="renderer" content="webkit">
  7. <title>EZOPEN播放协议</title>
  8. <style>
  9. body {
  10. margin: 0;
  11. }
  12. .hint {
  13. font-size: 14px;
  14. line-height: 3em;
  15. color: gray;
  16. }
  17. #url,
  18. #url2,
  19. #accessToken {
  20. width: 100%;
  21. }
  22. .btn-container {
  23. margin: 10px;
  24. }
  25. .normal {
  26. color: green;
  27. margin: 5px;
  28. }
  29. .error {
  30. color: red;
  31. margin: 5px;
  32. }
  33. </style>
  34. </head>
  35. <script>
  36. </script>
  37. <body>
  38. <script src="../ezuikit.js"></script>
  39. <!-- <script src="../js/jsPlugin-1.2.0.js"></script> -->
  40. <script src="../js/jquery.min.js"></script>
  41. <div class="hint">demo页面仅为代码示例无法直接运行,需要部署到服务器上才可以播放。另外监控模式与多窗口模式对浏览器版本有要求:Chrome: 55+ Firefox: V55+。</div>
  42. <h2>预览,回放功能示例:</h2>
  43. <textarea id="url" placeholder="这里输入ezopen地址"></textarea>
  44. <textarea id="accessToken" placeholder="这里输入accessToken"></textarea>
  45. <div class="btn-container">
  46. <button id="init">初始化播放</button>
  47. <button id="play">播放</button>
  48. <button id="stop">结束</button>
  49. <button id="getOSDTime">获取OSD时间</button>
  50. <button id="openSound">打开声音(默认已经开启)</button>
  51. <button id="closeSound">关闭声音</button>
  52. <button id="capturePicture">视频截图</button>
  53. <button id="startSave">开始录像</button>
  54. <button id="stopSave">停止录像</button>
  55. <button id="enableZoom">开启电子放大</button>
  56. <button id="closeZoom">关闭电子放大</button>
  57. <span>录制功能不支持加密视频,且录制的文件需要<a href="https://service.ys7.com/downloadInfoSite/admin"
  58. target="_blank">下载海康播放器播放</a></span>
  59. </div>
  60. <div id="playWind" style="width: 600px; height: 400px;">
  61. </div>
  62. <script>
  63. $("#init").click(function () {
  64. function handleError(e) {
  65. console.log('捕获到错误', e)
  66. // log(JSON.stringify(e),'error');
  67. //alert(e)
  68. }
  69. function handleSuccess() {
  70. console.log("播放成功回调函数,此处可执行播放成功后续动作");
  71. }
  72. var url = $('#url').val().trim();
  73. var accessToken = $('#accessToken').val().trim();
  74. var decoder = new EZUIKit.EZUIPlayer({
  75. id: 'playWind',
  76. autoplay: true,
  77. url: url,
  78. accessToken: accessToken,
  79. decoderPath: '',
  80. width: 600,
  81. height: 400,
  82. handleError: handleError,
  83. handleSuccess: handleSuccess,
  84. });
  85. // 这里是打印日志,本例抛出到播放页面
  86. decoder.on('log', log);
  87. function log(str, className) {
  88. var div = document.createElement('DIV');
  89. div.className = className || 'normal';
  90. div.innerHTML = (new Date()).Format('yyyy-MM-dd hh:mm:ss.S') + JSON.stringify(str);
  91. document.body.appendChild(div);
  92. }
  93. $("#start").click(function () {
  94. function handleError(e) {
  95. console.log('handleError', e)
  96. }
  97. function handleSuccess() {
  98. console.log('handleSuccess')
  99. }
  100. decoder.play({
  101. handleError: handleError,
  102. });
  103. })
  104. $("#stop").click(function () {
  105. /*停止播放方法1*/
  106. // decoder.stop();
  107. /*停止播放方法2 - promise模式*/
  108. var stopPromise = decoder.stop();
  109. stopPromise.then(function () {
  110. console.log("关闭成功,用户执行关闭成功后的操作");
  111. })
  112. })
  113. $("#getOSDTime").click(function () {
  114. var getOSDTimePromise = decoder.getOSDTime();
  115. getOSDTimePromise.then(function (data) {
  116. console.log("getOSDTime success", data)
  117. })
  118. })
  119. $("#openSound").click(function () {
  120. decoder.openSound();
  121. })
  122. $("#closeSound").click(function () {
  123. decoder.closeSound();
  124. })
  125. $("#capturePicture").click(function () {
  126. /*截图方法1*/
  127. // decoder.capturePicture(0,'default');
  128. /*截图方法2*/
  129. var capturePicturePromise = decoder.capturePicture(0, 'default');
  130. capturePicturePromise.then(function (data) {
  131. console.log("截图成功,用户执行关闭成功后的操作", data);
  132. })
  133. })
  134. $("#startSave").click(function () {
  135. // decoder.startSave(0, (new Date().getTime() + 'video'));
  136. /*开始录制方法2*/
  137. var startSavePromise = decoder.startSave(0, (new Date().getTime() + 'video'));
  138. startSavePromise.then(function (data) {
  139. console.log("start save success", startSavePromise)
  140. })
  141. .catch(function (error) {
  142. console.log("start Save error", error)
  143. })
  144. })
  145. $("#stopSave").click(function () {
  146. /*结束录制方法1*/
  147. // decoder.stopSave(0);
  148. /*结束录制方法2*/
  149. var stopSavePromise = decoder.stopSave(0);
  150. stopSavePromise.then(function (data) {
  151. console.log("stop save success", stopSavePromise)
  152. })
  153. .catch(function (error) {
  154. console.log("stop Save error", error)
  155. })
  156. })
  157. $("#play").click(function () {
  158. decoder.play();
  159. })
  160. $("#enableZoom").click(function () {
  161. decoder.enableZoom();
  162. })
  163. $("#closeZoom").click(function () {
  164. decoder.closeZoom();
  165. })
  166. })
  167. </script>
  168. </body>
  169. </html>