目前我正在使用AVAudioSession在iOS上录制音频但录制超过50分钟录制时会出现问题。使用AVAudioPlayer可以播放超过50分钟的重新编码。
任何人都可以告诉记录音频的最大限制是什么。
答案 0 :(得分:4)
iPhone中的记录文件没有限制。 但在保存到应用程序文档目录之前。检查iPhone上的可用空间然后保存,这样丢失文件的机会就会减少。
以下代码检查iPhone中的可用空间。
-(uint64_t)getFreeDiskspace {
NSString *folderPath = [[NSBundle mainBundle] bundlePath];
NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:folderPath error:nil];
NSEnumerator *filesEnumerator = [filesArray objectEnumerator];
NSString *fileName;
unsigned long long int fileSize = 0;
while (fileName = [filesEnumerator nextObject]) {
NSDictionary *fileDictionary = [[NSFileManager defaultManager] fileAttributesAtPath:[folderPath stringByAppendingPathComponent:fileName] traverseLink:YES];
fileSize += [fileDictionary fileSize];
}
NSLog(@"App size : %lld",fileSize);
uint64_t totalSpace = 0;
uint64_t totalFreeSpace = 0;
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
NSError *attributesError = nil;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[paths lastObject] error:&attributesError];
NSLog(@"App Directory size %llu",[fileAttributes fileSize]);
if (dictionary) {
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
totalSpace = [fileSystemSizeInBytes unsignedLongLongValue];
totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
NSLog(@"Memory Capacity of %llu MiB with %llu MiB Free memory available.", ((totalSpace)), ((totalFreeSpace)));
} else {
NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %ld", [error domain], (long)[error code]);
}
// NSLog(@"DISK SPACE %f",[self diskSpace]);
// NSLog(@"GET FREE SPACE %lld",[self getFreeSpace]);
return totalFreeSpace;
}
- (long long)getFreeSpace
{
long long freeSpace = 0.0f;
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *fileSystemFreeSizeInBytes = [dictionary objectForKey: NSFileSystemFreeSize];
freeSpace = [fileSystemFreeSizeInBytes longLongValue];
} else {
//Handle error
NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %ld", [error domain], (long)[error code]);
}
NSLog(@"Free Space %lli",freeSpace);
return (freeSpace);
}
答案 1 :(得分:0)
我找不到它的最大限制,但这里有一个代码将其限制为特定的秒数,以便您可以尝试捕捉以找到限制