如何将视频文件转换为Base64字符串,反之亦然?

时间:2014-02-28 10:59:34

标签: android

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

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

1 个答案:

答案 0 :(得分:1)

首先将原始文件转换为byte[]

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

使用Android Base64

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

您应该在AsyncTask中启动它 http://developer.android.com/reference/android/os/AsyncTask.html