fvisticot
fvisticot

Reputation: 8536

Download MPMediaItem music from cloud

MPMediaPickerController returns a MPMediaItem

If a local url is returned it is possible to play the sound.

If the music has not been downloaded locally, the assetURL is null.

How to download the MPMediaItem music locally ?

Upvotes: 6

Views: 520

Answers (1)

AMGuru
AMGuru

Reputation: 116

Apple does not provide API to trigger MPMediaItem download. However you can trigger downloading by playing it.

// init a system music player
MPMusicPlayerController *MPPlayer = [MPMusicPlayerController systemMusicPlayer];

// set play queue with the MPMediaItem you got
[MPPlayer setQueueWithItemCollection:[MPMediaItemCollection collectionWithItems:@[theMPMediaItemYouGot]]];

// prepare to play it
[MPPlayer prepareToPlayWithCompletionHandler:^(NSError *error){
if ( error ){
...
}
// success playing
}];

Upvotes: 1

Related Questions