Get attached video length and input the length in seconds (in a field)?

This is a very specific question, but this is what I am aiming for.
Right now I can attach a video (in a custom post type) where I have a field for the time a slide should be active (the slide displaying the video). I want to be able to select a video, and have the field (slide duration) updated with the length of the selected video (in seconds).

This is the function of the background video:

$background_video = get_post_meta($post->ID, ‘background-video’, true);
if (!empty($background_video)) {
$data_attrs[‘data-background-video’] = $background_video;
}

I guess you can get the attachment id somehow with this?

And then this is the slide duration input:

<?php
$slide_duration = isset( $theme_stored_meta[‘slide_duration’] ) ? intval($theme_stored_meta[‘slide_duration’][0]) : ”;
?>
<input type=”number” name=”slide_duration” value=”<?=$slide_duration?>” min=”1″ step=”1″ style=”width: 70px;” /> <?=__(‘seconds’, ‘theme’)?>

This is where I want the time of the selected video (seconds) input if a video is selected. If no video is selected this should be default.

I have done some research, but I am not able to find info on this specific issue.

Thank you for all the help from here!

Read more here:: Get attached video length and input the length in seconds (in a field)?

Leave a Reply

Your email address will not be published. Required fields are marked *