sudheer
sudheer

Reputation: 428

how can i search all sound files in iphone through xcode

i am new to xcode programming.my need is to search all sound files and display them in table view.Any one please give me idea

Upvotes: 3

Views: 2990

Answers (2)

Ravindra Bagale
Ravindra Bagale

Reputation: 17665

You can get all sound files by simply checking the extension of file. Below I have given the example for mp3 files. If you want to also search for another extension then simply add one more extension in the "OR" condition:

  1. Find the resourcePath i.e. directory, because all sound files are resources
  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
        }
    }
    

Upvotes: 4

Roshit
Roshit

Reputation: 1579

If you are looking for Sound files within your app, Ravindra has already answered it.

If you are looking for Sound files from all other Music Apps in the iPhone, I doubt if you can access them.

You can however access the Songs from the users iTunes Music Library. You will need to use the MPMediaPickerController.

Try this tutorial: http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-music-library-access/

Upvotes: 3

Related Questions