我这样解决它:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("Imagen este ", String.valueOf(data));
if(data!=null) {
switch (requestCode) {
case SELECT_VIDEO:
Uri selectedVideoUri = data.getData();
String[] projection = {MediaStore.Video.Media.DATA, MediaStore.Video.Media.SIZE, MediaStore.Video.Media.DURATION};
Cursor cursor = managedQuery(selectedVideoUri, projection, null, null, null);
cursor.moveToFirst();
String filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
Log.d("File Name:",filePath);
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.MINI_KIND);
// Setting the thumbnail of the video in to the image view
msImage.setImageBitmap(thumb);
InputStream inputStream = null;
// Converting the video in to the bytes
try
{
inputStream = getContentResolver().openInputStream(selectedVideoUri);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
byteBuffer = new ByteArrayOutputStream();
int len = 0;
try
{
while ((len = inputStream.read(buffer)) != -1)
{
byteBuffer.write(buffer, 0, len);
}
}
catch (IOException e)
{
e.printStackTrace();
}
System.out.println("converted!");
String videoData="";
//Converting bytes into base64
videoData = Base64.encodeToString(byteBuffer.toByteArray(), Base64.DEFAULT);
Log.d("VideoData**> " , videoData);
String sinSaltoFinal2 = videoData.trim();
String sinsinSalto2 = sinSaltoFinal2.replaceAll("\n", "");
Log.d("VideoData**> " , sinsinSalto2);
baseVideo = sinsinSalto2;
videoData有视频的base64 .. 我希望你服务,我工作完美