Get video length (Interactive Videos)

I'm wondering if there is a way to pull the length of the video for interactive videos (specifically youtube video in my case).

I'm hoping to do this with the hooks already available, i.e. without having to get youtube api key. Is there a mechanism in h5p to get the current h5p node's video duration?

Thanks in advance.

Summary: 
Get video duration from h5p interactive video instance
0
0
Supporter votes Members of the Supporter Network can vote for feature requests. When the supporter network has generated sufficient funding for the top voted feature request it will normally be implemented and released. More about the H5P Supporter Network
thomasmars's picture

There is indeed, if you look at the code on github you'll find that the getDuration() function is exported, which allows you to call it.

When inside the H5P iFrame you can call it using the following code:

H5P.instances[0].getDuration();

Hi Thomas, Thanks for pointing that out, that's very useful. My next goal is to store this value on save/update. Any recommendations on how to approach that would be appreciated. I'll share my solution at the end.

Thanks again!

thomasmars's picture

Hi, there's currently no API for hooking into the save/update functions of H5P content, and you would not have access to the H5P instance there either way. Depending on what you want to accomplish there may be other ways to achieve what you want.

What I'm hoping to do is display the length of the video in a view. For example, if the view is display a grid of videos, I would like to also display the length of each video - I've attached a screenshot from a site that demonstrates this visually.

Additionally, it would be ideal if the length of videos in a series can be added together (i.e. Series X with 10 videos is 20 hours long).

Any guidance on how to do this efficiently would be helpful.

tim's picture

This is beyond the scope of H5P. You'll have to write some code to interact with your db to retrieve the lengths of the videos and then display them on in your view.