如何找到的音频文件的长度(以秒为单位) [英] How to find an audio file's length (in seconds)

查看:304
本文介绍了如何找到的音频文件的长度(以秒为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(目标C)
只需使用简单的AudioServicesPlaySystemSoundID和它的同行,但我不能在文档中找到,如果已经有找到一个音频文件长度的方法。

(Objective C) Just using simple AudioServicesPlaySystemSoundID and its counterparts, but I can't find in the documentation if there is already a way to find the length of an audio file.

我知道有AudioServicesGetPropertyInfo,但似乎返回一个字节的缓冲区? - 做音频文件中嵌入它们的长度对自己和我可以使用此提取它

I know there is AudioServicesGetPropertyInfo, but that seems to return a byte-buffer - do audio files embed their length in themselves and I can just extract it with this?

还是有可能根据比特率*档案大小公式转换为长度的时间?

Or is there perhaps a formula based on bit-rate * fileSize to convert to length-of-time?

mIL3S

www.milkdrinkingcow.com

www.milkdrinkingcow.com

推荐答案

根据快速谷歌搜索,有一个公式:

According to a quick Google search, there is a formula:

length-of-time (duration in seconds) = fileSize (in bytes) / bit-rate (bits/secs)*8

有你使用系统声音服务来播放声音什么特别的原因?

Is there any particular reason you're using System Sound Services to play a sound?

如果您使用AVAudioPlayer来处理你的声音,你可以这样做:

If you use AVAudioPlayer to handle your sounds you could do something like:

AVAudioPlayer * sound = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
sound.delegate = self;
sound.volume = 1;
NSLog([NSString stringWithFormat:@"%f", sound.duration]);

这篇关于如何找到的音频文件的长度(以秒为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆