gpt4 book ai didi

php - 使用 wp_read_audio_metadata()

转载 作者:可可西里 更新时间:2023-10-31 23:27:53 24 4
gpt4 key购买 nike

我正在尝试从 WordPress 中的 mp3 文件中获取一些元数据。特别是长度变量。这是我的一些代码。它没有在这里显示,但我已经包含了 wp-admin/includes/media.php 文件。当我查看我的页面时 http://beta.openskyministry.org/podcasts/我只看到 <itunes:length></itunes:length> 的空标签

如果您需要任何其他帮助回答我的问题,请告诉我。

$aud_meta = wp_read_audio_metadata($aud_url); ?>

<item>


<title><?php the_title(); ?></title>

<itunes:author><?php echo htmlspecialchars((get_bloginfo('name'))); ?></itunes:author>

<itunes:summary><?php echo htmlspecialchars(strip_tags(get_the_excerpt())); ?></itunes:summary>

<itunes:length><?php echo $aud_meta['length_formatted']; ?></itunes:length>

最佳答案

WordPress 已经存储了媒体元数据,所以没有必要再去研究它。解决方案很简单:

add_action( 'wp_head', function(){
global $post;
if ( is_single($post) ) {
$args = array(
'post_type' => 'attachment',
'numberposts' => 1,
'post_parent' => $post->ID,
'post_mime_type' => 'audio'
);
$attachments = get_posts( $args );
if($attachments){
$meta = wp_get_attachment_metadata( $attachments[0]->ID );
echo "<itunes:length>{$meta['length_formatted']}</itunes:length>";
}
}
});

作为记录,wp_read_audio_metadata() 需要文件路径,而不是 URL。如果需要,它应该是:

$path = get_attached_file( $attachment->ID );
$meta = wp_read_audio_metadata($path);
echo "<itunes:length>{$meta['length_formatted']}</itunes:length>";

相关:Save camera info as metadata on image upload?

关于php - 使用 wp_read_audio_metadata(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43336867/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com