gpt4 book ai didi

iphone - AVAudioPlayer 的问题

转载 作者:太空狗 更新时间:2023-10-30 03:34:09 25 4
gpt4 key购买 nike

我是 iPhone 开发的新手。

我想在点击 UIButton 时播放声音。我尝试了以下方法:

ViewController.h:

@interface JahrenzeitenViewController : UIViewController <AVAudioPlayerDelegate> {

UIButton *button_PlaySound;
AVAudioPlayer *audioPlayer;
}

@property (nonatomic, retain) IBOutlet UIButton *button_PlaySound;

ViewController.m

- (IBAction)playSound {

//[audioPlayer release];
//audioPlayer = nil;

NSString *audioFilePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"wav"];
NSURL *audioFileURL = [NSURL fileURLWithPath:audioFilePath];
NSError *error = nil;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:&error];
[audioPlayer setDelegate:self];
[audioPlayer prepareToPlay];
[audioPlayer play];
if (audioPlayer == nil)
NSLog(@"Error playing sound. %@", [error description]);
else
[audioPlayer play];

如果我尝试运行应用程序,我会收到以下错误:

Undefined symbols for architecture i386: "_OBJC_CLASS_$_AVAudioPlayer", referenced from: objc-class-ref in JahrenzeitenViewController.o ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status

我也试过改线

audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:&error];

audioPlayer = [audioPlayer initWithContentsOfURL:audioFileURL error:&error];

然后我没有得到上面的错误,但它仍然没有播放,我在“playSound”-Method 中从我的 NSLog 得到了 DebugMessage:

Error playing sound. (NULL)

我希望你能帮助我。提前谢谢你:)

最佳答案

您需要将AVFoundation 框架添加到您的项目中。 (右键单击您的主要目标,然后添加现有框架)。

关于iphone - AVAudioPlayer 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5376437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com