massoudss/waveformSeekBar

can't use setSampleFrom method

power95031 opened this issue · 5 comments

i can't find setSampleFrom() method on 2.0.0 Version

so i try to implemataion 1.1.4 version but 1.1.4 version setSampleFrom method draw wave speed too slow

so, how can i set Waves from mp3 file on JAVA

Hello @power95031. Version 2.0.0 use another audio processing method. You should use WaveformOptions object to process audio at first and then use samples in the setSample() method from WaveformSeekBar. Example:

        WaveformSeekBar wsb = findViewById(R.id.waveformSeekBar); // Your waveform

        WaveformOptions.getSampleFrom("/storage/emulated/0/Music/my_audio_file.mp3", ints -> {
            wsb.setSample(ints); // ints - samples produced from your audio file 
            return null;
        });

thanks for comment and example, by the way i try your example comment code but getSampleFrom method make error
like this Cannot resolve method 'getSampleFrom' in 'WaveformOptions'
and in lambda wsb.setSample(ints); method parameter error

Required type: int[]
Provided: <lambda parameter>

@power95031 It looks like you use old waveformSeekBar library version: 1.1.4 in your case.

Try to update the version to 2.0.0 and run code example again.

implementation 'com.github.massoudss:waveformSeekBar:2.0.0'

@lincollincol well my Module gradle already used implementation 'com.github.massoudss:waveformSeekBar:2.0.0'
i think maybe problem of Kotlin but i have no idea about how can i fit it XD
thank you very much for your help comment and advice @lincollincol 👍
and forgive me my bad english and question format, Have a good day

@power95031 you need to set java language level to 8 by adding blow lines to build.gradle file:

android {
....
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
....
}

And use this code to get samples in java side:

WaveformOptions.getSampleFrom(your_file, s -> {
waveformSeekBar.setSample(s);
return Unit.INSTANCE;
});