[英]How to determine the size of a recorded audio file
我想在UITableView
显示音频文件的大小。 我用以下方式录制了音频:
[[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];
我将文件保存在Documents文件夹中,并在UITableView
单元格中显示名称。
如何显示音频文件的大小?
尝试这个
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:URL error:&attributesError];
NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize];
long long fileSize = [fileSizeNumber longLongValue];
请注意,fileSize不一定适合整数(尤其是带符号的整数),尽管对于iOS来说您肯定会花很长的时间,因为在现实中您再也不会超过它了。 该示例使用了很长时间,因为在我的代码中,我必须与可用容量更大的系统兼容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.