diff --git a/iphone/ScanTest/Classes/RootViewController.m b/iphone/ScanTest/Classes/RootViewController.m index bbcb33508..d852d7f63 100644 --- a/iphone/ScanTest/Classes/RootViewController.m +++ b/iphone/ScanTest/Classes/RootViewController.m @@ -19,6 +19,8 @@ [super viewDidLoad]; [self setTitle:@"ZXing"]; scanController = [[ZXingWidgetController alloc] initWithDelegate:self]; + NSBundle *mainBundle = [NSBundle mainBundle]; + [scanController setSoundToPlay:[[NSURL fileURLWithPath:[mainBundle pathForResource:@"beep-beep" ofType:@"aiff"] isDirectory:NO] retain]]; } - (IBAction)scanPressed:(id)sender { diff --git a/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj b/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj index a26753e26..6da81c0b8 100755 --- a/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj +++ b/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ 28F335F11007B36200424DE2 /* RootViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28F335F01007B36200424DE2 /* RootViewController.xib */; }; E5345BC91198D74D000CB77F /* libZXingWidget.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E5345BC81198D74D000CB77F /* libZXingWidget.a */; }; E5345BF11198D81A000CB77F /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E5345BF01198D81A000CB77F /* AudioToolbox.framework */; }; + E548755C119C62B9001CC0F8 /* beep-beep.aiff in Resources */ = {isa = PBXBuildFile; fileRef = E548755B119C62B9001CC0F8 /* beep-beep.aiff */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -72,6 +73,7 @@ E5345BED1198D7E2000CB77F /* ZXingWidgetController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ZXingWidgetController.h; path = ../ZXingWidget/ZXingWidgetController.h; sourceTree = SOURCE_ROOT; }; E5345BF01198D81A000CB77F /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; E5345FD6119B27D2000CB77F /* libZXingWidget.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = libZXingWidget.a; path = "build/Debug-iphoneos/libZXingWidget.a"; sourceTree = ""; }; + E548755B119C62B9001CC0F8 /* beep-beep.aiff */ = {isa = PBXFileReference; lastKnownFileType = audio.aiff; path = "beep-beep.aiff"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -135,6 +137,7 @@ 29B97317FDCFA39411CA2CEA /* Resources */ = { isa = PBXGroup; children = ( + E548755B119C62B9001CC0F8 /* beep-beep.aiff */, 28F335F01007B36200424DE2 /* RootViewController.xib */, 28AD735F0D9D9599002E5188 /* MainWindow.xib */, 8D1107310486CEB800E47090 /* ScanTest-Info.plist */, @@ -248,6 +251,7 @@ files = ( 28AD73600D9D9599002E5188 /* MainWindow.xib in Resources */, 28F335F11007B36200424DE2 /* RootViewController.xib in Resources */, + E548755C119C62B9001CC0F8 /* beep-beep.aiff in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/iphone/ScanTest/beep-beep.aiff b/iphone/ScanTest/beep-beep.aiff new file mode 100644 index 000000000..8854a590a Binary files /dev/null and b/iphone/ScanTest/beep-beep.aiff differ diff --git a/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj b/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj index 3eafbc085..10f4b6645 100644 --- a/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj +++ b/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj @@ -430,7 +430,6 @@ E5345AA21198859A000CB77F /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; E5345AC611988B6E000CB77F /* GrayBytesMonochromeBitmapSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GrayBytesMonochromeBitmapSource.h; sourceTree = ""; }; E5345AC711988B6E000CB77F /* GrayBytesMonochromeBitmapSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GrayBytesMonochromeBitmapSource.cpp; sourceTree = ""; }; - E5345D2911999F62000CB77F /* beep-beep.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "beep-beep.caf"; sourceTree = ""; }; E5345F2B119B0762000CB77F /* Decoder.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Decoder.mm; sourceTree = ""; }; /* End PBXFileReference section */ @@ -816,7 +815,6 @@ E5345D2811999F53000CB77F /* Resources */ = { isa = PBXGroup; children = ( - E5345D2911999F62000CB77F /* beep-beep.caf */, ); name = Resources; sourceTree = ""; diff --git a/iphone/ZXingWidget/ZXingWidgetController.h b/iphone/ZXingWidget/ZXingWidgetController.h index 9429fe6c3..6955d3453 100755 --- a/iphone/ZXingWidget/ZXingWidgetController.h +++ b/iphone/ZXingWidget/ZXingWidgetController.h @@ -28,12 +28,14 @@ OverlayView *overlayView; SystemSoundID beepSound; BOOL showCancel; + NSURL *soundToPlay; id delegate; BOOL wasCancelled; } @property (nonatomic, assign) id delegate; @property (nonatomic, assign) BOOL showCancel; +@property (nonatomic, assign) NSURL *soundToPlay; @property (nonatomic, retain) ParsedResult *result; @property (nonatomic, retain) NSArray *actions; diff --git a/iphone/ZXingWidget/ZXingWidgetController.m b/iphone/ZXingWidget/ZXingWidgetController.m index d3560afe9..adfc11753 100755 --- a/iphone/ZXingWidget/ZXingWidgetController.m +++ b/iphone/ZXingWidget/ZXingWidgetController.m @@ -29,12 +29,13 @@ CGImageRef UIGetScreenImage(); @implementation ZXingWidgetController -@synthesize result, actions, showCancel, delegate; +@synthesize result, actions, showCancel, delegate, soundToPlay; - (id)initWithDelegate:(id)scanDelegate { if (self = [super init]) { [self setDelegate:scanDelegate]; showCancel = true; + beepSound = -1; self.wantsFullScreenLayout = YES; self.sourceType = UIImagePickerControllerSourceTypeCamera; float zoomFactor = CAMERA_SCALAR; @@ -55,7 +56,9 @@ CGImageRef UIGetScreenImage(); } - (void)dealloc { - AudioServicesDisposeSystemSoundID(beepSound); + if (beepSound != -1) { + AudioServicesDisposeSystemSoundID(beepSound); + } [overlayView dealloc]; [super dealloc]; } @@ -85,13 +88,16 @@ CGImageRef UIGetScreenImage(); return false; } -- (void)viewDidLoad { - [super viewDidLoad]; - NSBundle *mainBundle = [NSBundle mainBundle]; - OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:[mainBundle pathForResource:@"beep-beep" ofType:@"caf"] isDirectory:NO], &beepSound); - if (error != kAudioServicesNoError) { - NSLog(@"Problem loading nearSound.caf"); - } +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + NSLog(@"should load sound"); + if ([self soundToPlay] != nil) { + NSLog(@"will try to load sound"); + OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)[self soundToPlay], &beepSound); + if (error != kAudioServicesNoError) { + NSLog(@"Problem loading nearSound.caf"); + } + } } - (void)viewDidAppear:(BOOL)animated { @@ -113,27 +119,30 @@ CGImageRef UIGetScreenImage(); CGRect cropRect = overlayView.cropRect; cropRect.origin.x = 0.0; cropRect.origin.y = 0.0; - NSLog(@"crop rect %f, %f, %f, %f", cropRect.origin.x, cropRect.origin.y, cropRect.size.width, cropRect.size.height); [d decodeImage:scrn cropRect:cropRect]; } // DecoderDelegate methods - (void)decoder:(Decoder *)decoder willDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset{ +#ifdef DEBUG NSLog(@"DecoderViewController MessageWhileDecodingWithDimensions: Decoding image (%.0fx%.0f) ...", image.size.width, image.size.height); +#endif } - (void)decoder:(Decoder *)decoder decodingImage:(UIImage *)image usingSubset:(UIImage *)subset progress:(NSString *)message { - NSLog(@"decoding image %@", message); } - (void)presentResultForString:(NSString *)resultString { - NSLog(@"in presentResultForString()"); self.result = [ResultParser parsedResultForString:resultString]; - AudioServicesPlaySystemSound(beepSound); + + if (beepSound != -1) { + NSLog(@"about to play beep... trying..."); + AudioServicesPlaySystemSound(beepSound); + } #ifdef DEBUG NSLog(@"result string = %@", resultString); NSLog(@"result has %d actions", actions ? 0 : actions.count); @@ -145,13 +154,11 @@ CGImageRef UIGetScreenImage(); forImage:(UIImage *)image usingSubset:(UIImage *)subset { // simply add the points to the image view - NSLog(@"got points for display"); [overlayView setPoints:resultPoints]; } - (void)decoder:(Decoder *)decoder didDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset withResult:(TwoDDecoderResult *)twoDResult { - // [self presentResultForString:twoDResult.text]; - NSLog(@"decoded image!!"); + [self presentResultForString:[twoDResult text]]; [self presentResultPoints:[twoDResult points] forImage:image usingSubset:subset]; // now, in a selector, call the delegate to give this overlay time to show the points [self performSelector:@selector(alertDelegate:) withObject:[[twoDResult text] copy] afterDelay:1.0];