简体   繁体   中英

How to convert video file to Base64 string and vice versa?

我想将视频文件转换为base64字符串,反之亦然,我的视频位于原始文件夹中。这是我的代码:

String uriPath = "android.resource://com.hello.videouploaddemo/raw/sendvideo";

First convert the raw file into a byte[]

InputStream inStream = context.getResources().openRawResource(R.raw.sendvideo);
byte[] video = new byte[inStream.available()];

Use the Android Base64 Class

public static byte[] encode (byte[] input, int flags)

byte[] base64 = Base64.encode(video,Base64.DEFAULT);

public static byte[] decode (byte[] input, int offset, int len, int flags)

byte[] rowVideoAgain = Base64.decode(base64,0,base64.length,Base64.DEFAULT);

http://developer.android.com/reference/android/util/Base64.html

You should start this in a AsyncTask http://developer.android.com/reference/android/os/AsyncTask.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM