base64 encode audio file and send as a String then decode the String

前端 未结 2 1039
青春惊慌失措
青春惊慌失措 2020-12-14 22:58

I have been stuck on this issue for a few hours now trying to get it working. Basically what I am trying to do is the following. Base64 encode an audio file picked up from a

2条回答
  •  生来不讨喜
    2020-12-14 23:34

    Decoding base64 string file to .m4a file format

    try
    {
        String audioDataString = "";
        BufferedReader jsonReader = new BufferedReader(new InputStreamReader(this.getResources().openRawResource(R.raw.audioBase64File)));
        StringBuilder jsonBuilder = new StringBuilder();
        for (String line = null; (line = jsonReader.readLine()) != null; ) {
            jsonBuilder.append(line).append("");
        }
        audioDataString = jsonBuilder.toString();
        byte[] decoded = Base64.decode(audioDataString, Base64.DEFAULT);
        try {
            File file2 = new File(Environment.getExternalStorageDirectory() + "/faakhir_testAudio.m4a");
            FileOutputStream os = new FileOutputStream(file2, true);
            os.write(decoded);
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    } catch(Exception e){
        e.printStackTrace();
    }
    

提交回复
热议问题