Get duration of music file and time last modified
This video shows how to get the duration of a music file and the time it was last modified in Sketchware android project. Code to get time last modified in milliseconds: java.io.File music_file = new java.io.File(path); double lastModified = music_file.lastModified(); Code to get duration of music file in seconds: MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(getApplicationContext(), FileProvider.getUriForFile(ListActivity.this, getApplicationContext().getPackageName() + ".provider", music_file)); String duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); int millSecond = Integer.parseInt(duration); double seconds = millSecond/1000;
This video shows how to get the duration of a music file and the time it was last modified in Sketchware android project. Code to get time last modified in milliseconds: java.io.File music_file = new java.io.File(path); double lastModified = music_file.lastModified(); Code to get duration of music file in seconds: MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(getApplicationContext(), FileProvider.getUriForFile(ListActivity.this, getApplicationContext().getPackageName() + ".provider", music_file)); String duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); int millSecond = Integer.parseInt(duration); double seconds = millSecond/1000;