0

我正在尝试获取 iphone 播放列表中歌曲的标题。

我努力了:

MPMediaQuery *playlistsQuery = [MPMediaQuery songsQuery];
NSArray *list = [[NSArray alloc] initWithArray:[playlistsQuery colkections]; 
MPMediaItem *song = [list objectAtIndex:position];
NSString *title = [song valieForProperty:MPMediaItemPropertyTitle];
NSLog(@"%@", title);

而这个称号又回来了"(null)"。该数组返回 50 个 itens,即我 iphone 中音乐的数量

4

3 回答 3

1

可能是,这对你有用。这里的“播放列表”是 NSArray。

playlistsQuery = [MPMediaQuery playlistsQuery];
    playlists = [playlistsQuery collections];
    NSArray *playlistsss = [myPlaylistsQuery collections];
    for (MPMediaPlaylist *playlist in playlistsss) {
        NSLog (@"%@", [playlist valueForProperty: MPMediaPlaylistPropertyName]);
        NSArray *songs = [playlist items];

        for (MPMediaItem *song in songs) {

            NSString *songTitle =[song valueForProperty: MPMediaItemPropertyTitle];
            NSString *str_artistName =[song valueForProperty: MPMediaItemPropertyArtist];
            NSLog(@"teh artist name is --->%@",str_artistName);
            playlists=[song valueForProperty: MPMediaItemPropertyTitle];
            NSLog(@"the songs titles---->%@",array_playList);

        }
    }
于 2014-08-20T16:13:48.913 回答
0

它应该valueForProperty代替valieForProperty.

于 2012-12-06T08:58:57.677 回答
0

Apple 有一个名为AddMusic的示例代码,演示了 MPMediaPlayer 框架。查看此示例代码,可能会帮助您解决问题。

于 2012-10-27T13:57:24.807 回答