Ios 如何使用(iAction)播放声音:(id)发送方播放声音
我试着简单地用按钮放置声音。由于缺乏理解,我已经到达了一个停止点。我试了大约4个小时试图解决这个问题,但没有找到任何结果。有人能帮我吗?我收到错误,“使用未声明的标识符'soundFile”,这是我的.m文件Ios 如何使用(iAction)播放声音:(id)发送方播放声音,ios,objective-c,xcode,macos,audio,Ios,Objective C,Xcode,Macos,Audio,我试着简单地用按钮放置声音。由于缺乏理解,我已经到达了一个停止点。我试了大约4个小时试图解决这个问题,但没有找到任何结果。有人能帮我吗?我收到错误,“使用未声明的标识符'soundFile”,这是我的.m文件 // // FirstViewController.m // simpleApp // // Created by Abby Russell on 11/29/13. // Copyright (c) 2013 Abby Russell. All rights reserved.
//
// 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
谢谢你们这么聪明的人 声音文件需要是声音文件的NSString路径。看起来您刚刚输入了文本“soundFile”,实际上没有任何名为soundFile的NSString。尝试用“路径”替换声音文件 这成功了!哦,天哪,我觉得问这个问题很傻。也许我应该呼吸点新鲜空气。。。非常感谢,没有必要否决投票。这是初学者提出的合理问题。还记得你开始的时候是什么样子吗。