Browse Source

safari autoplay

master
azri 1 week ago
parent
commit
de6ece57b5
1 changed files with 10 additions and 1 deletions
  1. 10
    1
      src/components/VideoAds/VideoAds.jsx

+ 10
- 1
src/components/VideoAds/VideoAds.jsx View File

1
-import React, { useRef, useState } from 'react';
1
+import { useRef, useState, useEffect  } from 'react';
2
 import { Box, Button } from '@mui/material';
2
 import { Box, Button } from '@mui/material';
3
 import PropTypes from 'prop-types';
3
 import PropTypes from 'prop-types';
4
 import videoAds from "../../assets/video/amberads.mp4";
4
 import videoAds from "../../assets/video/amberads.mp4";
7
   const videoRef = useRef(null);
7
   const videoRef = useRef(null);
8
   const [isMuted, setIsMuted] = useState(true);
8
   const [isMuted, setIsMuted] = useState(true);
9
 
9
 
10
+  useEffect(() => {
11
+    if (videoRef.current) {
12
+      videoRef.current.muted = true; // Ensure video starts muted for autoplay
13
+      videoRef.current.play().catch((err) => {
14
+        console.warn('Autoplay failed:', err);
15
+      });
16
+    }
17
+  }, []);
18
+
10
   const toggleMute = () => {
19
   const toggleMute = () => {
11
     if (videoRef.current) {
20
     if (videoRef.current) {
12
       videoRef.current.muted = !isMuted;
21
       videoRef.current.muted = !isMuted;

Loading…
Cancel
Save