Amber Shopify Project created using ReactJS+React-Redux with GraphQL API integration. Storefront Shopify API: https://github.com/Shopify/shopify-app-js/tree/main/packages/api-clients/storefront-api-client#readme
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VideoAds.jsx 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { useRef, useState, useEffect } from 'react';
  2. import { Box, Button } from '@mui/material';
  3. import PropTypes from 'prop-types';
  4. import videoAds from "../../assets/video/amberads.mp4";
  5. const VideoAds = ({ video_url, height, width }) => {
  6. const videoRef = useRef(null);
  7. const [isMuted, setIsMuted] = useState(true);
  8. useEffect(() => {
  9. if (videoRef.current) {
  10. videoRef.current.muted = true; // Ensure video starts muted for autoplay
  11. videoRef.current.play().catch((err) => {
  12. console.warn('Autoplay failed:', err);
  13. });
  14. }
  15. }, []);
  16. const toggleMute = () => {
  17. if (videoRef.current) {
  18. videoRef.current.muted = !isMuted;
  19. setIsMuted(!isMuted);
  20. }
  21. };
  22. return (
  23. <Box
  24. sx={{
  25. position: 'relative',
  26. overflow: 'hidden',
  27. width: '100%',
  28. height: {
  29. xs: 230,
  30. sm: 330,
  31. md: 520,
  32. lg: 675,
  33. xl: 850,
  34. },
  35. }}
  36. >
  37. <video
  38. ref={videoRef}
  39. src={video_url || videoAds}
  40. autoPlay
  41. loop
  42. muted={isMuted}
  43. playsInline
  44. style={{
  45. position: 'absolute',
  46. top: 0,
  47. left: 0,
  48. width: '100%',
  49. height: 'auto',
  50. }}
  51. />
  52. <Button
  53. onClick={toggleMute}
  54. variant="contained"
  55. sx={{
  56. position: 'absolute',
  57. bottom: 16,
  58. right: 16,
  59. zIndex: 1,
  60. backgroundColor: 'rgba(0, 0, 0, 0.5)',
  61. color: 'white',
  62. '&:hover': {
  63. backgroundColor: 'rgba(0, 0, 0, 0.7)',
  64. },
  65. }}
  66. >
  67. {isMuted ? 'Unmute' : 'Mute'}
  68. </Button>
  69. </Box>
  70. );
  71. };
  72. VideoAds.propTypes = {
  73. video_url: PropTypes.string.isRequired,
  74. height: PropTypes.string,
  75. width: PropTypes.string,
  76. };
  77. VideoAds.defaultProps = {
  78. video_url: videoAds,
  79. height: '300px',
  80. width: '100%',
  81. };
  82. export default VideoAds;