我正在尝试播放设备上保存的音频,但已将其放置在路径中,但无法正常工作
任何人都可以帮忙吗?
NSURL *url = [NSURL fileURLWithPath:@"/Users/Luna/Library/ApplicationSupport/iPhone Simulator/5.0
/Applications/E3D65190-9DE0-4C60-A2F8-0948970A1788/Documents/Sound1.caf"];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = -1;
[audioPlayer play];
最佳答案
NSFileManager* manager = [[NSFileManager alloc] init];
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSLog(@"Documents directory: %@",[manager contentsOfDirectoryAtPath:documentsDirectory error:&error]);
NSString* yourFile =[documentsDirectory() stringByAppendingPathComponent:@"Sound1.caf"];
if ([manager fileExistsAtPath:yourFile]) {
NSLog(@"Audio Exists");
}
上面的代码将输出您的文档目录内容..并且最后还应记录音频存在 ...尝试此操作,让我们知道您将获得什么输出
关于objective-c - 在xcode中播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9719856/