简体   繁体   中英

MPMusicPlayerController play not working with Apple Music

I am using the new Apple Music API with MPMusicPlayerController but play method doesn't work in the first time called, but after the second or third time.

My code is the following:

MPMusicPlayerController *appleMusicPlayer = /*access instantiated player*/;
[appleMusicPlayer setQueueWithStoreIDs:@[url]];
[appleMusicPlayer play];

The player is instantiated as follows:

_appleMusicPlayer = [MPMusicPlayerController applicationMusicPlayer];
_appleMusicPlayer.repeatMode = MPMusicRepeatModeNone;
_appleMusicPlayer.shuffleMode = MPMusicShuffleModeOff;
[_appleMusicPlayer beginGeneratingPlaybackNotifications];

The url passed in setQueueWithStoreIDs method is a NSString with a country-specific valid iTunesID. I provide you with a screenshot of NSLog output of url after above play method is called.

的NSLog

Any help would be much appreciated.

Make sure url is a string of the store ID!

You can get that here: https://affiliate.itunes.apple.com/resources/documentation/itunes-store-web-service-search-api/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM