diff --git a/src/ch/blinkenlights/android/vanilla/CompatMetadata.java b/src/ch/blinkenlights/android/vanilla/CompatMetadata.java deleted file mode 100644 index 15b7625a..00000000 --- a/src/ch/blinkenlights/android/vanilla/CompatMetadata.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2012 Christopher Eby - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package ch.blinkenlights.android.vanilla; - -import android.annotation.TargetApi; -import android.media.MediaMetadataRetriever; - -/** - * Wrapper around MediaMetadataRetriever to allow compatibility with older - * versions of Android. - */ -@TargetApi(10) -public class CompatMetadata { - /** - * The wrapped MediaMetadataRetriever instance. - */ - private final MediaMetadataRetriever mData; - - /** - * Create an MediaMetadataRetriever attached to the file at the given path. - */ - public CompatMetadata(String path) - { - MediaMetadataRetriever data = new MediaMetadataRetriever(); - data.setDataSource(path); - mData = data; - } - - /** - * Call {@link MediaMetadataRetriever#extractMetadata(int)}. - */ - public String extractMetadata(int keyCode) - { - return mData.extractMetadata(keyCode); - } - - /** - * Call {@link MediaMetadataRetriever#release()}. - */ - public void release() - { - mData.release(); - } -} diff --git a/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java b/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java index 2d3e160d..9f753959 100644 --- a/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java +++ b/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java @@ -513,15 +513,22 @@ public class FullPlaybackActivity extends PlaybackActivity { Song song = mCurrentSong; - if (song == null) { - mGenre = null; - mTrack = null; - mYear = null; - mComposer = null; - mFormat = null; - } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) { - CompatMetadata data = new CompatMetadata(song.path); + mGenre = null; + mTrack = null; + mYear = null; + mComposer = null; + mFormat = null; + if(song != null) { + + MediaMetadataRetriever data = new MediaMetadataRetriever(); + + try { + data.setDataSource(song.path); + } catch (Exception e) { + Log.w("VanillaMusic", "Failed to extract metadata from " + song.path); + } + mGenre = data.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE); mTrack = data.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER); String composer = data.extractMetadata(MediaMetadataRetriever.METADATA_KEY_COMPOSER); @@ -548,7 +555,6 @@ public class FullPlaybackActivity extends PlaybackActivity sb.append("kbps"); } mFormat = sb.toString(); - data.release(); }