我使用以下代码在TableView中获得歌曲标题:
MPMediaQuery *everything = [[MPMediaQuery alloc] init];
NSArray *itemsFromGenericQuery = [everything items];
for (MPMediaItem *song in itemsFromGenericQuery) {
NSString *songTitle = [song valueForProperty: MPMediaItemPropertyTitle];
[songTitleArray addObject:songTitle];
}
现在我想在tableView中播放那首歌我在同一个ViewController中添加了两个按钮播放和停止如何使用Title播放。
答案 0 :(得分:0)
要播放歌曲,您可以执行以下操作:
SELECT tableA.id,
title,
date_created,
date_completed,
percent_complete,
complete,
COALESCE(COUNT(tableC.id), 0) AS 'total_ids'
FROM tableA
INNER JOIN tableB
ON tableA.id = tableB.id
LEFT JOIN tableC
ON tableA.id = tableC.id
WHERE submitted = '0' AND tableB.user = 'user'
GROUP BY tableA.id
ORDER by title ASC
通过MPMusicPlayerController *controller = [MPMusicPlayerController iPodMusicPlayer];
MPMediaItemCollection *collection = [[MPMediaItemCollection alloc] initWithItems:arrayOfMediaItems];
MPMediaItem *item = [collection representativeItem];
[controller setQueueWithItemCollection:collection];
[controller setNowPlayingItem:item];
[controller prepareToPlay];
[controller play];
选择播放后,您还可以使用AVPlayer
播放歌曲:
MPMediaPickerController