【发布时间】:2013-01-01 10:49:10
【问题描述】:
我正在尝试在 iOS 中播放从UITableView 中选择的Media Item。
我正在使用MediaQuery,并从我的UITableView 的iPod 库中加载了歌曲列表。
但我不知道如何播放来自UITableView 的选定歌曲。
我知道非常基本的简单 AudioPlayer 以及以下代码。
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: @"sample"
ofType: @"mp3"];
NSURL *fileURL = [[[NSURL alloc] initFileURLWithPath: soundFilePath] autorelease];
self.player = [[[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error: nil]
autorelease];
用于ContentOfURL,已位于资源中。无需从 iPod 库中检索歌曲。
这是我的 CellForRowAtIndexPath 方法代码
MPMediaItemCollection *songs = [self.arrayOfSongs objectAtIndex:indexPath.row];
cell.textLabel.text = [songs.items[0] valueForProperty:MPMediaItemPropertyTitle];
现在我正在尝试使用 MediaQuery 播放从 iPod 库中检索到的歌曲以及从 UITableView 中选择的歌曲
那么我怎样才能从UITableView 中选择的 iPod 库中检索 URL 并播放歌曲?
感谢您的阅读。
【问题讨论】:
-
没人回答我的问题吗?
-
请在 indexpath 方法中发布你的 cell for row,你需要在 indexpath 方法中实现 didselect 行
-
是的,我也想知道代码应该写在 didselectedrow 方法中。如何播放选定的歌曲?
标签: ios cocoa-touch mpmediaitem