Reading meta and start playing m4a files on Android is very slow
I am using MediaMetadataRetriever to extract metadata from m4a files on an Android device. Here is the code I am executing.
final MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(new File(root, audioFile).getAbsolutePath());
String title = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
String album = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
String artist = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
mmr.release();
The problem is that when I call this code for mp3 files it is very fast. For example, 25 mp3 files are analyzed in less than 900 ms.
But if I name it for one m4a file, then the same code takes 6 seconds . And this is very slow.
Another observation - when I use Android MediaPlayer, then any mp3 file starts playing immediately, and there is the same 6-second delay between the start m4a file and the first sound.
I've tried with different Android versions and different devices. Same problem.
Is there a way to get rid of this delay?
source to share
Have you tried FFmpegMediaMetadataRetriever :
final FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever();
mmr.setDataSource(new File(root, audioFile).getAbsolutePath());
String title = mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_TITLE);
String album = mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_ALBUM);
String artist = mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_ARTIST);
mmr.release();
source to share
Have you tried MediaStore ?
Please check the speed of the MP4 file in concern with MediaStore. A sample can be found here
source to share