Download MPMediaItem music from cloud
Asked Answered
C

1

6

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 ?

Cambell answered 15/5, 2017 at 11:35 Comment(0)
D
1

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
}];
Deeply answered 10/7, 2018 at 13:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.