[Android] Prevent NPE due to Bitmap format issue
Geoffrey Métais
git at videolan.org
Wed Mar 11 18:26:40 CET 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Mar 11 18:25:08 2015 +0100| [07069f2ad8c0195088948a7f7ae82d1e11f7ad34] | committer: Geoffrey Métais
Prevent NPE due to Bitmap format issue
+ Refactoring
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=07069f2ad8c0195088948a7f7ae82d1e11f7ad34
---
vlc-android/src/org/videolan/vlc/MediaWrapperList.java | 3 +++
.../src/org/videolan/vlc/audio/AudioService.java | 16 ++++++++--------
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/MediaWrapperList.java b/vlc-android/src/org/videolan/vlc/MediaWrapperList.java
index f955820..fedc351 100644
--- a/vlc-android/src/org/videolan/vlc/MediaWrapperList.java
+++ b/vlc-android/src/org/videolan/vlc/MediaWrapperList.java
@@ -20,6 +20,8 @@
*****************************************************************************/
package org.videolan.vlc;
+import android.support.annotation.Nullable;
+
import java.util.ArrayList;
import org.videolan.libvlc.LibVLC;
@@ -141,6 +143,7 @@ public class MediaWrapperList {
return mInternalList.size();
}
+ @Nullable
public MediaWrapper getMedia(int position) {
if (!isValid(position))
return null;
diff --git a/vlc-android/src/org/videolan/vlc/audio/AudioService.java b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
index f873a77..cf7add9 100644
--- a/vlc-android/src/org/videolan/vlc/audio/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/audio/AudioService.java
@@ -47,6 +47,7 @@ import android.os.Message;
import android.os.PowerManager;
import android.os.RemoteException;
import android.preference.PreferenceManager;
+import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.telephony.TelephonyManager;
import android.util.Log;
@@ -649,6 +650,7 @@ public class AudioService extends Service {
*
* @return The current media or null if there is not any.
*/
+ @Nullable
private MediaWrapper getCurrentMedia() {
return mMediaListPlayer.getMediaList().getMedia(mCurrentIndex);
}
@@ -935,9 +937,12 @@ public class AudioService extends Service {
editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, Util.getMediaGenre(this, media));
editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle());
editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength());
+
// Copy the cover bitmap because the RemonteControlClient can recycle its artwork bitmap.
- Bitmap cover = getCover();
- editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, ((cover != null) ? cover.copy(cover.getConfig(), false) : null));
+ Bitmap cover = AudioUtil.getCover(this, media, 512);
+ if (cover != null && cover.getConfig() != null) //In case of format not supported
+ editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, (cover.copy(cover.getConfig(), false)));
+
editor.apply();
}
@@ -989,11 +994,6 @@ public class AudioService extends Service {
determinePrevAndNextIndices();
}
- private Bitmap getCover() {
- MediaWrapper media = getCurrentMedia();
- return media != null ? AudioUtil.getCover(this, media, 512) : null;
- }
-
private final IAudioService.Stub mInterface = new IAudioService.Stub() {
@Override
@@ -1093,7 +1093,7 @@ public class AudioService extends Service {
@Override
public Bitmap getCover() {
if (hasCurrentMedia()) {
- return AudioService.this.getCover();
+ return AudioUtil.getCover(AudioService.this, getCurrentMedia(), 512);
}
return null;
}
More information about the Android
mailing list