我想搜索 iPhone设备中的所有mp3文件。无论如何不使用 MPMediaQuery ????
答案 0 :(得分:1)
使用MPMediaQuery:
MPMediaQuery *getAlbums = [MPMediaQuery albumsQuery];
NSArray *getAllAlbumsArray = [getAlbums collections];
for (MPMediaItemCollection *collection in allAlbumsArray)
{
MPMediaItem *item = [collection representativeItem];
//do any task with 'item'
}
编辑:由于sop不想使用MPMediaQuery,您可以通过这种方式获取mp3文件的路径。(在应用中)
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
NSFileManager *filemanager = [[NSFileManager alloc] init];
NSArray *allFiles = [filemanager contentsOfDirectoryAtPath:bundlePath error:NULL];
for (NSString *fileName in allFiles)
{
if ([[fileName pathExtension] isEqualToString:@"mp3"])
{
NSString *fullFilePath = [bundlePath stringByAppendingPathComponent:fileName];
//do whatever you want to do with the path
}
}