Reputation: 71
I have been using the Scanning Barcodes with iOS 7 (Objective-C) from infragistics and it works well. I am trying to add a beep when it completes a successful scan but keep getting an error. I'm sure its an easy fix for someone who knows more than I.
-(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];
}
}
The Error is logging as -
-Could not play beep file. -The operation couldn’t be completed. (OSStatus error -10875.) -beepFilePath /private/var/mobile/Containers/Bundle/Application/22BB6164-82F8-46E5-B4B6- 4C91BCA2B7E9/ReThink Edu App.app/beep.mp3
and so it seems to be an issue with loading the beep sound but it is in the main bundle and the target membership box is ticked. Maybe I'm just trying to go about this the wrong way!
Upvotes: 0
Views: 1406
Reputation: 11217
When you use [NSURL URLWithString:beepFilePath];
it only gets string of the folder path like Users/***/folder/etc
.
So use [NSURL fileURLWithPath:beepFilePath];
this code to will full path like file:///Users/***/folder/etc
.
Working Code:
NSURL *beepURL = [NSURL fileURLWithPath:beepFilePath];
Optional Method:
NSURL *beepURL = [NSURL URLWithString:[NSString stringWithFormat:@"file:///%@", beepFilePath]];
Upvotes: 0
Reputation: 9352
Instead of this:
NSURL *beepURL = [NSURL URLWithString:beepFilePath];
Try this instead:
NSURL *beepURL = [NSURL fileURLWithPath:beepFilePath];
Upvotes: 2