Skip to content

tonmoym2mx/AudioVisualizerAndSoundRecorder

Repository files navigation

AudioVisualizerAndSoundRecorder

GIF-190712_150026_001 (1)

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
    ...
        maven { url 'https://jitpack.io' }
    }
}

Add the dependency

dependencies {
    implementation 'com.github.tonmoyv2mx:AudioVisualizerAndSoundRecorder:1.2'
}

Put permissions in Android manifest

 <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Add this in your layout:

<com.tonmoym2mx.audiovisualizer.AudioVisualizer
      android:id="@+id/audioVisualizer"
      android:layout_width="match_parent"
      android:layout_height="300dp"
     />

Initial Audio Visualizer

AudioVisualizer audioVisualizer = findViewById(R.id.audioVisualizer);

Initial Audio Recorder

String filePath = getExternalCacheDir().getAbsolutePath()+"/audio.mp3";
  
AudioRecorder audioRecorder = new AudioRecorder(MainActivity.this,filePath); 
  

Start Record Audio

if(!audioRecorder.isRecord){ //isRecord is boolean , for check recoder is recoding are not 
  audioRecorder.startRecord();
}
  

Stop Record Audio

if(audioRecorder.isRecord){
   audioRecorder.stopRecord();
}
   

Set Visualizer Amplitud

audioRecorder.setMaxAmplitudeListener(new MaxAmplitudeListener() {

     @Override
     public void getMaxAmplitude(int amplitude) {
     
         audioVisualizer.addAmplitude(amplitude);
         
     }
            
},50);
        

Set Timer Update Listener

 audioRecorder.setTimerUpdateListener(new TimerUpdateListener() {
       @Override
       public void onTimeChange(long time) {
       
           String d = new SimpleDateFormat("mm:ss").format(time);
           textView.setText(d);
           
       }
});
        

Audio Player

AudioPlayerDialog playerDialog = new AudioPlayerDialog(MainActivity.this, filePath);

playerDialog.show();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published