我有一个要求,我需要在应用程序中搜索和播放歌曲,所以我在我的应用程序中使用iTunes Search API来播放歌曲,但它无法播放。
请从 iTunes 搜索 API 中找到请求和响应参数。
Request : https://itunes.apple.com/search?term=A+R+Rahman&entity=song&country=in&limit=1
Response :
{
resultCount = 1;
results = (
{
artistId = 3249567;
artistName = "A. R. Rahman, Javed Ali & Mohit Chauhan";
artistViewUrl = "https://itunes.apple.com/in/artist/a-r-rahman/id3249567?uo=4";
collectionId = 1123241840;
collectionViewUrl = "https://itunes.apple.com/in/album/kun-faya-kun/id1123241840?i=1123241921&uo=4";
country = IND;
currency = INR;
discCount = 1;
discNumber = 1;
isStreamable = 1;
kind = song;
previewUrl = "http://audio.itunes.apple.com/apple-assets-us-std-000001/AudioPreview20/v4/00/a6/82/00a68217-deef-d90c-d63b-1fab15acb840/mzaf_8630030048415899809.plus.aac.p.m4a";
primaryGenreName = Bollywood;
releaseDate = "2011-09-30T07:00:00Z";
trackCensoredName = "Kun Faya Kun";
trackCount = 14;
trackExplicitness = notExplicit;
trackId = 1123241921;
trackName = "Kun Faya Kun";
trackNumber = 4;
trackPrice = 15;
trackTimeMillis = 470500;
trackViewUrl = "https://itunes.apple.com/in/album/kun-faya-kun/id1123241840?i=1123241921&uo=4";
wrapperType = track;
}
);
}
我正在使用trackId并将其传递给setQueueWithStoreIDs
.MPMusicPlayerController
注意:我也尝试过previewUrl、trackViewUrl、 collectionId和collectionViewUrl但没有成功。
我还完成了检查设备播放Apple Music歌曲的授权和功能的过程。
请找到下面的完整代码。
[SKCloudServiceController requestAuthorization:^(SKCloudServiceAuthorizationStatus status) {
if(status == SKCloudServiceAuthorizationStatusAuthorized) {
SKCloudServiceController *cloudServiceController = [[SKCloudServiceController alloc] init];
[cloudServiceController requestCapabilitiesWithCompletionHandler:^(SKCloudServiceCapability capabilities, NSError * _Nullable error) {
if (capabilities == SKCloudServiceCapabilityMusicCatalogPlayback) {
NSLog(@"You can play the song");
[[MPMusicPlayerController systemMusicPlayer] setQueueWithStoreIDs:@[@"1123241921"]];
[[MPMusicPlayerController systemMusicPlayer] prepareToPlayWithCompletionHandler:^(NSError * _Nullable error) {
NSLog(@"Error : %@",error.description);
}];];
}
else {
NSLog(@"You did not have the capability for playing the Apple Music");
}
}];
}
else {
NSLog(@"You do not authorize for Apple Music");
}
}];
播放歌曲时出错。
错误域=MPErrorDomain 代码=4“(空)”
请指导我需要什么实施以及这是否可行。
从下面的链接下载应用程序的源代码。 https://www.dropbox.com/s/2n5110qmaqpvkdf/TestAppleMusic.zip?dl=0