gpt4 book ai didi

iphone - 使用按钮iPhone SDK进行简单的声音播放

转载 作者:行者123 更新时间:2023-12-03 00:10:31 25 4
gpt4 key购买 nike

单击按钮后,我已经尝试了数小时来播放简单的声音,但是我做不到。在尝试了几本教程之后,我在此链接中关注了一个:

http://www.mybringback.com/tutorial-series/1126/xcode-4-tutorial-ios-ipad-iphone-20-playing-sound-with-button/

这是.h文件:

#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
@interface soundTestViewController : UIViewController{

}
-(IBAction) playSound;

@end

这是.m文件:
#import "soundTestViewController.h"

@implementation soundTestViewController
-(IBAction) playSound{
CFBundleRef mainBundle=CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"mysound", CFSTR("mp3"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {
[super dealloc];
}

@end

但是,“生成结果”给出了错误:
Build soundTest of project soundTest with configuration Debug

Ld build/Debug-iphonesimulator/soundTest.app/soundTest normal i386
cd /Users/joegeneric/Documents/soundTest
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk -L/Users/joegeneric/Documents/soundTest/build/Debug-iphonesimulator -F/Users/joegeneric/Documents/soundTest/build/Debug-iphonesimulator -F/Users/joegeneric/Documents/soundTest -filelist /Users/joegeneric/Documents/soundTest/build/soundTest.build/Debug-iphonesimulator/soundTest.build/Objects-normal/i386/soundTest.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework CoreGraphics -framework AVFoundation -framework AudioToolbox -o /Users/joegeneric/Documents/soundTest/build/Debug-iphonesimulator/soundTest.app/soundTest

ld: warning: in /Users/joegeneric/Documents/soundTest/AVFoundation.framework/AVFoundation, missing required architecture i386 in file
ld: warning: in /Users/joegeneric/Documents/soundTest/AudioToolbox.framework/AudioToolbox, missing required architecture i386 in file
Undefined symbols:
"_AudioServicesPlaySystemSound", referenced from:
-[soundTestViewController playSound] in soundTestViewController.o
"_AudioServicesCreateSystemSoundID", referenced from:
-[soundTestViewController playSound] in soundTestViewController.o
ld: symbol(s) not found

您可以显示我做错了什么,或者在iPhone SDK中播放声音的任何其他更简单的工作教程吗?

最佳答案

[除了massimobio的正确答案]

您提供的教程链接提到了iOS的Xcode 4,但是“构建结果”中的“setenv MACOSX_DEPLOYMENT_TARGET 10.6”行指示您的部署目标为Mac。

您需要将Project Build Architecture更改为iOS,并检查您的目标是IOS,而不是OSX。

例如要更改您的构建体系结构,请单击您的项目,然后选择“构 build 置”以显示基本SDK。

另外,您的IBAction缺少发送者。应该在您的 Controller 头文件中将其声明为

-(IBAction) playSound:(id)sender;

并在您的Controller .m文件中实现为
-(IBAction) playSound:(id)sender {
// your code here
}

同样,不要忘记使用control-drag将代码中的IBAction链接到XIB,以创建一个操作目标对。

播放声音的最简单演示是SysSound。如果您搜索Xcode文档或通过Apple Developer网站的“示例代码”下可用。

关于iphone - 使用按钮iPhone SDK进行简单的声音播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11385176/

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