Featured image duration

How to insert the duration of a video into ClassicPress to see it in a featured image, something like youtube.
Thank you in advance

Featured image

Do you know the length of the video in advance? If so, it should really just be a matter of adding a field with that value and positioning it with some CSS.

If not, you are almost certainly going to need some sort of JavaScript to extract the length of the video in each case. Wavesurfer.js can certainly do that, but that’s not its primary purpose and it’s massive overkill for what you want. I’d Google for a smaller JavaScript library that does what you want.

I know the length of the video in advance
Is there any add-on that can do the job
Yes, I don’t mess with css
I have one old video theme that no one maintains anymore
And that theme doesn’t work properly with PHP larger than 5.6
The video data looks like on the picture
And it has a field to embed a video e.g. iframe

I have now found that there is the function wp_read_video_metadata, from which you can extract the length of the video in seconds. See https://developer.wordpress.org/reference/functions/wp_read_video_metadata/

But if you want a plugin that does the work for you, have you tried
https://wordpress.org/plugins/youtube-embed-plus/ ?

1 Like

It does not help
I don’t need embeding youtube videos
I cited Youtube as an example
You already need to embed any video from the web (iframe)
Specifically from XXX (porn) pages
And most of these plugins are related to popular video sites: youtube, Vimeo …
Some add-ons and players have broken my page because they are adapted to blocks
And when it comes to codes and functions, it’s not my strong point

Then be specific. Where is the video coming from?

I know this can be done easily with JS, a quick one I just did here: https://jsfiddle.net/obasewt8/, out of curiosity on how it would end in CP, I created a quick plugin, and a couple of styles gave me d following result:

Download d plugin here if u like: https://github.com/devsrealm/videolength/archive/master.zip upload and activate it

Goto your post editor and you’ll see the following:
As soon as you choose and open the video, the Audio constructor added in the js would read the audio duration in the video after onloadedmetadata is done and that would add the result to the input box.
video duration meta box

The video won’t actually upload to your server, this is just to get the duration or you can just manually add it yourself and skip choosing the video.

The last part which might be difficult cos we are not using the same theme is to figure out where you would add the meta result in your template part, I added mine in template-parts/content/entry_thumbnail.php before the close of my post-thumbnail div container.

If you know where to add urs, just add the following:

			<div class="video-duration">
				$video_duration   = get_post_meta( $post->ID, 'videolength_duration', true );
				if ( is_singular( get_post_type() ) && '' !== $video_duration) {
				   ?> <span> <?php echo esc_html( $video_duration ); ?> </span> <?php
				else {
				  echo '';}
			</div><!-- .video-duration -->

Here is a clue from my template part:

template part for video duration

In my case, the div.featured-image is the container holding the image so make sure the div.video-duration is positioned relative to the div.featured-image so it can be properly aligned. E.g I have added a positioned class to the div.video-duration in the plugin so, just add display: relative property to the nearest positioned ancestor or parent which would be the container holding ur featured-image.

Good luck, and I hope ot helps.

1 Like

No that’s not what I thought.
The video source is not on the computer but embedded in the iframe code with the URL as in the image

Also featured image is from URL.
Thank you for your effort and good intentions
He could solve it as in the pictures below
Duration and Duration 2

So, you mean d theme already has d feature? What specific issue are u having, clarify.

Sorry, I’ve been away for a few days.
So my goal is that with a featured image that has a source from a URL using THIS (I don’t know if it has a similar plugin with the ClassicPress signature) plugin
E I would with such a featured image that I have a visible duration of the video that I can enter manually.
The video is also not uploaded to my page but using the embedded IFRAME code as I wrote in the previous query