customButtonViewController.h
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
@interface customButtonViewController : UIViewController {
AVAudioPlayer *bang;
}
-(IBAction) button1;
-(IBAction) button2;
@end
customButtonViewController.m
#import "customButtonViewController.h"
@implementation customButtonViewController
-(IBAction) button1{
NSString *path = [[NSBundle mainBundle] pathForResource:@"bang1" ofType:@"mp3"];
if(bang) [bang release];
bang = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[bang play];
}
-(IBAction) button2{
NSString *path = [[NSBundle mainBundle] pathForResource:@"bang2" ofType:@"mp3"];
if(bang) [bang release];
bang = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[bang play];
}
-(IBAction)play{
[bang play];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
詳解 Objective-C 2.0 改訂版: 荻原 剛志 | iPhoneプログラミングUIKit詳解リファレンス: 所 友太, 京セラコミュニケーションシステム株式会社 | iPhone SDK アプリケーション開発ガイド: Jonathan Zdziarski, 近藤 誠 (監訳), 武舎 広幸, 武舎 るみ |
0 コメント:
コメントを投稿