从iphone设备搜索所有声音文件?

时间:2013-08-28 05:49:18

标签: iphone ios objective-c

我想搜索 iPhone设备中的所有mp3文件。无论如何不使用 MPMediaQuery ????

1 个答案:

答案 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
    }
}