I'm using jcodec
.
I'm trying to set cover art to an mp4 file, but it's not working. I've done the following:
fun AppCompatActivity.setAlbumCover(filePath: String) {
try {
val file = File(filePath)
val bitmap = ThumbnailUtils.createVideoThumbnail(file.absolutePath, MediaStore.Video.Thumbnails.MINI_KIND)
if (bitmap != null) {
val byteArrayOutputStream = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream)
val byteArray = byteArrayOutputStream.toByteArray()
val base64Str = Base64.encodeToString(byteArray, Base64.DEFAULT)
if (base64Str != null) {
val mediaMeta = MetadataEditor.createFrom(file)
if (mediaMeta != null) {
val meta = mediaMeta.keyedMeta
if (meta != null) {
meta["coverart"] = MetaValue.createString(base64Str)
}
mediaMeta.save(false)
}
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
After that I upload this video to server and when I load the thumbnail from video URL using MediaMetadataRetriever::getEmbededPicture
. It should return byte[]
not null
.
How to achieve this?
Use Itunes metaData and code 0x636F7672.
For example: