Library: Beep/Sound on reading a code

Created on 11 Jun 2019  路  6Comments  路  Source: zxing-js/library

It will be nice if we may produce a beep or a sound effect when a code is read.

Browsers now do not accept a JavaScript call to play an audio unless the call is made within the context of an event caused by a user action (e.g. clicking a button). I have attempted another JavaScript library to read QR codes which generates an event when a code is detected. A JavaScript call to play an audio in the context of this event is accepted by the browsers as a legit call and the sound is played.

I have not been able to find something similar in ZXing JS library. Can we play an audio when decodeFromInputVideoDevice() returns results? Or perhaps this is a feature enhancement request.

PRs welcome enhancement feature request no-auto-close no-issue-activity

Most helpful comment

const beepSound: HTMLAudioElement = new Audio('data:audio/wav;base64,//YOUR_BASE_64_AUDIO_HERE')

...

onScanSuccess(value): void {
        beepSound.play()
}

this works fines on all the browsers that I tested (desktop and mobile/android)

All 6 comments

It's a legit feature request, hehe. I have to figure out how to handle events like that library you're talking about, in fact, some events inside the code reader would be very awesome for a bunch of reasons. Also, I was thinking about adding some vibration effect (optional of course) when decoding happens and I'm wondering now if it would required a call inside an event callback too.

Stale issue message

const beepSound: HTMLAudioElement = new Audio('data:audio/wav;base64,//YOUR_BASE_64_AUDIO_HERE')

...

onScanSuccess(value): void {
        beepSound.play()
}

this works fines on all the browsers that I tested (desktop and mobile/android)

It would be essentially good if this feature could be imported as the user (developer) wants to enable beeping.

Stale issue message

ping @odahcam

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arthurmmedeiros picture arthurmmedeiros  路  3Comments

Mazecreator picture Mazecreator  路  10Comments

ismailjamiljauhari picture ismailjamiljauhari  路  6Comments

boruchsiper picture boruchsiper  路  7Comments

majestic84 picture majestic84  路  8Comments