From cfa5d8da1ae4a70112d7b4ee0d2e7257e3e2d4d0 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 14 Oct 2014 15:48:27 -0700 Subject: Change bitrate to be calculated on the fly instead of reading tags (fix for VBR) --- .../daneren2005/dsub/fragments/SubsonicFragment.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 70a3b027..9ecaa0e9 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -1178,6 +1178,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR } public void displaySongInfo(final Entry song) { + Integer duration = null; Integer bitrate = null; String format = null; long size = 0; @@ -1188,10 +1189,21 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR if(file.exists()) { MediaMetadataRetriever metadata = new MediaMetadataRetriever(); metadata.setDataSource(file.getAbsolutePath()); - String tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE); - bitrate = Integer.parseInt((tmp != null) ? tmp : "0") / 1000; + + String tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); + duration = Integer.parseInt((tmp != null) ? tmp : "0") / 1000; format = FileUtil.getExtension(file.getName()); size = file.length(); + + // If no duration try to read bitrate tag + if(duration == null) { + tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE); + bitrate = Integer.parseInt((tmp != null) ? tmp : "0") / 1000; + } else { + // Otherwise do a calculation for it + // Divide by 1000 so in kbps + bitrate = (size / duration) / 1000; + } if(Util.isOffline(context)) { song.setGenre(metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE)); -- cgit v1.2.3