Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Geoffrey Métais
VLC-Android
Commits
55265e3f
Commit
55265e3f
authored
May 16, 2018
by
Geoffrey Métais
Browse files
Pass image width to thumbnail provider
parent
3d776270
Changes
2
Hide whitespace changes
Inline
Side-by-side
vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
View file @
55265e3f
...
...
@@ -69,11 +69,9 @@ private suspend fun getImage(v: View, item: MediaLibraryItem, binding: ViewDataB
binding
?.
removeOnRebindCallback
(
rebindCallbacks
!!
)
}
private
suspend
fun
obtainBitmap
(
item
:
MediaLibraryItem
,
width
:
Int
)
:
Bitmap
?
{
return
withContext
(
VLCIO
)
{
if
(
item
.
itemType
==
MediaLibraryItem
.
TYPE_MEDIA
)
ThumbnailsProvider
.
getMediaThumbnail
(
item
as
MediaWrapper
)
else
AudioUtil
.
readCoverBitmap
(
Uri
.
decode
(
item
.
artworkMrl
),
width
)
}
private
suspend
fun
obtainBitmap
(
item
:
MediaLibraryItem
,
width
:
Int
)
=
withContext
(
VLCIO
)
{
if
(
item
.
itemType
==
MediaLibraryItem
.
TYPE_MEDIA
)
ThumbnailsProvider
.
getMediaThumbnail
(
item
as
MediaWrapper
,
width
)
else
AudioUtil
.
readCoverBitmap
(
Uri
.
decode
(
item
.
artworkMrl
),
width
)
}
@MainThread
...
...
vlc-android/src/org/videolan/vlc/util/ThumbnailsProvider.java
View file @
55265e3f
...
...
@@ -12,7 +12,6 @@ import android.text.TextUtils;
import
org.videolan.medialibrary.Medialibrary
;
import
org.videolan.medialibrary.media.MediaLibraryItem
;
import
org.videolan.medialibrary.media.MediaWrapper
;
import
org.videolan.vlc.R
;
import
org.videolan.vlc.VLCApplication
;
import
org.videolan.vlc.gui.helpers.AudioUtil
;
import
org.videolan.vlc.gui.helpers.BitmapCache
;
...
...
@@ -32,14 +31,13 @@ public class ThumbnailsProvider {
private
static
File
appDir
;
private
static
String
cacheDir
;
private
static
final
int
sImageWidth
=
VLCApplication
.
getAppResources
().
getDimensionPixelSize
(
VLCApplication
.
showTvUi
()
?
R
.
dimen
.
tv_grid_card_thumb_width
:
R
.
dimen
.
grid_card_thumb_width
);
private
static
final
int
MAX_IMAGES
=
4
;
@WorkerThread
public
static
Bitmap
getMediaThumbnail
(
final
MediaWrapper
item
)
{
if
(
item
.
getType
()
==
MediaWrapper
.
TYPE_GROUP
)
return
ThumbnailsProvider
.
getComposedImage
((
MediaGroup
)
item
);
if
(
item
.
getType
()
==
MediaWrapper
.
TYPE_VIDEO
&&
TextUtils
.
isEmpty
(
item
.
getArtworkMrl
()))
return
getVideoThumbnail
(
item
);
else
return
AudioUtil
.
readCoverBitmap
(
Uri
.
decode
(
item
.
getArtworkMrl
()),
sImageW
idth
);
public
static
Bitmap
getMediaThumbnail
(
final
MediaWrapper
item
,
int
width
)
{
if
(
item
.
getType
()
==
MediaWrapper
.
TYPE_GROUP
)
return
ThumbnailsProvider
.
getComposedImage
((
MediaGroup
)
item
,
width
);
if
(
item
.
getType
()
==
MediaWrapper
.
TYPE_VIDEO
&&
TextUtils
.
isEmpty
(
item
.
getArtworkMrl
()))
return
getVideoThumbnail
(
item
,
width
);
else
return
AudioUtil
.
readCoverBitmap
(
Uri
.
decode
(
item
.
getArtworkMrl
()),
w
idth
);
}
public
static
String
getMediaCacheKey
(
boolean
isMedia
,
MediaLibraryItem
item
)
{
...
...
@@ -53,14 +51,14 @@ public class ThumbnailsProvider {
}
@WorkerThread
private
static
Bitmap
getVideoThumbnail
(
final
MediaWrapper
media
)
{
private
static
Bitmap
getVideoThumbnail
(
final
MediaWrapper
media
,
int
width
)
{
final
String
filePath
=
media
.
getUri
().
getPath
();
if
(
appDir
==
null
)
appDir
=
VLCApplication
.
getAppContext
().
getExternalFilesDir
(
null
);
final
boolean
hasCache
=
appDir
!=
null
&&
appDir
.
exists
();
final
String
thumbPath
=
getMediaCacheKey
(
true
,
media
);
final
Bitmap
cacheBM
=
hasCache
?
BitmapCache
.
getInstance
().
getBitmapFromMemCache
(
thumbPath
)
:
null
;
if
(
cacheBM
!=
null
)
return
cacheBM
;
if
(
hasCache
&&
new
File
(
thumbPath
).
exists
())
return
readCoverBitmap
(
thumbPath
,
sImageW
idth
);
if
(
hasCache
&&
new
File
(
thumbPath
).
exists
())
return
readCoverBitmap
(
thumbPath
,
w
idth
);
if
(
media
.
isThumbnailGenerated
())
return
null
;
final
Bitmap
bitmap
=
ThumbnailUtils
.
createVideoThumbnail
(
filePath
,
MediaStore
.
Video
.
Thumbnails
.
MINI_KIND
);
if
(
bitmap
!=
null
)
{
...
...
@@ -76,12 +74,12 @@ public class ThumbnailsProvider {
}
@WorkerThread
private
static
Bitmap
getComposedImage
(
MediaGroup
group
)
{
private
static
Bitmap
getComposedImage
(
MediaGroup
group
,
int
width
)
{
final
BitmapCache
bmc
=
BitmapCache
.
getInstance
();
final
String
key
=
"group:"
+
group
.
getTitle
();
Bitmap
composedImage
=
bmc
.
getBitmapFromMemCache
(
key
);
if
(
composedImage
==
null
)
{
composedImage
=
composeImage
(
group
);
composedImage
=
composeImage
(
group
,
width
);
if
(
composedImage
!=
null
)
bmc
.
addBitmapToMemCache
(
key
,
composedImage
);
}
return
composedImage
;
...
...
@@ -91,11 +89,11 @@ public class ThumbnailsProvider {
* @param group The MediaGroup instance
* @return a Bitmap object
*/
private
static
Bitmap
composeImage
(
MediaGroup
group
)
{
private
static
Bitmap
composeImage
(
MediaGroup
group
,
int
imageWidth
)
{
final
Bitmap
[]
sourcesImages
=
new
Bitmap
[
Math
.
min
(
MAX_IMAGES
,
group
.
size
())];
int
count
=
0
,
minWidth
=
Integer
.
MAX_VALUE
,
minHeight
=
Integer
.
MAX_VALUE
;
for
(
MediaWrapper
media
:
group
.
getAll
())
{
final
Bitmap
bm
=
getVideoThumbnail
(
media
);
final
Bitmap
bm
=
getVideoThumbnail
(
media
,
imageWidth
);
if
(
bm
!=
null
)
{
int
width
=
bm
.
getWidth
();
int
height
=
bm
.
getHeight
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment