核心代码:
NSFileManager *fileManage = [[NSFileManager alloc]init];
NSURL *directorURL = [NSURL URLWithString:@"/System/Library/Audio"];
NSArray *key = [NSArray arrayWithObject:NSURLIsDirectoryKey];
NSDirectoryEnumerator *enumerator = [fileManage enumeratorAtURL:directorURL includingPropertiesForKeys:key options:0 errorHandler:^BOOL(NSURL * _Nonnull url, NSError * _Nonnull error) {return YES;}];
for (NSURL *url in enumerator) {
NSError *error;
NSNumber *isDirectory = nil;
if (![url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&error]) {
}
else if (![isDirectory boolValue])
{
[arrData addObject:url]; // 获取的音频存到数组
}
例子:获取后点击播放