首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OS在mp3之外播放mainBundle

OS在mp3之外播放mainBundle
EN

Stack Overflow用户
提问于 2013-09-30 14:18:17
回答 1查看 176关注 0票数 0

我想播放一个mp3文件以外的mainBundle (从任何位置的硬盘驱动器)。

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

代码语言:javascript
复制
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];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-30 15:37:57

您可以使用NSSound

代码语言:javascript
复制
NSURL* file = [NSURL fileURLWithPath:@"/Music/1.mp3"];
NSSound *sound = [[NSSound alloc] initWithContentsOfURL:file byReference:NO];
[sound play];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19096574

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档