( Objective-C ) 仅使用简单的 AudioServicesPlaySystemSoundID 及其对应项,但我无法在文档中找到是否已经有查找音频文件长度的方法。
我知道有 AudioServicesGetPropertyInfo,但它似乎返回一个字节缓冲区 - 音频文件是否将它们的长度嵌入到自身中,我可以用它提取它?
或者是否有基于比特率 * 文件大小的公式来转换为时间长度?
mIL3S
www.milkdrinkingcow.com
最佳答案
根据 Google 的快速搜索,有一个公式:
length-of-time (duration in seconds) = fileSize (in bytes) / bit-rate (bits/secs)*8
您使用系统声音服务播放声音有什么特别的原因吗?
如果你使用 AVAudioPlayer 来处理你的声音,你可以这样做:
AVAudioPlayer * sound = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
sound.delegate = self;
sound.volume = 1;
NSLog([NSString stringWithFormat:@"%f", sound.duration]);
关于iphone - 如何查找音频文件长度(以秒为单位),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4630176/