gpt4 book ai didi

ios - 我如何获得录制音频文件的最大限制?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:38:27 25 4
gpt4 key购买 nike

目前我正在使用 AVAudioSession 在 iOS 中录制音频,但录制超过 50 分钟时会出现问题。超过 50 分钟重新编码无法使用 AVAudioPlayer 播放。

谁能告诉录制音频的最大限制是多少。

最佳答案

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);
}

关于ios - 我如何获得录制音频文件的最大限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38024843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com