在cocoa touch 4.x中可以创建或编辑音乐播放列表到iphone / ipad的默认/捆绑音乐应用程序中吗?如果是的话,代码怎么样?
答案 0 :(得分:2)
最后,我找到了适用于iOS 9.3及更高版本的解决方案。您可以使用MPMediaLibrary来实现这一目标。
// Setup your playlist metadata
__auto_type metadata = [[MPMediaPlaylistCreationMetadata alloc] initWithName:@"Playlist Name"];
metadata.authorDisplayName = @"My app name";
metadata.descriptionText = @"Playlist description";
// Save it to get the same playlist next time
NSUUID *uuid = [NSUUID UUID];
// Items to add to your playlist
NSArray<MPMediaItem *> *mediaItems = self.items;
// Get or create your playlist in Apple Music
[[MPMediaLibrary defaultMediaLibrary] getPlaylistWithUUID:uuid creationMetadata:metadata completionHandler:^(MPMediaPlaylist * _Nullable playlist, NSError * _Nullable error) {
// Handle the error
NSLog(@"Got error — %@", error);
// You can add items to your playlist
[playlist addMediaItems:mediaItems completionHandler:^(NSError * _Nullable addError) {
// Handle the error
NSLog(@"finished! error — %@", addError);
}];
}];
答案 1 :(得分:0)
您可以通过创建MPMediaQuery
来访问iPod库(iPod Library Access Programming Guide)中的信息。这将允许您检索播放列表(使用MPMediaPickerControllerDelegate
),但我认为您无法创建播放列表,因为您只能获得只读访问权限(以及播放)。