2013-08-28 20 views
-1

我想从iPhone设备搜索所有的MP3文件。反正有没有使用MPMediaQuery从iPhone设备搜索所有声音文件?

+2

当然,这是行不通的。您正在应用程序的沙箱中搜索文件,该文件显然不会包含所有音乐文件。 – Abizern

+0

@Abizern感谢那我怎么拿到 – iCoder

+0

你可以在这里找到https://developer.apple.com/search/index.php?q=movie&platform=iOS&type=Sample%20Code一些示例代码 –

回答

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

感谢reply.I不想使用MPmediaQuery – iCoder

+1

为什么不能?很显然,通过系统访问系统资源的唯一方法就是通过系统。 iOS是沙盒,除非你越狱。 – Abizern