Skip to content

Instantly share code, notes, and snippets.

@layneios
Last active September 7, 2017 07:14
Show Gist options
  • Save layneios/c2850ff9f6339aee7b17b6814e520eab to your computer and use it in GitHub Desktop.
Save layneios/c2850ff9f6339aee7b17b6814e520eab to your computer and use it in GitHub Desktop.
OC 获取音乐列表
#import <MediaPlayer/MediaPlayer.h>

+ (void)getMusicList {
    NSMutableArray *musicList = [[NSMutableArray alloc] init];
    MPMediaQuery *videoQuery = [[MPMediaQuery alloc] init];
    NSArray<MPMediaItem *> *mediaItems = videoQuery.items;
    for (MPMediaItem *mediaItem in mediaItems) {
        if (mediaItem.title) {
            [musicList addObject:mediaItem.title];
        }
    }
    NSLog(@"%@", musicList);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment