iOS用AVAudioPlayer播放m4a音频

时间:2014-09-05 17:53:21   收藏:0   阅读:2601

音频文件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]; 

原文:http://www.cnblogs.com/JayK/p/3958267.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!