WavePlayerView is an advanced library for real-time sound analysis by recording sound and instantly plotting waves based on frequencies and visualizing waves from an audio file or a track within your application.
- Real-time Sound Analysis: Display sound waves in real-time while recording or playing an audio file.
- Customizable Display: Easily adjust wave colors, stroke widths, and wave speed.
- User-friendly: Simple and intuitive API for seamless integration.
- Wide Compatibility: Supports Android API level 21 and above.
- Advanced Controls: Control playback speed, pause/resume functionality, and monitor audio progress.
- High Performance: Engineered for high efficiency with minimal impact on your application's performance.
- Open Source: Full access to source code for customization and enhancement.
- Community Support: Supported by a dedicated community, with opportunities for contributions and improvements.
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
//...
maven { url 'https://jitpack.io' }
}
}
Add the following to your project's
build.gradle
file:
dependencies {
implementation 'com.github.alex11111115:WavePlayerView:1.10'
}
Add
WavePlayerView
to your activity layout fileactivity_main.xml
:
<sound.wave.kilobyte.WavePlayerView
android:id="@+id/waveView"
android:layout_width="250dp"
android:layout_height="75dp"
android:padding="2dp"
android:gravity="center"
android:orientation="horizontal"
android:layout_gravity="center"
app:waveColor1="#FF8E8DE5"
app:waveStrokeWidth1="5dp"
app:waveColor2="#FFE8D8FB"
app:waveStrokeWidth2="5dp"
app:waveSpeed="0.5"
app:wave2Visible="true" />
In your
MainActivity.java
file, you can control theWavePlayerView
as follows:
To play from file path:
// Play audio from a file path
waveView.playAudioWithWaveFromPath(filePath);
To play from your app resources:
// Play audio from app resources
waveView.playAudioWithWave(R.raw.mus); //Replace 'mus' with your audio
To pause media and waves:
// Pause media and waves
waveView.pauseAudioWithWave();
To resume media and waves:
// Resume media and waves
waveView.resumeAudioWithWave();
To stop media and waves:
// Stop media and waves
waveView.stopAudioWithWave();
To start listening and show waves live:
// Start listening and show live waves
waveView.startListening();
To stop listening:
// Stop listening
waveView.stopListening();
To set playback speed:
// Set playback speed (default is "1.0")
waveView.setPlaybackSpeed("1.0");
To set wave properties:
// Set wave properties
waveView.setWaveProperties(color1, wave1Width, color2, wave2Width, waveSpeed);
To control the visibility of the second wave:
// Hide the second wave
waveView.setWave2Visible(false);
// Show the second wave
waveView.setWave2Visible(true);
To handle audio completion events:
// Handle audio completion events
waveView.setOnAudioCompleteListener(() -> progressbar1.setProgress(0));
To track audio progress:
// Track audio progress
waveView.setOnAudioProgressListener(currentMilliSec -> {
//your codes here
});
To seek to a position in the media:
// Seek to a position in the media
progressbar1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
value = progress; // Store value
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
waveView.pauseAudioWithWave(); // Pause media
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
waveView.seekToPosition((int) value); // Seek to new position
waveView.setPlaybackSpeed(s);
}
});
Add the following permissions to your
AndroidManifest.xml
:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
Put this in "onDestroy" as follows
if (waveView != null) {
waveView.release();
}
WavePlayerView is developed and maintained by alex11111115.
We welcome contributions from the community! If you have ideas or improvements, feel free to submit pull requests or open issues on the GitHub repository.
Thanks to these amazing people for their contributions
This project follows the all-contributors specification. Contributions of any kind are welcome!
WavePlayerView is licensed under the Apache License 2.0.