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. |
错误记录为 –
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 |
因此加载哔声似乎是一个问题,但它位于主捆绑包中,并且目标成员资格框已打勾。也许我只是想以错误的方式解决这个问题!
- 你能用错误注销 beepFilePath 并更新问题吗,谢谢。
- 我想我不知道你在问什么
- 我想看到它正在取回一个有效的文件路径,这将是最明显的失败点。
- 而不是这个: NSURL *beepURL = [NSURL URLWithString:beepFilePath];试试这个: NSURL *beepURL = [NSURL fileURLWithPath:beepFilePath];
- 这解决了迈克!我怎样才能给你信用?
- 很高兴它奏效了!我发布了我的答案,你能接受吗?非常感谢!
而不是这个:
1
|
NSURL *beepURL = [NSURL URLWithString:beepFilePath];
|
试试这个:
1
|
NSURL *beepURL = [NSURL fileURLWithPath:beepFilePath];
|
- 更简单的方法是将所有路径/URL 代码替换为:NSURL *beepURL = [[NSBundle mainBundle] URLForResource:@”beep” withExtension:@”mp3″];
- 是的,那就更好了。
当您使用 [NSURL URLWithString:beepFilePath]; 时,它只会获取文件夹路径的字符串,例如 Users/***/folder/etc。
所以使用 [NSURL fileURLWithPath:beepFilePath]; 这段代码将完整路径像 file:///Users/***/folder/etc.
工作代码:
1
|
NSURL *beepURL = [NSURL fileURLWithPath:beepFilePath];
|
可选方法:
1
|
NSURL *beepURL = [NSURL URLWithString:[NSString stringWithFormat:@“file:///%@”, beepFilePath]];
|
来源:https://www.codenong.com/27432841/