[Android] ThumbnailsProvider: Prevent NPE
Geoffrey Métais
git at videolan.org
Tue May 28 16:39:19 CEST 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue May 28 16:24:00 2019 +0200| [b794c160b730e447a50e964a586c950d0463ea3a] | committer: Geoffrey Métais
ThumbnailsProvider: Prevent NPE
> https://code.videolan.org/videolan/vlc-android/commit/b794c160b730e447a50e964a586c950d0463ea3a
---
vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt b/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt
index 8d4e4940b..1c81038df 100644
--- a/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.kt
@@ -64,17 +64,16 @@ object ThumbnailsProvider {
@WorkerThread
fun getVideoThumbnail(media: MediaWrapper, width: Int): Bitmap? {
- val filePath = media.uri.path
+ val filePath = media.uri.path ?: return null
if (appDir == null) appDir = VLCApplication.appContext.getExternalFilesDir(null)
- val hasCache = appDir != null && appDir!!.exists()
- val thumbPath = getMediaCacheKey(true, media)
+ val hasCache = appDir?.exists() == true
+ val thumbPath = getMediaCacheKey(true, media) ?: return null
val cacheBM = if (hasCache) BitmapCache.getBitmapFromMemCache(thumbPath) else null
if (cacheBM != null) return cacheBM
if (hasCache && File(thumbPath).exists()) return readCoverBitmap(thumbPath, width)
if (media.isThumbnailGenerated) return null
- val bitmap: Bitmap?
- synchronized(lock) {
- bitmap = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.MINI_KIND)
+ val bitmap = synchronized(lock) {
+ ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.MINI_KIND)
}
if (bitmap != null) {
BitmapCache.addBitmapToMemCache(thumbPath, bitmap)
More information about the Android
mailing list