我的音频文件无法播放。
- (IBAction)playTapped:(id)sender {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* foofile = [documentsDirectory stringByAppendingPathComponent:fileNameStringAudio];
NSLog(@"TRYING TO PLAY %@", foofile);
NSURL *murl = [NSURL fileURLWithPath :foofile];
NSError *error;
AVAudioPlayer *players = [[AVAudioPlayer alloc] initWithContentsOfURL:murl error:&error];
players.numberOfLoops = 1;
[players play];
}
注意:我的NSLog结果是"尝试播放/var/mobile/Applications/XXXXXXXXXXXX/Documents/1400512882.m4a"
答案 0 :(得分:1)
*players
未被保留。把它变成一个财产。并确保将音频文件复制到Documents目录中。