Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play Apple Music files (even "available offline" ones) with AVPlayer?

Is it possible to play Apple Music files—even the "available offline" ones—with AVPlayer? I've tried the following code to retrieve the URL, but it returns nil:

- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection{
    [mediaPicker dismissViewControllerAnimated:YES completion:nil];

    NSURL *thisURL=[[[mediaItemCollection items] firstObject] valueForProperty:MPMediaItemPropertyAssetURL];
...

Thanks for reading.

EDIT: Discussions on the Apple Developer forum suggest this may not be possible, unless AVPlayer is not used. But then that prevents audio processing, so not an option unfortunately.

like image 634
Rogare Avatar asked Sep 29 '15 09:09

Rogare


Video Answer


1 Answers

Apple Music assets are DRM protected, as expected. Additionally, offline songs do not have a valid Asset URL you can use with AVPlayer. The only way to play Apple Music songs is by using MusicKit with MPMusicPlayerController, or Apple Music API available in iOS 11.

like image 178
donkey Avatar answered Nov 11 '22 16:11

donkey