我正在尝试将音频/视频转换为字节数组,反之亦然, 使用下面的代码可以将音频/视频文件转换为字节数组(见下面的代码)但是我无法转换大文件(超过 50MB 的文件)是否有任何限制。? 如何将字节数组转换为音频/视频文件。?请帮帮我。
public byte[] convert(String path) throws IOException {
FileInputStream fis = new FileInputStream(path);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
for (int readNum; (readNum = fis.read(b)) != -1;) {
bos.write(b, 0, readNum);
}
byte[] bytes = bos.toByteArray();
return bytes;
}
请帮忙出结果
最佳答案
谢谢...在您的帮助下我得到了解决方案,将字节转换为文件(音频/视频),请参见下面的代码。
private void convertBytesToFile(byte[] bytearray) {
try {
File outputFile = File.createTempFile("file", "mp3", getCacheDir());
outputFile.deleteOnExit();
FileOutputStream fileoutputstream = new FileOutputStream(tempMp3);
fileoutputstream.write(bytearray);
fileoutputstream.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
**文件输出文件 = File.createTempFile("文件", "mp3", getCacheDir());
outputFile 包含路径,用它来播放您的音频/视频文件**
关于android - 如何在 android 中将视频/音频文件转换为字节数组,反之亦然?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34923169/