views:

449

answers:

2

i want to make a list of all audio or video file stored in iPhone with the help of my application. I know the mp3 is stored at "var/mobile/media/iTune_control/music" this path. But when i run my application using this path, it show there is no file at this path. I think the certain path is write protected. Is there is any way to find the path of video or audio and also create its list. Please help me to solve this problem.

+1  A: 

Look at the MPMediaPlayer class.

Apple doesn't like you messing around with the actual song files. The thinking is that if you could grab the song files then you'd be able to share them with your friends easier. Therefore, you can go through the MPMediaPlayer class and get listings and play songs, but you can't access the actual song files.

mahboudz
+2  A: 

You should never make assumptions on the filesystem layout, and you should not access the filesystem outside of your applications own sandbox. So if you can not find the directory using NSSearchPathForDirectoriesInDomains(), then you should not access it.

When accessing the music library you should not use the filesystem at all, but instead use the Media Player framework. The easiest way to enumerate all available songs would be something like this:

for (MPMediaItem* item in [MPMediaQuery songsQuery].items) {
  NSString* title = [item valueForProperty:MPMediaItemPropertyTitle];
  NSString* artist = [item valueForProperty:MPMediaItemPropertyArtist];
  NSLog(@"%@ by %@", title, artist);
}

Use MPMediaQuery and MPMediaPredicate to create your own custom and more complex result sets of songs and videos.

PeyloW