//
// ViewController.m
// 静音键播放音乐-IOS
//
// Created by Weblogic on 16/4/1.
// Copyright © 2016年 Weblogic. All rights reserved.
//
/*
*
*注意:如果播放失败,请注意检查:
* 1,是否将AudioPlayer声明为全局变量;
* 2,本地音乐文件是否存在,路径是否正确;
* 3,初始化NSURL时,是否使用的是 fileURLWithPath . (如果错用 URLWithString 也是会造成初始化失败的)
*/
#import "ViewController.h"
@interface ViewController ()<AVAudioRecorderDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *tmp=[[NSBundle mainBundle].resourcePath stringByAppendingPathComponent:@"笛声.mp3"];
NSLog(@"%@",tmp);
NSURL *moveMP3=[NSURL fileURLWithPath:[[NSBundle mainBundle].resourcePath stringByAppendingPathComponent:@"笛声.mp3"]];
NSError *err=nil;
self.movePlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:moveMP3 error:&err];
self.movePlayer.volume=1.0;
[self.movePlayer prepareToPlay];
if (err!=nil) {
NSLog(@"move player init error:%@",err);
}else {
[self.movePlayer play];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end