📜 ⬆️ ⬇️

Run the music player in the emulator


In this small article I want to share with you one trick when creating an iOS application that plays music.

If you are an iOS developer, then most likely you know that you can access the library with music ( iPod Library ) only on a real device, but not on an emulator ( iPhone Simulator ) [ link to documentation]:

Note: iPod Simulator. This is because the Simulator has an iPod library. To develop applications using this technology, you need a provisioned iOS device.

However, it is not always necessary to access files with music, sometimes only information about tracks (title, artist, cover, etc.) is sufficient . For this situation, you can create the illusion of working with the iPod Library.

When can this situation arise? Suppose you are writing a music player, testing it on a real device (for example, you have two of them: iPhone 4 and iPhone 5). The time is coming for publishing in the App Store: screenshots are needed. You take screenshots from your devices. There are devices (for example, iPhone 6, iPhone 6 Plus) that you do not have. You only need screenshots for the missing devices: here the launch of the emulator is most welcome.
')
So, first you need to copy the database with information about the tracks from the real device. For these purposes, install iFunBox (note that for iOS versions> = 8.3, access to the file system was denied). It is enough to copy the following 3 files and a folder (entirely):

'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 




The copied files should be put in the folder:

 ~/Library/Developer/CoreSimulator/Devices/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/data/Media/iTunes_Control/iTunes 

where xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - for each type of device has its own folder, the device name can be found in the file device.plist located in this folder

For previous versions of Xcode, files need to be put in a folder:

 ~/Library/Application Support/iPhone Simulator/7.1/Media/iTunes_Control/iTunes/ 


Everything! Now you can get information about the tracks, for example:

 MPMediaQuery *myAllSongsQuery = [MPMediaQuery songsQuery]; NSArray *allSongs = [myAllSongsQuery items]; //... cell.songTitleLabel.text = [allSongs[indexPath.row] valueForProperty: MPMediaItemPropertyTitle]; cell.atristLabel.text = [allSongs[indexPath.row] valueForProperty: MPMediaItemPropertyArtist]; cell.coverImage.image = [[allSongs[indexPath.row] valueForProperty: MPMediaItemPropertyArtwork] imageWithSize:cell.coverImage.frame.size]; 


An example of an application running in an emulator:

Source: https://habr.com/ru/post/256097/


All Articles