3

我是 xcode 编程的新手。我需要搜索所有声音文件并在表格视图中显示它们。任何人请给我想法

4

2 回答 2

4

您只需检查文件的扩展名即可获取所有声音文件。下面我给出了 mp3 文件的示例。如果您还想搜索另一个扩展名,那么只需在 " OR" 条件中添加一个扩展名:

  1. 找到resourcePathie目录,因为所有的声音文件都是资源
  2. 获取该目录中所有文件的列表
  3. 现在在该列表中搜索特定的扩展名

    NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
    NSFileManager *filemgr = [[NSFileManager alloc] init];
    
    NSArray *allFiles = [filemgr 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
        }
    }
    
于 2013-05-30T05:07:06.743 回答
3

如果您在您的应用程序中寻找声音文件,Ravindra 已经回答了它。

如果您正在 iPhone 中的所有其他音乐应用程序中寻找声音文件,我怀疑您是否可以访问它们。

但是,您可以从用户 iTunes 音乐库访问歌曲。您将需要使用 MPMediaPickerController

试试这个教程:http: //mobile.tutsplus.com/tutorials/iphone/ios-sdk-music-library-access/

于 2013-05-30T05:26:19.670 回答