Search code examples
ioszbar-sdkbeep

ZBar SDK no beep sound


I just use ZBar SDK to scan barcode. I want that when the barcode scanned, it can play a beep sound. though the scanning is pretty good. no sound over there. I didn't find any flag in SDK to take control of sound. does anyone meet with this problem? I'm new to ZBar. Thank you in advance. as I know ZXing has beep sound as default.but it can only decode QRCode.


Solution

  • The ZBar iPhone SDK doesn't automatically play a sound on successful scan. It's not hard to play one yourself, though:

    • Add a sound file you want played to your app, I called mine 'beep.mp3'.
    • Add the AudioToolbox framework to your project.

    In header file:

    #import <AudioToolbox/AudioServices.h>
    

    Setup (possibly in viewDidLoad):

    SystemSoundID soundID;
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef ref = CFBundleCopyResourceURL(mainBundle, (CFStringRef)@"beep.mp3", NULL, NULL);
    AudioServicesCreateSystemSoundID(ref, &soundID);
    self.soundID = soundID;
    

    Play sound:

    AudioServicesPlaySystemSound(self.soundID);