You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Shaka-Player under the hood and no matter what stream I play, the calculated timeBehindEdge is always way way off. Like multitudes off. Yet clicking the Live button does correctly bring it to live edge, so however that is calculating it is correct.
At a quick glance of the code it seems like the seekable range is wrong (when compared to calling shakaPlayer.seekRange() anyway), and the computed time behind edge is therefore wrong (always like hours behind edge, when in reality your only a few seconds behind).
I have the following wrapper around the MediaLiveButton as a hacky fix by directly using player, but this means I need to trickle down the player variable, or use a react portal/provider. Not ideal.
import{useEffect,useState}from"react"import{clsx}from"@nextui-org/shared-utils"import{useMediaSelector}from"media-chrome/react/media-store"import{MediaLiveButton}from"media-chrome/react"exportdefaultfunctionLiveButton({ player }){/** * Small wrapper over MediaLiveButton to fix the indicator. * * Media-Chrome gets the value for seekable range wrong, somehow. * Since the seekable range value is wrong, then calculating how * far behind edge the player is cannot be correct. Usually it is * way behind, when in reality it's only a few seconds behind. */constcurrentTime=useMediaSelector(state=>state.mediaCurrentTime)/* only used when player is not passed or is falsey */consttimeIsLive=useMediaSelector(state=>state.mediaTimeIsLive)const[isLive,setIsLive]=useState(false)useEffect(()=>{if(player){constseekRange=player.seekRange()// media-chrome get's this value wrong, we must use thisconstbehindEdge=Math.max(0,Math.floor(seekRange.end-currentTime))setIsLive(behindEdge<=2)}else{setIsLive(timeIsLive)}},[player,currentTime])return(<MediaLiveButton><spanslot="indicator"className={clsx("text-lg leading-none icon-[mdi--circle-medium]",isLive ? "text-danger" : "text-gray-500")}/></MediaLiveButton>)}
The text was updated successfully, but these errors were encountered:
rlaphoenix
changed the title
MediaLiveButton indicator never activates -- the calculated time behind edge is always wrong
MediaLiveButton indicator never activates -- mediaTimeIsLive is always false
Nov 7, 2024
I'm using Shaka-Player under the hood and no matter what stream I play, the calculated timeBehindEdge is always way way off. Like multitudes off. Yet clicking the Live button does correctly bring it to live edge, so however that is calculating it is correct.
At a quick glance of the code it seems like the seekable range is wrong (when compared to calling
shakaPlayer.seekRange()
anyway), and the computed time behind edge is therefore wrong (always like hours behind edge, when in reality your only a few seconds behind).I have the following wrapper around the MediaLiveButton as a hacky fix by directly using player, but this means I need to trickle down the player variable, or use a react portal/provider. Not ideal.
The text was updated successfully, but these errors were encountered: