I am implementing a bring Images to life feature, this is the blog that I was following, and I tried to convert the URL image to bitmap but it seems not connecting to a local video.
I am using Picasso, to download the image as a bitmap from a URL but it can't seem to be working.
Below is my code :
override fun getSessionConfiguration(session: Session): Config {
fun loadAugmentedImageBitmap(imageName: String): Bitmap =
requireContext().assets.open(imageName).use { return BitmapFactory.decodeStream(it) }
val loader = activity?.applicationContext?.let { Coil.imageLoader(it) }
var hashMap: HashMap<String, String> = HashMap<String, String>()
hashMap.put(
TEST_VIDEO_1,
"https://res.cloudinary.com/do6g6dwlz/image/upload/v1594037658/lofsos15kot28ymz9fwb.jpg"
)
hashMap.put(
TEST_VIDEO_2,
"https://res.cloudinary.com/do6g6dwlz/image/upload/v1594038114/ijl9ngoomay9mleifv88.jpg"
)
hashMap.put(
TEST_VIDEO_3,
"https://res.cloudinary.com/do6g6dwlz/image/upload/v1594038131/po2fp4mviqsqkvwpztpe.jpg"
)
fun setupAugmentedImageDatabase(config: Config, session: Session): Boolean {
try {
config.augmentedImageDatabase = AugmentedImageDatabase(session).also { db ->
for ((key, value) in hashMap) {
print("load URL ---- $value")
Picasso.get().load(value).into(object : com.squareup.picasso.Target {
override fun onPrepareLoad(placeHolderDrawable: Drawable?) {
Toast.makeText(context,"Loading Images",Toast.LENGTH_SHORT).show()
}
override fun onBitmapFailed(
e: java.lang.Exception?,
errorDrawable: Drawable?
) {
Toast.makeText(context,"Something wrong happened",Toast.LENGTH_SHORT).show()
}
override fun onBitmapLoaded(
bitmap: Bitmap?,
from: Picasso.LoadedFrom?
) {
db.addImage(key, bitmap)
}
})
}
}
return true
} catch (e: IllegalArgumentException) {
Log.e(TAG, "Could not add bitmap to augmented image database", e)
} catch (e: IOException) {
Log.e(TAG, "IO exception loading augmented image bitmap.", e)
}
return false
}
return super.getSessionConfiguration(session).also {
it.lightEstimationMode = Config.LightEstimationMode.DISABLED
it.focusMode = Config.FocusMode.AUTO
if (!setupAugmentedImageDatabase(it, session)) {
Toast.makeText(
requireContext(),
"Could not setup augmented image database",
Toast.LENGTH_LONG
).show()
}
}
}
This is the entire class and as well as the repository link
NOTE:
When both the Images and Videos are in the local project, it works fine, but trying to access both via URL it doesn't work.