我想播放一个mp3文件以外的mainBundle (从任何位置的硬盘驱动器)。
那是我的尝试(不起作用):
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];发布于 2013-09-30 15:37:57
您可以使用NSSound。
NSURL* file = [NSURL fileURLWithPath:@"/Music/1.mp3"];
NSSound *sound = [[NSSound alloc] initWithContentsOfURL:file byReference:NO];
[sound play];https://stackoverflow.com/questions/19096574
复制相似问题