播放本地音乐
获取音乐路径
NSString *path =@"file:///Users/tangge/Desktop/day02/资料/拳皇PNG素材/sound/dazhao.mp3";
转换成url
path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; //中文编码
NSURL *url = [NSURL URLWithString:path];
实例化AVAudioPlayer对象
AVAudioPlayer *player =[[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[player play]; //播放
网友评论