简体   繁体   English

如何通过xcode搜索iphone中的所有声音文件

[英]how can i search all sound files in iphone through xcode

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

You can get all sound files by simply checking the extension of file. 只需检查文件的扩展名即可获得所有声音文件。 Below I have given the example for mp3 files. 下面我给出了mp3文件的例子。 If you want to also search for another extension then simply add one more extension in the " OR " condition: 如果您还要搜索其他扩展名,则只需在“ OR ”条件中再添加一个扩展名:

  1. Find the resourcePath ie directory, because all sound files are resources 找到resourcePath ie目录,因为所有声音文件都是资源
  2. Get the list of all files in that directory 获取该目录中所有文件的列表
  3. Now search for a specific extension in that list 现在搜索该列表中的特定扩展名

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

If you are looking for Sound files within your app, Ravindra has already answered it. 如果您正在寻找应用程序中的声音文件,Ravindra已经回答了它。

If you are looking for Sound files from all other Music Apps in the iPhone, I doubt if you can access them. 如果您正在寻找iPhone中所有其他音乐应用程序的声音文件,我怀疑您是否可以访问它们。

You can however access the Songs from the users iTunes Music Library. 但是,您可以从用户iTunes Music Library访问歌曲。 You will need to use the MPMediaPickerController . 您需要使用MPMediaPickerController

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM