VideoPlay.jsx 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { Row, Col, Card, Statistic, Carousel } from "antd";
  2. import {
  3. ArrowDownOutlined,
  4. ArrowUpOutlined,
  5. LikeOutlined,
  6. } from "@ant-design/icons";
  7. import React, { useState } from "react";
  8. import { useRef } from "react";
  9. import { useEffect } from "react";
  10. // https://image.baidu.com/search/albumsdetail?tn=albumsdetail&word=%E5%AE%A0%E7%89%A9%E5%9B%BE%E7%89%87&fr=albumslist&album_tab=%E5%8A%A8%E7%89%A9&album_id=688&rn=30
  11. // https://image.baidu.com/search/albumsdetail?tn=albumsdetail&word=%E5%9F%8E%E5%B8%82%E5%BB%BA%E7%AD%91%E6%91%84%E5%BD%B1%E4%B8%93%E9%A2%98&fr=searchindex_album%20&album_tab=%E5%BB%BA%E7%AD%91&album_id=7&rn=30
  12. const VideoPlay = (props) => {
  13. const { url, index, current, isVideoPlayRef, style } = props;
  14. const ref = useRef();
  15. useEffect(() => {
  16. if (current == index) {
  17. ref.current
  18. ?.play()
  19. .then((res) => {
  20. isVideoPlayRef.current = true;
  21. })
  22. .catch((err) => {
  23. console.log(err)
  24. isVideoPlayRef.current = false;
  25. });
  26. } else {
  27. ref.current.pause();
  28. isVideoPlayRef.current = false;
  29. }
  30. }, [current, index]);
  31. useEffect(() => {}, []);
  32. return (
  33. <video
  34. ref={ref}
  35. autoPlay={false}
  36. src={url}
  37. controls="controls"
  38. onEnded={() => {
  39. isVideoPlayRef.current = false;
  40. }}
  41. style={style}
  42. ></video>
  43. );
  44. };
  45. export default VideoPlay;