通过第三方应用程序播放苹果音乐歌曲

编程入门 行业动态 更新时间:2024-10-25 04:16:03
本文介绍了通过第三方应用程序播放苹果音乐歌曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 iTunes Search API 在我的应用程序中播放 previewUrl 歌曲

I am using iTunes Search API in my application & playing the previewUrl songs from within the application by using

AVPlayer

AVPlayer

如果用户想播放完整的歌曲,他/她需要从iTunes商店购买这首歌,然后他/她才能播放完整的歌曲。申请。

If user wants to play the full song, he/she needs to purchase the song from iTunes Stores only then can he/she play the full song from application.

随着苹果发布 Apple Music &给予每个人的审判或正式会员资格。允许播放完整的歌曲,是否可以使用预览播放 Apple Music 完整歌曲

As apple released the Apple Music & giving the trial OR full membership to every one & allowing to play the full songs, is it possible to play Apple Music full songs from my application Like Previewurl by using

avplayer或mpmovieplayercontroller

avplayer or mpmovieplayercontroller

推荐答案

@Ted Hosmann感谢您的回复。

@"Ted Hosmann" Thanks for reply .

我想分享一些代码来自此处

I would like to share some code from here

viewcontroller.m

@import StoreKit; -(void) submitAppleMusicTrackWithProductID: (NSString *) productID // productID in US is the last numbers after i= in the share URL from Apple Music { NSLog(@"submitAppleMusic has been called for productID: %@", productID); [SKCloudServiceController requestAuthorization:^(SKCloudServiceAuthorizationStatus status) { NSLog(@"status is %ld", (long)status); SKCloudServiceController *cloudServiceController; cloudServiceController = [[SKCloudServiceController alloc] init]; [cloudServiceController requestCapabilitiesWithCompletionHandler:^(SKCloudServiceCapability capabilities, NSError * _Nullable error) { NSLog(@"%lu %@", (unsigned long)capabilities, error); if (capabilities >= SKCloudServiceCapabilityAddToCloudMusicLibrary) { NSLog(@"You CAN add to iCloud!"); [[MPMediaLibrary defaultMediaLibrary] addItemWithProductID:productID completionHandler:^(NSArray<__kindof MPMediaEntity *> * _Nonnull entities, NSError * _Nullable error) { NSLog(@"added id%@ entities: %@ and error is %@", productID, entities, error); NSArray *tracksToPlay = [NSArray arrayWithObject:productID]; [[MPMusicPlayerController systemMusicPlayer] setQueueWithStoreIDs:tracksToPlay]; [[MPMusicPlayerController systemMusicPlayer] play]; [self performSelectorOnMainThread:@selector(getInfoFromAddedAppleMusicTrack:) withObject:productID waitUntilDone:YES]; }]; } else { NSLog(@"Blast! The ability to add Apple Music track is not there. sigh."); } }]; }]; } -(void) getInfoFromAddedAppleMusicTrack: (NSString *) productID { NSLog(@"FYI - musicplayer duration is: %f", [[[MPMusicPlayerController systemMusicPlayer] nowPlayingItem] playbackDuration]); //need to check for both the nowPlaying item and if there is a reported playbackDuration, as there is a variable time between a storeMediaItema and a concreteMediaItem if (([[MPMusicPlayerController systemMusicPlayer] nowPlayingItem]) && ([[[MPMusicPlayerController systemMusicPlayer] nowPlayingItem] playbackDuration])) { NSLog(@"Media item is playing: %@",[[MPMusicPlayerController systemMusicPlayer] nowPlayingItem]); NSLog(@"appleProductIDURL: %@",productID); NSLog(@"Ending time: %d",[[[[MPMusicPlayerController systemMusicPlayer] nowPlayingItem] valueForProperty:MPMediaItemPropertyPlaybackDuration] intValue]); NSLog(@"Track Name: %@", [[[MPMusicPlayerController systemMusicPlayer] nowPlayingItem] valueForProperty:MPMediaItemPropertyTitle]); NSLog(@"Artists Name: %@", [[[MPMusicPlayerController systemMusicPlayer] nowPlayingItem] valueForProperty:MPMediaItemPropertyArtist]); } else { NSLog(@"seems the track is not fully loaded so try again in 1 second"); [self performSelector:@selector(getInfoFromAddedAppleMusicTrack:) withObject:productID afterDelay:1.0]; // count loops and jump out if something is wrong - I've never seen more that 7 seconds needed } }

更多推荐

通过第三方应用程序播放苹果音乐歌曲

本文发布于:2023-11-27 03:32:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636395.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第三方   应用程序   苹果   歌曲   音乐

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!