Reputation: 63
my MediaPlayer is working, but I need to retrieve the metadata e.g. stream title. I'm using this code for it:
public String getMeta(){
meta = new MediaMetadataRetriever();
meta.setDataSource("http://111.1111.1111.1111:1111");
return meta.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
But I'm only getting a empty String from this. I also tried all constants for the meta. I'm not sure, but I think the problem is around the connection to the webstation. My MediaPlayer has a Listener e.g. mPlayer.setOnPreparedListener(new OnPreparedListener() {...}. But for the MediaMetadataRetriever does not exist one.
Can someone help me? Thanks!
Upvotes: 1
Views: 5538
Reputation: 1165
I don't have any idea about media player, but it's possible to use Apache Tika to extract metadata about file:
Here is a my code of extract metadata of a file:
InputStream is = new FileInputStream("/home/rahul/Music/03 - I Like Your Music.mp3");
Parser parser = new AutoDetectParser();
BodyContentHandler handler = new BodyContentHandler();
Metadata metadata = new Metadata();
parser.parse(is, handler, metadata, new ParseContext());
String handler = handler.toString();
System.out.println("Handler data: " + handler);
System.out.println(metadata.get(Metadata.CREATION_DATE));
System.out.println(metadata.get(Metadata.LAST_MODIFIED));
It will extract the metadata like we can see at:
Upvotes: 3
Reputation: 513
The reason why you are not getting any results from MediaMetadataRetriever.extractMetaData() is because your examples calls setDataSource(String path) which only will load local files. If you want to pass in a remote URL then you need to call setDataPath(String uri, Map headers) method.
Upvotes: 1
Reputation: 3530
Apacke Tika is too large and limited to use in a mobile application. Try FFmpegMediaMetadataRetriever (Disclaimer: it's my project). It has the same interface as MediaMetadataRetriever:
FFmpegMediaMetadataRetriever retriever = new FFmpegMediaMetadataRetriever();
retriever.setDataSource("http://someurl");
retriever.release();
Upvotes: 1