https://kotlinlang.org logo
#android
Title
# android
s

shock 11

02/27/2024, 12:19 PM
Hello guys, So I am using rememberLauncherForActivityResult to start a camera activity(to take a video). I've been able to successfully retrieve the uri of the video. Now I want to be able send this video over a server, but I have to send it as a ByteArray, so my question is what is the best way to convert a video uri to a ByteArray in kotlin? There seems to lack a lot of guides on video, but only for images, string etc and they are also mostly done on java too
m

marlonlom

02/27/2024, 8:58 PM
Hi, this link form stackoverflow could give you an idea about it. https://stackoverflow.com/questions/10296734/image-uri-to-bytesarray
s

shock 11

02/27/2024, 9:54 PM
Thanks, I'll look into that
I am actually making use of the first answer but then I encountered a memory error, but I'll have a look at the others as well
lol actually just noticed the owner made some changes to the answer on this new post. Thanks again
m

marlonlom

02/28/2024, 5:02 PM
@shock 11 👏
s

shock 11

02/28/2024, 8:01 PM
@marlonlom it seems this method isn't recommended for large videos. So I will have to find some other way
m

marlonlom

02/29/2024, 4:11 PM
🤔 ... @shock 11 try this: https://stackoverflow.com/questions/7913384/how-to-convert-video-from-uri-to-byte in large videos, try to do this using coroutines and/or workmanager, as this could be a background operation
👍 1
s

shock 11

02/29/2024, 6:26 PM
yeah that's also a nice suggestion. I will consider that thank you
2 Views