jackpocket/android-scratchoff

Scratch sound

Closed this issue · 3 comments

HI how i can add sound ?
thanks

That isn't supported out of the box, and can't be used with the current release version... but...

If you clone the repo, you can edit the onReceiveMotionEvent(MotionEvent event, boolean actionDown) method inside the ScratchoffProcessor.

At the end of that block of code, you could add a general trigger for your scratching sound, or work with the data available there to figure out the user's motion in order to trigger your desired sound effect.

Keep in mind, there are a lot of heavy calculations going on in there, so you should be careful of how much your adding and to which Thread you're adding it to.

General support for this will be included in Version 1.3.0 by interfacing with ScratchoffController.setScratchValueChangedListener(ScratchValueChangedListener).

ScratchoffController(context)
    .setScratchValueChangedListener(value -> {
        // Play your sound; preferably debounced.
        // Comparing this value with the last received will give you a rough estimate of  
        // velocity based on the size of the scratchable area
    })
    ....

Closing with 1.3.0 release