音频文件不会播放?

时间:2014-05-19 19:13:49

标签: objective-c xcode

我的音频文件无法播放。

- (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"

1 个答案:

答案 0 :(得分:1)

*players未被保留。把它变成一个财产。并确保将音频文件复制到Documents目录中。