-1

iPhone デバイスからすべての mp3 ファイルを検索したい。MPMediaQueryを使わずにそれを行う方法はありますか????

4

1 に答える 1

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
    }
}
于 2013-08-28T06:03:17.567 に答える