dmeo1.tsx 2.08 KB
Newer Older
喻天's avatar
喻天 committed
1 2 3 4 5 6 7 8 9 10 11 12 13
// @ts-ignore
import React, { useRef, useEffect } from 'react';
import Video from '../index';

const Demo1 = (props) => {
  const jessibuca = useRef(null);

  let JessibucaObj = {
    operateBtns: {
      // fullscreen: false,
      screenshot: false,
    },
    loadingText: '演示视频加载中',
喻天's avatar
喻天 committed
14
    decoder: '/JessibucaVideo/decoder.js',
喻天's avatar
喻天 committed
15
  };
喻天's avatar
喻天 committed
16 17 18 19 20 21
  // 若是在子应用中,则需加上子应用名称,且兼容基座
  // 如下:
  // let _url = '/civ_energy/JessibucaVideo/decoder.js'
  // let JessibucaObj = {
  //   decoder: window.__POWERED_BY_QIANKUN__ ? '/civbase' + _url : _url
  // }
喻天's avatar
喻天 committed
22
  let VideoInfo = {
喻天's avatar
喻天 committed
23 24 25
    key: '1CEB209F-8BC7-44B5-9F6B-3D8FCB855E76',
    dataRate: `/2`,
    fullUrl: 'ws://172.16.19.19:8080/jessica/1CEB209F-8BC7-44B5-9F6B-3D8FCB855E76',
喻天's avatar
喻天 committed
26
    useFullUrl: true,
喻天's avatar
喻天 committed
27 28 29 30
    cameraName: `摄像头s8`,
  };

  useEffect(() => {
喻天's avatar
喻天 committed
31
    // 事件 ,返回视频信息
喻天's avatar
喻天 committed
32 33 34
    jessibuca.current.on('videoInfo', function (data) {
      console.log('width:', data.width, 'height:', data.width);
    });
喻天's avatar
喻天 committed
35 36

    // 事件 ,播放视频之后的回调
喻天's avatar
喻天 committed
37 38 39
    jessibuca.current.on('play', function (data) {
      console.log('play:', jessibuca);
    });
喻天's avatar
喻天 committed
40 41

    // 事件 ,暂停视频之后的回调
喻天's avatar
喻天 committed
42 43 44
    jessibuca.current.on('pause', function (data) {
      console.log('pause:', data);
    });
喻天's avatar
喻天 committed
45 46 47 48

    // ******
    // 其他事件需查看在线文档
    // ******
喻天's avatar
喻天 committed
49 50 51
  }, []);

  const stopVideo = () => {
喻天's avatar
喻天 committed
52
    jessibuca.current.pause();
喻天's avatar
喻天 committed
53 54 55
  };

  const startVideo = () => {
喻天's avatar
喻天 committed
56 57 58
    if (jessibuca && jessibuca.current) {
      jessibuca.current.play();
      // console.log(jessibuca.current.isPlaying());
喻天's avatar
喻天 committed
59 60 61
    }
  };
  const testVideo = () => {
喻天's avatar
喻天 committed
62
    // console.log(jessibuca.current.isPlaying());
喻天's avatar
喻天 committed
63
  };
喻天's avatar
喻天 committed
64

喻天's avatar
喻天 committed
65
  const destroyVideo = () => {
喻天's avatar
喻天 committed
66
    jessibuca.current.destroy();
喻天's avatar
喻天 committed
67 68 69 70 71
  };
  return (
    <div>
      <button onClick={stopVideo}>暂停</button>
      <button onClick={startVideo}>开始</button>
喻天's avatar
喻天 committed
72 73
      <button onClick={testVideo}>测试</button>
      <button onClick={destroyVideo}>销毁</button>
喻天's avatar
喻天 committed
74 75 76 77 78 79
      <Video {...{ JessibucaObj: JessibucaObj, VideoInfo: VideoInfo }} ref={jessibuca} />
    </div>
  );
};

export default Demo1;