How to use Java Function

112 views
Skip to first unread message

Martin Hafner

unread,
Feb 6, 2015, 3:45:32 AM2/6/15
to tas...@googlegroups.com
Hi,

I wanna realise a music player with tasker. Therefore it is possible to get the duration of the mp3. My music files are located on the sdcard1, what is the external_sd. The tasker integrated Test Media function doesn't work.
Therefore I found the following code, by using java.
Now is my question how can I use this code with tasker?

MediaMetadataRetriever mmr=new
MediaMetadataRetriever();
mmr.setDataSource(%Playlist(%PlaylistNum));
String duration=mmr.extractMetadata( MediaMetadataRetriever.METADATA_KEY_DURATION);

Please help, because the help section doesn't work for me.

Thanks,...

David Wang

unread,
Feb 6, 2015, 4:35:16 AM2/6/15
to tas...@googlegroups.com
The tasker integrated Test Media function doesn't work. 
"Test Media" action works very well on my phone. Maybe you should report the issue to the developer.
I guess Tasker also use the "MediaMetadataRetriever" internally to get metadata from media files. 

MediaMetadataRetriever mmr=new
MediaMetadataRetriever();
mmr.setDataSource(%Playlist(%PlaylistNum));
String duration=mmr.extractMetadata( MediaMetadataRetriever.METADATA_KEY_DURATION);
I had created one just now. And works very well on my phone. Xml file attached. Enjoy it!

Please help, because the help section doesn't work for me.
The "Java" Section of help file is very important. Maybe you should learn it carefully if you want to make some Java stuff with Tasker. :-)
JavaCode_MediaMetadataRetriever.tsk.xml

Martin Hafner

unread,
Feb 6, 2015, 5:21:02 AM2/6/15
to tas...@googlegroups.com
Thanks,
The internal function doesn't but the MediaMetadataRetriever works.

Wietse van Buitenen

unread,
Feb 6, 2015, 6:45:25 AM2/6/15
to tas...@googlegroups.com
you need to add the constant value of MediaMetadataRetriever.METADATA_KEY_DURATION instead of MediaMetadataRetriever.METADATA_KEY_DURATION itself.
You could get the value through refelextion as David posted or just get the value from here:

replacing:
String duration=mmr.extractMetadata( MediaMetadataRetriever.METADATA_KEY_DURATION); 
with:
String duration=mmr.extractMetadata( 9); 
should do the trick.
You might also want to replace duration by %duration so you can Fash the result in a Toast..
Reply all
Reply to author
Forward
0 new messages