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];

上一篇:Cookie 和Session


下一篇:[MVC] 深入浅出Spring MVC