AVAudioPlayer的问题 [英] Problems with AVAudioPlayer

查看:141
本文介绍了AVAudioPlayer的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone-Development的新手。

I'm new to the iPhone-Development.

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

I want to play a Sound when an UIButton is tapped. I tried the following:

ViewController.h:

ViewController.h:

@interface JahrenzeitenViewController : UIViewController <AVAudioPlayerDelegate> {

    UIButton *button_PlaySound;
    AVAudioPlayer *audioPlayer;
}

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

ViewController.m

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];

如果我尝试运行App,我会收到以下错误:

If I try to run the App, I get the following error:


架构i386的未定义符号:
_ OBJC_CLASS _ $ _ AVAudioPlayer,引自:
objc-class-ref in JahrenzeitenViewController.o
ld:找不到架构的符号i386
collect2:ld返回1退出状态

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];

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

Then I don't get the error above, but its still not playing and i get the DebugMessage from my NSLog in the "playSound"-Method:


播放声音时出错。 (NULL)

Error playing sound. (NULL)

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

I hope you can help me. Thank you in advance :)

推荐答案

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

You need to add the AVFoundation framework to your project. (right-click on your main target then add existing framework).

这篇关于AVAudioPlayer的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆