android将视频转换为字节数组

时间:2014-05-26 14:05:22

标签: java android bytearray

我尝试在字节数组中转换来自SD卡的视频。我写了代码,但我做错了什么。我的代码中有什么问题?我不知道我做错了什么 这是我的来源

public byte[] readBytes(Uri uri) throws IOException {

    InputStream inputStream = getContentResolver().openInputStream(uri);
    ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();


    int bufferSize = 1024;
    byte[] buffer = new byte[bufferSize];


    int len = 0;
    while ((len = inputStream.read(buffer)) != -1) {
        byteBuffer.write(buffer, 0, len);

    }


    return byteBuffer.toByteArray();
}



upload_btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            String fileName = "video.mp4";
            String completePath = Environment.getExternalStorageDirectory()
                    + "/" + fileName;

            File file = new File(completePath);
            Uri imageUri = Uri.fromFile(file);
            try {
                byte[] bytes = readBytes(imageUri);
                Log.e("Byte Array is", String.valueOf(bytes));
                Toast.makeText(getApplicationContext(),
                        String.valueOf(bytes), Toast.LENGTH_LONG).show();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

我运行我的应用程序,结果是小的streang,而不是字节数组

0 个答案:

没有答案