"use strict";(self.webpackChunk_streamlit_app=self.webpackChunk_streamlit_app||[]).push([[9464],{89464:(e,t,r)=>{r.r(t),r.d(t,{default:()=>s});var n=r(58878),u=r(90782);function s(e){let{element:t,width:r,endpoints:s,elementMgr:a}=e;const i=(0,n.useRef)(null),{startTime:d,endTime:c,loop:l,autoplay:o}=t,m=(0,n.useMemo)((()=>{if(!t.id)return!0;const e=a.getElementState(t.id,"preventAutoplay");return e||a.setElementState(t.id,"preventAutoplay",!0),null!==e&&void 0!==e&&e}),[t.id,a]);(0,n.useEffect)((()=>{i.current&&(i.current.currentTime=d)}),[d]),(0,n.useEffect)((()=>{const e=i.current,r=()=>{e&&(e.currentTime=t.startTime)};return e&&e.addEventListener("loadedmetadata",r),()=>{e&&e.removeEventListener("loadedmetadata",r)}}),[t]),(0,n.useEffect)((()=>{const e=i.current;if(!e)return;let t=!1;const r=()=>{c>0&&e.currentTime>=c&&(l?(e.currentTime=d||0,e.play()):t||(t=!0,e.pause()))};return c>0&&e.addEventListener("timeupdate",r),()=>{e&&c>0&&e.removeEventListener("timeupdate",r)}}),[c,l,d]),(0,n.useEffect)((()=>{const e=i.current;if(!e)return;const t=()=>{l&&(e.currentTime=d||0,e.play())};return e.addEventListener("ended",t),()=>{e&&e.removeEventListener("ended",t)}}),[l,d]);const p=s.buildMediaURL(t.url);return(0,u.jsx)("audio",{className:"stAudio","data-testid":"stAudio",ref:i,controls:!0,autoPlay:o&&!m,src:p,style:{width:r}})}}}]);