I need help for my video carousel using Swiper.js and React Player. I want to stop the video when swiped and became inactive slide. I set the state like below and it does behave as I wanted. But now, it autoplays the active slide even autoplay prop is false. How can I achieve both stop playing inactive video and not auto playing the active one? I have stuck here almost 3 weeks so I appreciate any suggestions.
UPDATE: Revised question to be clearer and includes autoplay issue.
const videodata = [
{
id: 0,
name: 'video1',
url: 'https://www.youtube.com/1234',
},
{
id: 1,
name: 'video2',
url: 'https://www.youtube.com/5678',
},
]
const [isPlaying, setIsPlaying] = useState(false)
<Swiper
onSlideChange={(swiper) => {
if (swiper.activeIndex !== videodata.id) {
setIsPlaying(false)}
}}
autoplay={false}
watchSlidesProgress={true}>
{videodata.map((data) => (
<SwiperSlide>
<ReactPlayer
key={data.id}
url={data.url}
controls={true}
playing={isPlaying}/>
</SwiperSlide>
))}
</Swiper>