11

I am trying some code to open the iPod Library using the simulator but the app crashes with this error:

MPMediaLibrary: Unable to launch iPod library server: application not found

Do I need an actual iPhone to test this code?

newenglander
  • 2,019
  • 24
  • 55
coure2011
  • 40,286
  • 83
  • 216
  • 349
  • 1
    Could you update your choice of answer to reflect the fact that this is now possible in the newer versions of Xcode? – newenglander Jul 07 '16 at 08:49

5 Answers5

22

I've had some success using MPMediaLibrary / MPMediaQuery on the simulator (not playing music, but at least able to query for items) and xcode 4.6.3

I used iFunBox to copy these files from my device:

'Raw File System'/iTunes_Control/iTunes/MediaLibrary.sqlitedb
'Raw File System'/iTunes_Control/iTunes/MediaLibrary.sqlitedb-shm
'Raw File System'/iTunes_Control/iTunes/MediaLibrary.sqlitedb-wal
'Raw File System'/iTunes_Control/iTunes/Artwork

onto my mac in the folder:

"~/Library/Application Support/iPhone Simulator/6.1/Media/iTunes_Control/iTunes/"
newenglander
  • 2,019
  • 24
  • 55
JosephH
  • 37,173
  • 19
  • 130
  • 154
8

Yes you need to test on a device to access the media library.

prendio2
  • 1,885
  • 17
  • 25
5

Clarification to answer JosephH:

it even works in Xcode 6 but the files should be placed in a folder:

"~/Library/Developer/CoreSimulator/Devices/########-####-####-####-############/data/Media/iTunes_Control/iTunes"

where ########-####-####-####-############ - will be different for different versions of the simulator phone

Rinat Abidullin
  • 141
  • 4
  • 4
  • I tried copying the entire iTunes_Control folder, but it was unable to play the media. – Hackmodford Aug 01 '15 at 23:22
  • Did they change anything with the newer Xcode 6 versions? I tried getting this to work, but doesn't find any entries for a media query at all. (even though on my iphone i have hundreds of songs) – Jan Sep 04 '15 at 12:54
  • okay this was on me. The library files are from iOS7 and don't work in an iOS8 simulator. work fine though in a simulator for iOS7. Have to organize corresponding files for 8 (and maybe 9?) – Jan Sep 10 '15 at 21:54
  • @Dimitri, yes the music database for iOS changed quite a bit from iOS 7 to 8 and also from 8 to 8.4, so you'll need separate copies of each. I believe iOS 8.4 and 9 are quite similar, but I can't say for sure. – newenglander Oct 05 '15 at 21:01
  • @Hackmodford: Depending on where the audio file was stored, you may also need to copy the `Purchases` folder, which is next to `iTunes_Control`. See my new answer for more information. – newenglander Jun 01 '16 at 15:51
1

I was trying to figure this out as well and since you basically need to use all of the answers given here and it is somewhat outdated I figured I would write a little how to.

I will try to keep this up to date so everyone who wants to use this ability will be able to use it without to much trouble

NoSixties
  • 2,443
  • 2
  • 28
  • 65
  • You may want to copy the contents of your how-to into an answer as link-only answers are generally to be avoided like the plague. – Till Apr 30 '17 at 21:16
0

To add to @JosephH and @Rinat Abidullin's answers, I also found that it is possible to access the music files themselves from the Simulator (at least using the iOS 8 and 9 Simulators from Xcode 7.3). For this to work, I copied the following folders from my iPhone to the corresponding folder on my Mac (in addition to the files @JosephH mentioned):

  • /var/mobile/Media/iTunes_Control/Music
  • /var/mobile/Media/Purchases

The files can then be played by using an AVAudioSession to open the MPMediaItemPropertyAssetURL.

Update: There is also a very good sample project that can be used to easily test this out: GVMusicPlayerController.

newenglander
  • 2,019
  • 24
  • 55
  • I don't have a directory `mobile` in my `var` directory. Do you happen to know if this changed and where to find it now? – NoSixties Dec 23 '16 at 13:16
  • Could you possible edit your answer and tell step by step what needs to be done to get this working – NoSixties Dec 23 '16 at 13:32
  • @NoSixties: What iOS version and how are you accessing the file system? – newenglander Dec 23 '16 at 13:45
  • I'm talking about on my macbook since you say the go in the corresponding directory. But iOS 10.2 and IfunBox – NoSixties Dec 23 '16 at 18:05
  • @NoSixties: The directories listed above are on iOS (though I'm not sure if anything changed in iOS 10). For the corresponding directory on your Mac, see Rinat Abidullin's answer (assuming it's still the same for the latest version of Xcode). – newenglander Dec 24 '16 at 02:24