[英]Iphone audio only working in Simulator NOT in Device
I have set up part of my app to play a sound. 我已经设置了部分应用程序来播放声音。 Simple - but only is working in Simulator.
很简单-但仅适用于Simulator。
Initing audio session this way: 通过这种方式启动音频会话:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
AudioSessionInitialize(NULL,NULL,NULL,NULL);
AudioSessionSetActive(YES);
return self;
}
Playing sound, setting completion calback, and checking for file this way: 播放声音,设置完成校准和通过以下方式检查文件:
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp3"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
AudioServicesAddSystemSoundCompletion (soundID,NULL,NULL,
completionCallback,
(void*) self);
if([[NSFileManager defaultManager] fileExistsAtPath:path])
{
NSLog(@"Playing Sound" );
AudioServicesPlaySystemSound(soundID);
}
else {
NSLog(@"NO SOUND");
}
In Simulator, the file is found, sound plays, and completion happens. 在模拟器中,找到文件,播放声音并完成播放。 In device, file is found, sound does not play, and completion is never called.
在设备中,找到文件,声音不播放,并且永远不会调用完成。
Any ideas? 有任何想法吗? Thank you very much, both my forehead and my desk appreciate any replies...:)
非常感谢您,我的额头和书桌都感谢您的答复... :)
OK, So there were a few things I changed to get this working. 好的,为了使它正常工作,我做了一些更改。 DOn't have the code in front of me, will try to add later.
我前面没有代码,稍后将尝试添加。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.