简体   繁体   English

iPhone音频仅在设备中的模拟器中起作用

[英]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. 我前面没有代码,稍后将尝试添加。

  1. I stopped using the system sound and started using AVAudioPlayer instead. 我停止使用系统声音,而是开始使用AVAudioPlayer。
  2. I didn't have my UIView set up as the audio delegate 我没有将UIView设置为音频委托
  3. Was not starting the audio session. 没有启动音频会话。 Now am starting the audio session in the initNib function(I saw tutrorials that said to use awakeFromNib, but the awakeFromNib never fired...) 现在开始在initNib函数中进行音频会话(我看到说使用awakeFromNib的教程,但awakeFromNib从未触发过...)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iPhone音频在模拟器上播放,但不在设备上播放 - iphone audio plays on simulator but not on device 使用AVAudioPlayer播放的音频在iPhone Simulator中有效,但在Device中不起作用 - Audio played using AVAudioPlayer is working in iPhone Simulator but not in the Device 在 iPhone 设备中合并音频和视频不起作用。 在模拟器中合并音频和视频需要时间在 AVAssestTrack 初始化 - Merging of audio and video in iPhone device is not working. In simulator merging of audio and video is taking time in AVAssestTrack initialisation iPhone应用程序正在模拟器上运行,但无法在设备上运行 - iphone app is working on simulator but not on device 音频文件无法在设备上运行,但它正在模拟器上运行 - Audio file not working on device but it is working on simulator 背景音频在iOS模拟器上可运行,但不能在设备上运行 - background audio working on iOS simulator but not device 应用程序仅在iPhone设备上崩溃而不在模拟器中崩溃 - App crash only on iPhone Device and not in Simulator 调试已在iPhone模拟器中退出,但可在设备中运行 - Debugging exited in iphone simulator but working in device Phonegap文件传输可在iPhone模拟器中运行,但不能在设备上运行 - Phonegap filetransfer working in iPhone simulator but not on device 自动旋转仅在设备上的模拟器中有效(IOS 7.1) - Autorotation only working in simulator not on device (IOS 7.1)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM