catch setDataSource exception thrown by metadata reader
This commit is contained in:
parent
e59782e54e
commit
96daf91e3b
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2012 Christopher Eby <kreed@kreed.org>
|
||||
*
|
||||
* 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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user