简体   繁体   English

如何确定录制的音频文件的大小

[英]How to determine the size of a recorded audio file

I want to display the size of an audio file in a UITableView . 我想在UITableView显示音频文件的大小。 I recorded the audio with: 我用以下方式录制了音频:

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];

[[AVAudioSession sharedInstance] setActive: YES error: nil];

NSDictionary *recordSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
                                [NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
                                [NSNumber numberWithInt: kAudioFormatAppleLossless],  AVFormatIDKey,
                                [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
                                [NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey, nil];

I saved the file in the Documents folder, and I'm displaying the name in a UITableView cell. 我将文件保存在Documents文件夹中,并在UITableView单元格中显示名称。

How do I display the size of the audio file as well? 如何显示音频文件的大小?

Try this 尝试这个

NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:URL error:&attributesError];

NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize];
long long fileSize = [fileSizeNumber longLongValue];

Note that the fileSize won't necessarily fit in an integer (especially a signed one) although you could certainly drop to a long for iOS as you'll never exceed that in reality. 请注意,fileSize不一定适合整数(尤其是带符号的整数),尽管对于iOS来说您肯定会花很长的时间,因为在现实中您再也不会超过它了。 The example uses long long as in my code I have to be compatible with systems with much larger storage available. 该示例使用了很长时间,因为在我的代码中,我必须与可用容量更大的系统兼容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM