Xcode上iPhone的UISoundboard?
可能重复: 嗨,我正在为我的iPhone应用程序创建一个音板,但我的代码中不断出现错误等。你们可以编辑它吗?或者你们知道音板的更好的代码吗?我使用的是Xcode 4.2,我是新的,所以请说清楚谢谢你们的时间,我真的很感激 我认为没有错误Xcode上iPhone的UISoundboard?,iphone,ios,xcode,xcode4.2,Iphone,Ios,Xcode,Xcode4.2,可能重复: 嗨,我正在为我的iPhone应用程序创建一个音板,但我的代码中不断出现错误等。你们可以编辑它吗?或者你们知道音板的更好的代码吗?我使用的是Xcode 4.2,我是新的,所以请说清楚谢谢你们的时间,我真的很感激 我认为没有错误 #import <UIKit/UIKit.h> #import <AudioToolbox/AudioToolbox.h> @interface ViewController : UIViewController { } -(I
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
@interface ViewController : UIViewController {
}
-(IBAction)sound1:(id)sender;
@end
谢谢,希望您能帮助我。音频工具箱对于您的需要来说可能有点太低级了。。。通过使用AVFoundation,您可能会使您的生活更加轻松;具体来说,就是课堂 在您的实施中:
#import <AVFoundation/AVFoundation.h>
- (void)viewDidLoad
{
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
NSURL *soundURL = [NSURL fileURLWithPath:soundPath];
NSError *error = nil;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error];
if ( ! player )
{
NSLog(@"%@", [error description]);
}
else
{
[player prepareToPlay];
[player play];
}
}
注意,我在这里没有做任何内存管理。此外,如果您需要一次播放多个声音,您可以创建AVAudioPlayer的其他实例,也可以查看OpenAL库。。。它有一个很好的包装器。@implementation-viewController缺少@end?在方法原型-IBActionsound1之后需要{预期标识符AudioservicecreatesystemsoundIDsoundfileURLRef,&soundID;请在您的实现文件中实现@end。方法原型也应该是这样的。-IBActionsound1:idsender;您有没有可能为我编辑它,或者只是复制和粘贴它?您好,我只想在每个视图控件中播放大约10个声音片段我是否只需复制代码并将其放入.m中?我在.h中放入了什么?buddy?和内存管理?谢谢您的时间。
#import <AVFoundation/AVFoundation.h>
- (void)viewDidLoad
{
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
NSURL *soundURL = [NSURL fileURLWithPath:soundPath];
NSError *error = nil;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error];
if ( ! player )
{
NSLog(@"%@", [error description]);
}
else
{
[player prepareToPlay];
[player play];
}
}