Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。












想改善这个问题吗?更新问题,以便将其作为on-topic用于堆栈溢出。

6年前关闭。



Improve this question




我正在尝试简单地通过按钮放置声音。由于缺乏理解,我已经到达了一个停顿点。我尝试了大约4个小时来尝试解决此问题,但无济于事。有人能帮我吗?我收到了错误消息,“。未声明标识符'soundFile 的使用'”这是我的.m文件。
//
//  FirstViewController.m
//  simpleApp
//
//  Created by Abby Russell on 11/29/13.
//  Copyright (c) 2013 Abby Russell. All rights reserved.
//

#import "FirstViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)playsound:(id)sender {
    SystemSoundID soundID;
    NSString *buttonName=[sender currentTitle];
    NSString *path = [[NSBundle mainBundle] pathForResource:buttonName ofType:@"wav"];

    AudioServicesCreateSystemSoundID((__bridge CFURLRef)
                                     [NSURL fileURLWithPath: soundFile], &
                                     soundID;
    AudioServicesPlaySystemSound(soundID);


}
@end

非常感谢聪明的人!

最佳答案

soundFile必须是声音文件的NSString路径。看来您刚刚输入文本“soundFile”而实际上没有任何名为soundFile的NSString。尝试用“path”替换soundFile。

09-10 09:31