Annoying click sound using MediaCapture APIs

Jun 25, 2015 at 9:33 PM
I am trying to build a QR Code scanner for my app in Windows 10 using Media Capture APIs and Zxing.net,
After initializing the MediaCapture element I am using following code to scan the QR code

private async Task CaptureQRCodeFromCameraAsync()
{
    ImageEncodingProperties imgProp = new ImageEncodingProperties { Subtype = "BMP", Width = 600, Height = 800 };
    InMemoryRandomAccessStream imageStream = null;
    WriteableBitmap writeableBitmap = null;
    BarcodeReader barcodeReader = new BarcodeReader();
    barcodeReader.Options.PossibleFormats = new BarcodeFormat[] { BarcodeFormat.QR_CODE };

    try
    {
        while (true)
        {
            if (_mediaCapture == null)
            {
                break;
            }

            //Update MediaCapture preview rotation bases on current display orientation
            _mediaCapture.SetPreviewRotation(VideoRotationLookup(DisplayInformation.GetForCurrentView().CurrentOrientation, false));

            // Capture QR code image in a filestream using CapturePhotoToStreamAsync API in MediaCapture class
            imageStream = new InMemoryRandomAccessStream();
            await _mediaCapture..CapturePhotoToStreamAsync(imgProp, imageStream);

            // Convert image stream to a writeable bitmap image for decoding
            imageStream.Seek(0);
            writeableBitmap = new WriteableBitmap(600, 800);
            await writeableBitmap.SetSourceAsync(imageStream);

            // Decode writeable bitmap impage using ZXing lib 
            _result = barcodeReader.Decode(writeableBitmap);
            if (_result != null)
            {
                // Initiate a CameraScanEvent to pass the scanned QR code to the caller
                InitiateCameraScanEvent();
                // Clean up the memory resources after use
                if (imageStream != null)
                {
                    imageStream.Dispose();
                }

                writeableBitmap = null;
                break;
            }
        }
    }
    catch (Exception e)
    {
        TelemetryManager.TrackException(e);
        Log.Error("Error while scanning QR code: " + e.Message);
    }
    finally
    {
        // Clean up resources
        if (imageStream != null)
        {
            imageStream.Dispose();
        }

        if (_mediaCapture != null)
        {
            _mediaCapture.Dispose();
        }

        writeableBitmap = null;
        barcodeReader = null;
        _result = null;
    }
Problem is for every scan in the while loop there is a click sound generated, looks very annoying.
Is there a way to suppress this thru code?

Thanks
Coordinator
Aug 13, 2015 at 7:38 PM
Sorry, no idea.
I don't think that this is an issue with ZXing.Net. Perhaps it's a feature in the Media Capture API.
Aug 27, 2015 at 12:26 PM
See if this helps your click problem.
                m_lowLagPhoto = await MediaCapture.PrepareLowLagPhotoCaptureAsync(ImageEncodingProperties.CreateJpeg());
                CapturedPhoto myPic = await m_lowLagPhoto.CaptureAsync();
                await m_lowLagPhoto.FinishAsync();
                WriteableBitmap image = new WriteableBitmap((int)myPic.Frame.Width, (int)myPic.Frame.Height);
My decoder is having issues if you know about that. If I generate a QR using the ZXing demo programs, and send that to the decoder it decodes. If I take a picture of one, it never does. His webcam capture demo seems to work, but for the life of me I can't figure out why a nice clear picture wont decode.