alxrm / audiowave-progressbar

Lightweight audiowave progressbar for Android
MIT License
492 stars 83 forks source link

Slow and excess load on the UI thread #19

Closed abbasnaqdi closed 5 years ago

abbasnaqdi commented 5 years ago

Hello . I used WaveView inside the RecyclerView and found it to be extremely slow and adds extra load on the UI thread.

Please fix this problem. Thank .

setData :

   if (itemView.wave_voice.scaledData.isEmpty()) {
            Observable.fromCallable { fileHelper.getFileByte(voice.file) }
                    .newThread()
                    .subscribe {
                        itemView.wave_voice.scaledData = it
                        itemView.wave_voice.setRawData(it)
                    }
        }

func :

 fun getFileByte(filename: String): ByteArray {
        val file = getFilePath(filename)
        return if (file.exists())
            file.readBytes()
        else byteArrayOf(0)
    }
alxrm commented 5 years ago

You're doing it wrong, take a closer look to the readme and l check out sample app

In short, you have to turn off the the expansion animation of the wave(it's in the readme).

And also consider not reading the whole file every time you bind your item, it also produces ridiculously high amount of redundant work, to avoid it, you can store a collection of scaled byte arrays(using Sampler.downSampleAsync or Sampler.downSample which fits perfectly in your Rx pipeline BTW) and bind them synchronously, which is way more efficient

alxrm commented 5 years ago

You might as well consider using another library, since this one produces waves that are not very accurate