iOS用AVAudioPlayer播放m4a音频

音频文件sound.m4a放到Supporting Files目录

引用头文件

#import <AVFoundation/AVFoundation.h>  

定义一个全局的属性:

@property (nonatomic, strong) AVAudioPlayer *player; //音频播放器

//初始化音频播放器

NSString *path = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"m4a"];

self.player = [[AVAudioPlayer alloc] initWithData:[NSData dataWithContentsOfFile:path] error:nil];

self.player.numberOfLoops = 1;

self.player.volume = 1.0;

 

//播放

[self.player play]; 

posted @ 2014-09-05 16:05  大强跑了  阅读(3663)  评论(0编辑  收藏  举报