iOS add beep to barcode scanner
我一直在使用来自 infragistics 的带有 iOS 7 (Objective-C) 的扫描条码,它运行良好。我正在尝试在成功完成扫描时添加哔声,但不断收到错误消息。我相信对于比我了解更多的人来说,这很容易解决。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | -(void)loadBeepSound{ // Get the path to the beep.mp3 file and convert it to a NSURL object. NSString *beepFilePath = [NSString stringWithFormat:@"%@/beep.mp3", [[NSBundle mainBundle] resourcePath]]; NSURL *beepURL = [NSURL URLWithString:beepFilePath]; NSError *error; // Initialize the audio player object using the NSURL object previously set. _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:beepURL error:&error]; if (error) { // If the audio player cannot be initialized then log a message. NSLog(@"Could not play beep file."); NSLog(@"%@", [error localizedDescription]); NSLog(@"beepFilePath %@", beepFilePath); } else{ // If the audio player was successfully initialized then load it in memory. [_audioPlayer prepareToPlay]; } } |
错误记录为 -
1 2 3 | -Could not play beep file. -The operation couldna€?t be completed. (OSStatus error -10875.) -beepFilePath /private/var/mobile/Containers/Bundle/Application/22BB6164-82F8-46E5-B4B6- 4C91BCA2B7E9/ReThink Edu App.app/beep.mp3 |
因此加载哔声似乎是一个问题,但它位于主捆绑包中,并且目标成员资格框已打勾。也许我只是想以错误的方式解决这个问题!
而不是这个:
1 | NSURL *beepURL = [NSURL URLWithString:beepFilePath]; |
试试这个:
1 | NSURL *beepURL = [NSURL fileURLWithPath:beepFilePath]; |
当您使用
所以使用
工作代码:
1 | NSURL *beepURL = [NSURL fileURLWithPath:beepFilePath]; |
可选方法:
1 | NSURL *beepURL = [NSURL URLWithString:[NSString stringWithFormat:@"file:///%@", beepFilePath]]; |