引入音频,视频库
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()
@property(nonatomic,strong) AVPlayer *playler;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//播放音乐
AVAudioSession *session = [AVAudioSession sharedInstance];//他是一个单例,管理音视频的
[session setActive:YES error:nil];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
//资源
NSBundle *boudle =[NSBundle mainBundle];
// url 路径
NSURL *url = [boudle URLForResource:@"冰雨" withExtension:@"mp3"];
_playler = [[AVPlayer alloc]initWithURL:url];//初始化播放对像
[_playler setVolume:1.0];//设置y声音大小,1.0为音量最大
[_playler play];
}