0

我想在 mainBundle 之外播放一个 mp3 文件(从硬盘上的任何位置)。

那是我的尝试(不起作用):

NSString* theFileName = [filepath stringByDeletingPathExtension];

NSLog(@"%@", theFileName); // -> /Volumes/Data%20HD/Music/iTunes/Music/Linkin%20Park/Hybrid%20Theory/01%20Papercut

NSBundle *mainBundle = [NSBundle mainBundle];
NSString *filePath2 = [mainBundle pathForResource:theFileName ofType:@"mp3" ];
NSData *fileData = [NSData dataWithContentsOfFile:filePath2];
NSError *error2;
audioPlayer = [[AVAudioPlayer alloc] initWithData:fileData error:&error2];
[audioPlayer play];
4

1 回答 1

0

您可以使用NSSound

NSURL* file = [NSURL fileURLWithPath:@"/Music/1.mp3"];
NSSound *sound = [[NSSound alloc] initWithContentsOfURL:file byReference:NO];
[sound play];
于 2013-09-30T15:37:57.503 回答