2012-05-13 81 views

回答

0

你可以用它來播放簡單的聲音。它使用AVFoundation框架,這將需要您添加AVFoundation到您的項目,並使用#import <AVFoundation/AVFoundation.h>

- (IBAction) myPlayAction { 
    AVAudioPlayer *data; 
    NSString *name = [[NSString alloc] initWithFormat:@"SoundName"]; 
    NSString *source = [[NSBundle mainBundle] pathForResource:name ofType:@"mp3"]; 
    if (data) { 
     [data stop]; 
     data = nil; 
    } 
    data=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: source] error:NULL]; 
    data.delegate = self; 
    [data prepareToPlay]; 
    [data play]; 
} 
相關問題