How to get Sampling rate and frequency of music file (MP3) in android?

前端 未结 3 673
攒了一身酷
攒了一身酷 2020-12-05 11:50

I am developing audio player in android. So i want to add the details of the playing song i.e. Artist Name, Duration, Bit rate and sampling frequency. I can get Artist Name

3条回答
  •  广开言路
    2020-12-05 12:16

    I know it's been resolved but i got much better way to get accurate answer

    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);
    

提交回复
热议问题