大家好我正在处理一个记录用户声音并将其保存到NSDocumentDirectory的应用程序.数据文件保存得很好.但问题是我想播放这些文件.我正在使用表视图来填充它NSDocumentDirectory中的文件数量.但是该表只显示当前声音文件的一个单元格.我在某处做错了请帮助我.我正在使用此代码进行播放.
-(void)PlayAudio
{
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(@"strffdsa %@",documentsDirectory);
NSURL *fileURL = [NSURL fileURLWithPath:recorderFilePath];
player = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error: nil];
player.numberOfLoops = 0;
//[fileURL release];
[player play];
[player setDelegate: self];
}
Run Code Online (Sandbox Code Playgroud)
其中,recorderFilePath是文件的路径.每次在NSDate frmattor的帮助下,路径都是新的.但是没有得到如何使用驻留在DocumentDirectory中的所有文件填充表视图.
请帮助我......我是这项技术的新手.
在此先感谢所有........
NP *_*ete 13
使用枚举器简化迭代文档目录以搜索音乐文件.
//Use an enumerator to store all the valid music file paths at the top level of your App's Documents directory
NSDirectoryEnumerator *directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:documentsDirectory];
for (NSString *path in directoryEnumerator)
{
//check for all music file formats you need to play
if ([[path pathExtension] isEqualToString:@"mp3"] || [[path pathExtension] isEqualToString:@"aiff"] )
{
[myMusicFiles addObject:path];
}
}
//the NSArray 'myMusicFiles' will be the datasource for your tableview
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4190 次 |
| 最近记录: |