• Resolved tobiasmurphy

    (@tobiasmurphy)


    I need to get the length of my audio files. I know I can do it with wp_read_audio_metadata, but I know that’s a heavy process that requires including the WP administrative functions, and I’d like to avoid it if possible. I’ve tried all sorts of different codes for attachment meta, but they all seem to be only for images, and this must not be a common problem because I can’t seem to find a solution anywhere. But I know that each audio attachment page lists the length of the attached file, so I know there has to be a code available somewhere, even if it is wp_read_audio_metadata.

    Anyone know what I should do?

    Note: It doesn’t help that Google keeps conflating “audio” with “media” and then “images,” or “length” with “file size.”

Viewing 1 replies (of 1 total)
  • Thread Starter tobiasmurphy

    (@tobiasmurphy)

    I figured it out and I’m posting here so others may benefit. I do not guarantee that this is an elegant solution, but it does work.

    global $post;
    $audio_media = get_attached_media( 'audio', $post->ID );
    $audio_media_reset = reset($audio_media);
    $myvals = get_post_meta($audio_media_reset->ID);
    $myvals2 = unserialize($myvals['_wp_attachment_metadata'][0]);
    $audio_length = $myvals2[length];

    In place of “length” any other criteria can be used, like “filesize” or “length_formatted”, etc.

Viewing 1 replies (of 1 total)
  • The topic ‘How to get audio file metadata, namely, length’ is closed to new replies.