//app
// YYViewController.m函數
// 14-音效播放url
//.net
// Created by apple on 14-8-8.get
// Copyright (c) 2014年 yangyong. All rights reserved.it
//io
#import "YYViewController.h"event
#import <AVFoundation/AVFoundation.h>class
@interface YYViewController ()import
@implementation YYViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//1.得到音效文件的全路徑
NSURL *url=[[NSBundle mainBundle]URLForResource:@"buyao.wav" withExtension:nil];
//2.加載音效文件,建立音效ID(SoundID,一個ID對應一個音效文件)
SystemSoundID soundID=0;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &soundID);
//把須要銷燬的音效文件的ID傳遞給它既可銷燬
//AudioServicesDisposeSystemSoundID(soundID);
//3.播放音效文件
//下面的兩個函數均可以用來播放音效文件,第一個函數伴隨有震動效果
AudioServicesPlayAlertSound(soundID);
//AudioServicesPlaySystemSound(<#SystemSoundID inSystemSoundID#>)
}