返回介绍

wp_read_audio_metadata()

发布于 2017-09-11 12:40:37 字数 2790 浏览 1044 评论 0 收藏 0

wp_read_audio_metadata( string $file )

Retrieve metadata from a audio file’s ID3 tags


description


参数

$file

(string) (Required) Path to file.


返回值

(array|bool) Returns array of metadata, if found.


源代码

File: wp-admin/includes/media.php

function wp_read_audio_metadata( $file ) {
	if ( ! file_exists( $file ) ) {
		return false;
	}
	$metadata = array();

	if ( ! defined( 'GETID3_TEMP_DIR' ) ) {
		define( 'GETID3_TEMP_DIR', get_temp_dir() );
	}

	if ( ! class_exists( 'getID3', false ) ) {
		require( ABSPATH . WPINC . '/ID3/getid3.php' );
	}
	$id3 = new getID3();
	$data = $id3->analyze( $file );

	if ( ! empty( $data['audio'] ) ) {
		unset( $data['audio']['streams'] );
		$metadata = $data['audio'];
	}

	if ( ! empty( $data['fileformat'] ) )
		$metadata['fileformat'] = $data['fileformat'];
	if ( ! empty( $data['filesize'] ) )
		$metadata['filesize'] = (int) $data['filesize'];
	if ( ! empty( $data['mime_type'] ) )
		$metadata['mime_type'] = $data['mime_type'];
	if ( ! empty( $data['playtime_seconds'] ) )
		$metadata['length'] = (int) round( $data['playtime_seconds'] );
	if ( ! empty( $data['playtime_string'] ) )
		$metadata['length_formatted'] = $data['playtime_string'];

	wp_add_id3_tag_data( $metadata, $data );

	return $metadata;
}

更新日志

Versiondescription
3.6.0Introduced.

相关函数

Uses

  • wp-admin/includes/media.php: wp_add_id3_tag_data()
  • wp-includes/functions.php: get_temp_dir()

Used By

  • wp-admin/includes/image.php: wp_generate_attachment_metadata()
  • wp-admin/includes/media.php: media_handle_upload()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Example

    
    $uploads = wp_upload_dir();
    $uploads_dir = ( $uploads['baseurl'] . $uploads['subdir'] );
    $file = $uploads_dir . '/example.mp3';
    $metadata = wp_read_audio_metadata( $file );
    print "Audio is " . $metadata['length'] . ' seconds long';
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文