此特定功能的目的是能夠從表格視圖顯示和播放本地錄音。加載本地CAF文件中的代碼如下:加載本地音頻.caf文件,使用哪個對象? iOS
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadFileInformation];
}
- (void)loadFileInformation
{
items = [[NSMutableArray alloc] init];
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
for (int i = 0; i < [directoryContent count]; i++) [items addObject:[directoryContent objectAtIndex:i]];
[self.tableView reloadData];
}
隨着委託方法用於播放特定的文件,如下所示:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
avAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[[items objectAtIndex:indexPath.row] filePathURL] error:nil];
avAudioPlayer.delegate = (id)self;
[avAudioPlayer prepareToPlay];
[avAudioPlayer play];
}
然而,當這種方法被稱爲我得到一個錯誤:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString filePathURL]: unrecognized selector sent to instance 0x239420'
我只是想知道如果有人能指出我在正確的方向!當本地目錄的內容存儲在數組directoryContent
中時,每個元素的對象是什麼? NSData
?
非常感謝提前
感謝您的快速響應,NSLog(@「%@」,[NSURL fileURLWithPath:[items objectAtIndex:indexPath.row]]);''返回'363797875048.caf - file:// localhost /'和球員不起作用 – 2012-07-24 10:00:00