Playing music within your app

We released Mapping Tonal Harmony Pro 6 a few days ago.

One of the best features in the app is to be able to load and play tracks from the iPad’s Library. The process is pretty straight forward but we’ve encounter a few unexpected problems in the process.

We wanted the user to be able to pick a track from their library and load it into the app.
In order to do this the best option is to use the mediaPicker
This is how you call it:
– (void)chooseASongFromYourLibraryOnView:(UIViewController*) pViewController {
    MPMediaPickerController *picker =
    [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
    
    picker.delegate                     = self;
    picker.allowsPickingMultipleItems   = NO;
    picker.prompt                       = NSLocalizedString (@”Select any song from the list”, @”Choose one song only”);
   
    curPickerController=picker;
    [pViewController presentViewController:picker animated:YES completion:nil];
}

Here’s the function called after the user has picked a track
– (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
    [myPlayer setQueueWithItemCollection:mediaItemCollection];
    NSArray *itemsFromGenericQuery = [mediaItemCollection items];
    self.pickedMediaItemSong=[itemsFromGenericQuery objectAtIndex:0];
    [curPickerController dismissViewControllerAnimated:NO completion:nil];

}

So, we saved the item in pickedMediaItemSong

To play and draw the wave-form representation of the track you need to get the song as a AVURLAsset

asset = [[AVURLAsset alloc] initWithURL:[self.pickedMediaItemSong valueForProperty:MPMediaItemPropertyAssetURL] options:nil];

But, the app would not play items from the cloud

Solution: filter the items shown by the mediapicker to non-cloud items only
add:     picker.showsCloudItems=NO; before you present the ViewController

Now, everything seemed to work fine for a while but every now and then the MPMediaItemPropertyAssetURL would retrun NULL (the asset would end up being nil). And it only happened with a few tracks in our library.

Why? Becuase those tracks had DRM!!

Here’s what Apple Says:

About iTunes Plus

Learn more about iTunes Plus, the high-quality format of songs and music videos available through the iTunes Store.

iTunes Plus refers to songs and music videos in high quality AAC format that don’t have Digital Rights Management (DRM).

All songs and music videos now for sale in the iTunes Store are iTunes Plus. In some cases, if you previously bought music with DRM from the iTunes Store, you can download the higher quality, DRM-free versions of your songs with a subscription to iTunes Match. The tracks must show as Matched or Purchased in the iCloud Status column in your iTunes library, and the same album or song must still be available in the iTunes Store.

To upgrade your music to iTunes Plus, follow these steps on your computer:

  1. Open iTunes.
  2. If you’re not already, sign in with your Apple ID and password.
  3. Click the My Music tab at the top of iTunes.
  4. Click the song or album you want to upgrade.
  5. Press the delete key on your keyboard. In the message that appears, click Move to Trash.
  6. Click the iTunes Store tab at the top of iTunes.
  7. Under Quick Links on the right-hand side of iTunes, click Purchased.
  8. Click Music in the upper-right corner of iTunes.
  9. Find the song or album you want to upgrade.
  10. Click the iCloud Download icon   on the song or album to download the new version.
Advertisement

2 comments

  1. Pingback: Playing music within your app | mDecks Music

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s