2012-01-15 5 views

答えて

5

ボタンサウンドのように短い音を再生するのは実際とても簡単です。ここに簡単な例があります。

あなたはAudioToolbox.frameworkバイナリ

SoundExampleViewController.hをリンクする必要があります。

#import <UIKit/UIKit.h> 
#import <AudioToolbox/AudioToolbox.h> 
@interface SoundExampleViewController : UIViewController{ 
    SystemSoundID mySoundID; 
} 
@end 

SoundExampleViewController.m:次に

#import "SoundExampleViewController.h" 
@implementation SoundExampleViewController 
- (void)viewDidLoad{ 
    [super viewDidLoad]; 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"SoundFileName" ofType:@"wav"]; 
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path],&mySoundID); 
} 
- (void)viewDidUnload{ 
    [super viewDidUnload]; 
    AudioServicesDisposeSystemSoundID(mySoundID); 
} 
@end 

あなたは、単に呼び出す再生する:AudioServicesPlaySystemSound(mySoundID);

+0

スウィートは、どうもありがとうございました。非常に簡単です。 –

+0

壮大な答え – Fattie

+0

AVAudioPlayerでメモリリークの問題を修正しました。ありがとうございます! –

関連する問題