'재생'에 해당되는 글 1건

  1. 2011.05.13 [iPhone] 짧은 소리 재생
아이폰어플개발정보2011. 5. 13. 12:48

 

작성 후 테스트 할 때는 꼭 볼륨을 키워놓고 테스트 하세요... ^^;


Create a View Based iPhone Application

First, create a view based iPhone application in XCode and add a button to your view that will play the sound. If you need a refresher on how to use Interface Builder to hook up controls check out my article on adding a slider control.

Add the Audio Toolbox framework

Drag in the Audio Toolbox framework into your frameworks group in XCode. Here is a video on how to quickly add frameworks in XCode if you need it: Quick Tip: Adding Frameworks Painlessly in XCode. Remember that the framework will be all one word with the .framework extension, AudioToolbox.framework.

Add a short wav file to your project

I used the website Joe’s Original Wave Files for this demo and found a nice laser sound to use. You can also buy the rights to use sounds in apps that you want to sell from websites like iStockPhoto.

Use Audio Services to play the sound

To keep things simple I put all the code that you need to play the sound in an IBAction called “shoot”.

-(IBAction) shoot{
 //Get the filename of the sound file:
 NSString *path = [NSString stringWithFormat:@"%@%@",
       [[NSBundle mainBundle] resourcePath],
       @"/jad0007a.wav"];

 //declare a system sound id
 SystemSoundID soundID;

 //Get a URL for the sound file
 NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];

 //Use audio sevices to create the sound
 AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);

 //Use audio services to play the sound
 AudioServicesPlaySystemSound(soundID);
}

That is it – pretty simple way to add some cool effects to your app.



출처 : http://blog.naver.com/PostView.nhn?blogId=yell301&logNo=130097056899
Posted by 오늘마감

댓글을 달아 주세요