Real-time audio visualizer for android
At that time I was looking for a suitable library for my task and I found libraries that draw amplitudes in real-time, but almost every library had two big problems: a fixed interface and not flexible for use. Finally, I decided to write my own flexible custom view.
What are the advantages of this library?
Benefits:
The library is easy to use
Small and clear code
Support to use in both: code and XML
Active support and improvements
What do we mean when we say flexible? You can
Choose one of two types of alignment mode: "bottom" and "center"
Change the color of the chunks
Set minimum/maximum height of chunks
Change the width of chunks
Change space between two chunks.
Set the mode of rounded corners
Enable/disable "Soft Transition" mode
Control drawing speed
Setup AudioRecordView
In your application project (or root project if you prefer) build.gradle,make sure you have jcenter repository added:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add AudioRecordView SDK dependency to your app-levelbuild.gradle:
implementation'com.github.Armen101:AudioRecordView:latest_version'
After that, in your code (perhaps MainActivity class), find or create AudioRecordView object programmatically
private lateinit var audioRecordView: AudioRecordView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
audioRecordView = findViewById(R.id.audioRecordView)
}
In XML
<com.visualizer.amplitude.AudioRecordView
android:id="@+id/audioRecordView"
android:layout_width="256dp"
android:layout_height="64dp"
app:chunkAlignTo="bottom"
app:chunkRoundedCorners="true"
app:chunkSoftTransition="true"
app:chunkColor="#2196F3"
app:chunkSpace="1dp"
app:chunkWidth="2dp"
app:chunkMaxHeight="48dp"
app:chunkMinHeight="2dp"/>
timer = Timer()
timer?.schedule(object : TimerTask() {
override fun run() {
val currentMaxAmplitude = recorder?.maxAmplitude
audioRecordView.update(currentMaxAmplitude);
}
}, 0, 100)
app:chunkRoundedCorners="true"
app:chunkAlignTo="center"
app:chunkAlignTo="bottom"
Note: AudioRecordView SDK supports Android API 16 or later.
Thanks for your attention!
References