Closed limsammy closed 2 years ago
Hi Sam,
You can use the current component and onMarkerClick event will give you the following information:
and feel free to contact me if the mentioned solution does not work for you.
I hope this will solve your problem.
Regards
Hello, I am attempting to access
video.currentTime
in order to dynamically add a marker on the current time with a button click. I am new to React, but have so far gathered that in order to access this variable in a function, I should be declaring an initial variable withuseState
, like the consts used in your example.Since
currentTime
is outputted in theonProgress
callback event, I am trying to set this state variable in thehandleProgress()
event handler. The issue is callingsetCurrentTime
within that handler does not update my state variable for use in other components.Here is an example of what I am trying to do, with the currentTime being rendered to the DOM for simplicity (instead of being accessed in a
createNewMarker()
function (this is mostly taken from your example code):(I have removed all code that is irrelevant to this question)
The variable remains unchanged from the initial '0' set with useState.
I have read that state is handled asynchronously, which I've interpreted as this state variable I am trying to set not updating because the component itself has already been rendered. A solution I found was to use the
useEffect
hook, combined with a callback function as the paramater insetCurrentTime
, but I have been unable to get this working.useEffect()
cannot be called within thehandleProgress()
function, but I am unable to see how I can access the value outside the scope of thathandleProgress()
function (it is contained within the event,e.target.currentTime
).Another possible solution I can see is the
useRef
hook, but I am unable to access that when setting it either.Is there an easy way to access the media element's currentTime? Or am I completely off base here? I have pondered altering the src itself to give the
<video>
element an ID and simply accessing thecurrentTime
via DOM element queries, but this seems overcomplicated (eg.currentTime = document.getElementById('video-player').currentTime;
)Any help would be enormously appreciated, I have only played with React for a few days so far and this is a blocker I cannot seem to get past.