【发布时间】:2012-11-07 10:21:39
【问题描述】:
这是我从应用程序目录播放 mp3 文件的代码,但由于某种原因它无法正常工作。租赁找出这个代码有什么问题!
-(IBAction)PlayLesson:(id)sender;
{
NSString *folderAndFile = @"/Users/alaaalfadhel/Library/Application Support/iPhone Simulator/5.1/Applications/1021CF5B-F664-4123-B9CB-529217225B74/Documents/file.mp3";
NSString *audioFilePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:folderAndFile];
NSURL *url = [NSURL fileURLWithPath:audioFilePath];
ofType:@"mp3"]];
AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[click play];
}
【问题讨论】:
-
在调用
initWithContentsOfURL:之前插入NSLog(@"Path: %@, URL: %@", audioFilePath, url);。它打印什么? -
路径:/Users/alaaalfadhel/Library/Application Support/iPhone Simulator/5.1/Applications/5515AFBA-1E7D-4B06-A62E-F6FDFD7DD7C7/Documents/Users/alaaalfadhel/Library/Application Support/iPhone Simulator /5.1/Applications/1021CF5B-F664-4123-B9CB-529217225B74/Documents/file.mp3, URL:file://localhost/Users/alaaalfadhel/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/5515AFBA-1E7D -4B06-A62E-F6FDFD7DD7C7/Documents/Users/alaaalfadhel/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/1021CF5B-F664-4123-B9CB-529217225B74/Documents/file.mp3