3

I am new to Android and I want load an audio file (wav or mp3) from the file system and display audio information, such as sampling rate etc.

How can I do this? Do you know any examples?

Said Savci
  • 818
  • 4
  • 14
  • 28

1 Answers1

3

You can approximate it by dividing the file size by the length of the audio in seconds, for instance, from a random AAC encoded M4A in my library:

File Size: 10.3MB (87013064 bits)
Length: 5:16 (316 Seconds)
Which gives: 87013064 bits / 316 seconds = 273426.147 bits/sec or ~273kbps
Actual Bitrate: 259kbps

Since most audio files have a known set of valid bitrate levels, you can use that to step the bit rate to the appropriate level for display.

Link to original answer by Jake Basile

Or use this code to get it much more accurate:

MediaExtractor mex = new MediaExtractor();
try {
    mex.setDataSource(path);// the adresss location of the sound on sdcard.
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

MediaFormat mf = mex.getTrackFormat(0);
int bitRate = mf.getInteger(MediaFormat.KEY_BIT_RATE);
int sampleRate = mf.getInteger(MediaFormat.KEY_SAMPLE_RATE);

Link to original answer by architjn

Community
  • 1
  • 1