Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining the duration and format of an audio file

Tags:

android

audio

Given a path (on the SD card) to an audio file, what is the best way of determining the length of the audio in milliseconds and the file format (or Internet media type)?

(For the duration one could use MediaPlayer's getDuration-method, but this seems too slow/clumsy.)

like image 490
Kaarel Avatar asked Jan 26 '11 08:01

Kaarel


1 Answers

For the length of the audio file:

File yourFile;
MediaPlayer mp = new MediaPlayer();
FileInputStream fs;
FileDescriptor fd;
fs = new FileInputStream(yourFile);
fd = fs.getFD();
mp.setDataSource(fd);
mp.prepare(); 
int length = mp.getDuration();
mp.release();

Check this for MimeType: https://stackoverflow.com/a/8591230/3937699

like image 87
John K Avatar answered Oct 05 '22 06:10

John K