##What
#####Show audio file's waveform, not spectrum.
#####This lib based on ringdroid, but only contains WaveformView and related classes.
##How
compile 'com.github.derlio.waveform:library:1.0.3@aar'
<com.github.derlio.waveform.SimpleWaveformView
android:id="@+id/waveform"
android:layout_width="match_parent"
android:layout_height="144dp"
app:waveformColor="#fb6155"
app:indicatorColor="@android:color/holo_green_dark"
/>
app:waveformColor is the waveform line's color, app:indicatorColor is the current playing indicator's color.
final File file = new File(dir, "qudali.mp3");
final SoundFile soundFile = SoundFile.create(file.getPath(), new SoundFile.ProgressListener() {
int lastProgress = 0;
@Override
public boolean reportProgress(double fractionComplete) {
final int progress = (int) (fractionComplete * 100);
if (lastProgress == progress) {
return true;
}
lastProgress = progress;
Log.i(TAG, "LOAD FILE PROGRESS:" + progress);
return true;
}
});
Make sure below codes should not be in the Main Thread. User SoundFile.ProgressListener to get file load progress, param fractionComplete is from 0.0 to 1.0, and return true means to continue decode, return false will abort the decode.
mWaveformView.setAudioFile(soundFile);
mWaveformView.invalidate();
to set the audio file to WaveformView. It does work.
int now = mPlayer.getCurrentPosition();
mWaveformView.setPlaybackPosition(now);