How to make variable length sound in Android

I am trying to create an application that reproduces a sound similar to a piano organ. When the user presses the button, he will play a sound similar to a piano. The difficulty is that the user can hold his finger for some time. When they take their finger away, it should disappear, and not stop suddenly.

I played with SoundPool and Media Player, but they do not seem to be suitable.

There are many applications for the piano ... does anyone know how they solve this problem?

+4
source share
1 answer

You want to use the AudioTrack class. The main use is to record your audio data using the AudioTrack method write()for any duration that you want it to be heard. You will need to use a separate stream for each simultaneous voice that you want to β€œplay”.

Here is the AudioTrack man page and here is a blog entry where the author does a good job showing what to do without much distraction.

0
source

Source: https://habr.com/ru/post/1535871/


All Articles