iOS模拟器不播放音效
我知道这个问题已经被问了999次了。所有答案都表示要转到系统首选项>声音>音效,并确保选中“播放用户界面音效”,或者取消选中并重新检查 这对我不起作用。我已经检查过了,但是音效仍然没有播放 更多信息:iOS模拟器不播放音效,ios,ios-simulator,audiotoolbox,Ios,Ios Simulator,Audiotoolbox,我知道这个问题已经被问了999次了。所有答案都表示要转到系统首选项>声音>音效,并确保选中“播放用户界面音效”,或者取消选中并重新检查 这对我不起作用。我已经检查过了,但是音效仍然没有播放 更多信息: 我正在尝试使用SystemSoundID播放音效 我以前用过AVAudioPlayer来制作音效,效果不错 在模拟器中从Safari上传到YouTube,并播放视频声音 我已将AudioToolbox.framework链接到我的项目 我从下载了苹果的示例代码 这也没有播放,所以我很确定我的代码没
SystemSoundID
播放音效AVAudioPlayer
来制作音效,效果不错AudioToolbox.framework
链接到我的项目#import <AudioToolbox/AudioServices.h>
@interface SoundEffect : NSObject
{
SystemSoundID soundID;
}
- (id)initWithSoundNamed:(NSString *)filename withExtension:(NSString*) extension;
- (void)play;
@end
注意:我创建此对象并在项目中需要的任何位置播放它。当我尝试播放声音时,“找到文件URL”和“播放声音效果”都会被记录
来源:SystemSoundID customSound;
NSString*声音文件=[[NSBundle mainBundle]路径资源:ofType:];
NSURL*soundURL=[NSURL fileURLWithPath:openMenu];
AudioServicesCreateSystemSoundID((uu桥CFURLRef)soundURL和customSound);
AudioServicesPlaySystemSound(自定义声音);
这是我的作品我不想问显而易见的问题,但你的电脑是否播放其他声音?你是否尝试过使用不同的声音文件?你是calling@RyanForsyth是的,我试过使用多个声音文件。声音文件在Xcode中打开时是否播放声音?音频文件的格式是什么?你有没有试过看看这是否有帮助?
#import "SoundEffect.h"
@implementation SoundEffect
- (id)initWithSoundNamed:(NSString *)filename withExtension:(NSString *)extension
{
if ((self = [super init]))
{
NSURL *fileURL = [[NSBundle mainBundle] URLForResource:filename withExtension:extension];
if (fileURL != nil)
{
NSLog(@"fileURL found");
SystemSoundID theSoundID;
OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)fileURL, &theSoundID);
if (error == kAudioServicesNoError)
soundID = theSoundID;
}
}
return self;
}
- (void)dealloc
{
AudioServicesDisposeSystemSoundID(soundID);
}
- (void)play
{
if([[NSUserDefaults standardUserDefaults] boolForKey:soundEffectsKey]) {
NSLog(@"Play sound effect");
AudioServicesPlaySystemSound(soundID);
}else {
NSLog(@"Sound effects are disabled");
}
}
SystemSoundID customSound;
NSString *soundFile = [[NSBundle mainBundle]pathForResource:<#customSoundName#> ofType:<#soundFormat#>];
NSURL *soundURL = [NSURL fileURLWithPath:openMenu];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)soundURL, & customSound);
AudioServicesPlaySystemSound(customSound);