将音频路径转换为base64

时间:2017-10-16 06:59:32

标签: android audio

我正在将音频路径转换为base64并发送到服务器。我有音频路径但无法将其转换为base64。我试过这个:

        Uri uri = data.getData();
        //String str = getRealPathFromURI(uri);
        String   currentPath = Environment.getExternalStorageDirectory().getAbsolutePath()+uri.getPath();
        File file3= new File(currentPath);

        File[] files3 = file3.listFiles();
        int filesize= (int) file3.length();

        byte[] videoBytes;
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            InputStream inputStream = new FileInputStream(currentPath);
           // FileInputStream fis = new FileInputStream(new File(currentPath));
            byte[] buf = new byte[1024];
            int n;
            while (-1 != (n = inputStream.read(buf)))
                baos.write(buf, 0, n);
                videoBytes = baos.toByteArray();
                encodedImage = Base64.encodeToString(videoBytes,Base64.DEFAULT);

        } catch (Exception e) {
            e.printStackTrace();
        }

0 个答案:

没有答案