1. 在根目录的第六项(build phases)的第三项(link binary With libaries)里添加AVFoundation.framework文件
2. 再导入#import <AVFoundation/AVFoundation.h>
//1. 添加属性:@property(nonatomic,strong)AVPlayer *player;
// 2. 将MP3文件拽到当前工程,用bundle扫描当前工程的文件找到MP3文件
- (void)viewDidLoad {
[super viewDidLoad];
//播放本地音乐
//获取音乐文件的路径
NSString *path = [[NSBundle mainBundle]pathForResource:@"frxz" ofType:@"mp3"];
NSURL *url = [NSURL fileURLWithPath:path];
self.player = [AVPlayer playerWithURL:url]; //+1
[self.player play];
//创建 音乐播放类
// AVPlayer *play = [AVPlayer playerWithURL:url]; //网上下载的文件
// [play play];