how to get bit rate , sampling rate and no. of channels of a audio file in android

和自甴很熟 提交于 2020-01-01 09:33:15

问题


I need your help for the below query:

Query: Is there any way of getting following info of an audio file. Sample rate, Channel, Bitrate of an audio file.

For extracting bitrate, "MediaMetadataRetriever" API is available (METADATA_KEY_BITRATE).

Please suggest if it can be done using any android API.

Found this below API, But its use is actually in different. http://developer.android.com/reference/android/medi/AudioTrack.html

I want to extract these using Android API programmactically : Sampling rate, Quantization, Channel of an input audio file.

Please help on this.

Thanks in advance.


回答1:


Use MediaPlayer.getTrackInfo() during playback (after METADATE_UPDATE event come to onInfo callback) to obtain MediaFormat object by invoke getFormat for audio stream track. And then from MediaFormat you can get:

BIT_RATE

CHANNEL_COUNT

SAMPLE_RATE




回答2:


This can be done using MeiaExtractor like this:

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);
    int channelCount = mf.getInteger(MediaFormat.KEY_CHANNEL_COUNT);


来源:https://stackoverflow.com/questions/14749038/how-to-get-bit-rate-sampling-rate-and-no-of-channels-of-a-audio-file-in-andro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!