Reputation: 10078
I have an app with some mp3 files stored inside a subfolder of assets folder. I obtain list of files in this way
context.getAssets().list("audio");
and results show it inside a listview. By doing this, what i see is a list of mp3 filenames. Now i don't want show filenames, but associated metadata for each file.
Upvotes: 1
Views: 2483
Reputation: 3529
Copying the file to disk isn't necessary. MediaMetadataRetriever and FFmpegMediaMetadataRetriever both offer a setDataSource method that takes a FileDescriptor as an argument:
FFmpegMediaMetadataRetriever metaRetriver = new FFmpegMediaMetadataRetriever();\
// or MediaMetadataRetriever metaRetriver = new MediaMetadataRetriever();
String path = "audio";
String [] files = context.getAssets().list(path);
for (int i = 0; i < files.length; i++) {
String file = path + "/" + files[i];
AssetFileDescriptor afd = context.getAssets().openFd(file);
metaRetriver.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
String album = metaRetriver.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_ALBUM);
String artist = metaRetriver.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_ARTIST);
String gener = metaRetriver.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_GENRE);
afd.close();
}
metaRetriver.release();
Upvotes: 3
Reputation: 3843
By metadata means name, title, time etc data if you want then you need to use MediaMetadataRetriever class to do so..
MediaMetadataRetriever metaRetriver = new MediaMetadataRetriever();
metaRetriver.setDataSource("path of song");
String album = metaRetriver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
String artist = metaRetriver
.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
String gener=metaRetriver
.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);
Similarly you can extract other data also..
Hope it will help you.
Upvotes: 0
Reputation: 3775
Here you go. First get the file path as shown here
How to pass a file path which is in assets folder to File(String path)?
And then get metadata of audio as shown here
How to extract metadata from mp3?
Upvotes: 0