lincollincol / Amplituda

Audio processing library, which provides waveform data
Apache License 2.0
222 stars 31 forks source link

Process audio from Uri feature #40

Open lincollincol opened 2 years ago

lincollincol commented 2 years ago

@niklasdahlheimer Currently, It's not possible to process uri with Amplituda directly, but I'm working on it. This code will help you to convert uri to an internal file that can be processed with Amplituda. This approach also solves problems such as obtaining a path or access to a file

So, the reason Amplituda doesn't work with uri, is that I need to get the context to process uri. I don't really like this approach, but it seems there are no other options. Currently, I'm looking for the opportunity to work with uri in NDK, but there are no results yet

niklasdahlheimer commented 2 years ago

Thanks for you response! The mentioned workaround does it's job but a big disadvantage is, that the cacheDir will unnecessarily grow and grow and, like I already mentioned, the performance will suffer from cloning all audio files (especially for big wave files).

I don't like passing the context around either, but in this case I think it's reasonable as all other API functions which process URIs also do that. Besides that it would be up to the user if one uses processAudio(File: file) or processAudio(Context: context, Uri: uri).

You could simply adapt the way MediaExtractor is handling URIs: setDataSource(Context context, Uri uri, Map<String, String> headers) is just a wrapper around setDataSource(String path, Map<String, String> headers): Android Source code

khiemdnt commented 12 months ago

Hi @niklasdahlheimer, how to processAudio with url from API has headers.