sanity-io / sanity-mux-player

Play videos in the frontend uploaded with the MUX Sanity plugin
https://github.com/sanity-io/sanity-plugin-mux-input
21 stars 5 forks source link

Add playsinline option #21

Open j2is opened 2 years ago

j2is commented 2 years ago

Add a playsinline prop for autoplay on iOS

AllanPooley commented 2 years ago

This is the temporary fix I'm using 😢

videoRef.current.querySelector('video').setAttribute('playsinline', '')

const MuxVideo = (props) => {
  const { className, video } = props
  const styles = useStyles()
  const videoRef = useRef()
  useEffect(() => {
    if (videoRef.current) {
      videoRef.current.querySelector('video').setAttribute('playsinline', '')
    }
  }, [])
  if (!video?.video) return null
  return (
    <div className={cn(className || null, styles.videoContainer)} ref={videoRef}>
      <SanityMuxPlayer
        assetDocument={video.video}
        className={styles.video}
        autoload
        autoplay
        muted
        loop
        width='100%'
        showControls={false}
        poster
      />
    </div>
  )
}