get duration of audio file

后端 未结 10 1150
生来不讨喜
生来不讨喜 2020-12-07 19:15

I have made a voice recorder app, and I want to show the duration of the recordings in a listview. I save the recordings like this:

MediaRecorder recorder =          


        
10条回答
  •  天命终不由人
    2020-12-07 19:27

    If the audio is from url, just wait for on prepared:

    mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                 length = mp.getDuration();
            }
    });
    

提交回复
热议问题