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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With