I'm trying to draw a custom waveform view from a decoded audio file. The problem is that when I use the MediaCodec class to decode an m4a sound file to pcm, the decoding process may take a long time.
I followed this CTS test to get the decoded array.
Is there any way to minimize the decoding process or to get relevant information about the audio file frames without decoding the whole file each time.
You don't need to wait for the whole file to be decoded, you can use the decoded data from each frame once it is available.
In the CTS test you linked, have a look at lines 223-234 - here a buffer of decoded data has been received from the decoder, which is copied into an output buffer. If you change this to do the processing of the data right there, you can do your handling of the decoded data immediately without waiting for the whole file. (This is how playback of a file would be done as well.)
Keep in mind that you can't really assume the size of the output frames, it depends on the frame size of the codec used in the file. (For the most common versions of AAC, it is 1024 samples.) So depending on how you want to process your output data, you might want to buffer it up into slightly larger chunks if necessary.