What has happened to the .duration method on Wix Video element?

Question:
What has happened to the .duration method on Wix Video element?

Product:
Wix Editor => Wix Video

What are you trying to achieve:
Collecting duration of video after it plays or progresses.

What have you already tried:
After loading a video element with a video link, I’ve coded the element to log it’s play and progress events after attempting to collect the video element’s duration.


export function player_progress(event){if(duration<3){console.log("prog Stamp",event);duration=event.target.duration;testDuration()}}


And below is my console reporting that the element has a duration of 0, but has currentTime of 298 (being a 5 minute video, duration should certainly be 300+). This used to work without issue (returning the duration of any loaded video in seconds), and I moved on to other sections of the project. I’ve only recently discovered the method returns incorrect information after reviewing my project. Is there a way I can get help on this?

It’s hard to tell what could be happening here without knowledge of what the duration variable is initialized to (i.e. if (duration < 3)).

Are you trying to get the length of a video, or the current timestamp of where the user is in the VideoPlayer?

If you need the current timestamp, I recommend using the currentTime property

Example

let currentTime = $w("#myVideoPlayer").currentTime

Yes, i am looking for the length of the video. When i use .duration. which i assume is to get the legnth of the loaded and initialized video, however it reports 0, as you can see from my console log

Did you place the video on the page using the Wix Video App, VideoPlayer Element, or VideoBox Element?

Video Box Element. It is initialized (page loads with default video) and reads 0 duration, and when you set the SRC of the video element (in code or by connecting via Database) the duration value is still 0 even when the video element displays currentTime and duration values within the video’s frame. Please. try for yourself. Starting to believe this is a genuine bug and needs to be escalated…

image

This returns 0, regardless of what you do to the element or media source of the element.

let duration = $w("#myVideoPlayer").duration
console.log(duration)
// 0

Thanks for the context, this was helpful for recreating your issue.

I have flagged this issue internally, and will get back to you as soon as possible once I can provide a solution and/or explanation.

1 Like