我开发PhoneGap的应用程序,现在我试图写一个插件转换.AMR文件,.mp3文件。我使用 JAVE 做到这一点的转换,虽然它的工作在桌面上它无法在Android与此异常:
java.io.IOException异常:EXEC错误运行()。
命令:[/数据/数据/&LT; my_package&GT; /缓存/ java的-1 / ffmpeg的,-I,/sdcard/<my_filename>.amr,-vn,-a codeC,libmp3lame,-f,MP3 ,-y,/sdcard/<my_filename>.mp3]
工作目录:空环境:空
我试图做这样的转换:
私人无效转换(字符串INPUT_FILE,CallbackContext callbackContext){
文件输入=新的文件(INPUT_FILE);
文件输出=新的文件(input_file.replace(AMR,.MP3));
恩codeR连接codeR =新恩codeR();
EncodingAttributes encodingAttributes =新EncodingAttributes();
AudioAttributes audioAttributes =新AudioAttributes();
audioAttributes.set codeC(libmp3lame);
encodingAttributes.setAudioAttributes(audioAttributes);
encodingAttributes.setFormat(MP3);
尝试{
EN coder.en code(输入,输出,encodingAttributes);
input.delete();
callbackContext.success(成品);
}
赶上(例外五){
callbackContext.error(e.getMessage());
}
}
我发现this回答我理解为什么发生错误,但答案没有提供任何解决方案。有没有办法得到这个工作在PhoneGap的项目?我需要与插件一起打包的ffmpeg库,并将其复制到正确的文件夹,当应用程序调用插件?
/数据/数据/&LT; my_package&GT; /缓存/ java的-1
解决方案
Stucked有同样的问题。现在我发现有问题的文件ffmpeg的权限。 JAVE试图将它们设置,但由于某些原因,它不能正常工作。 所以我设置此权限由我自己是这样的:
工艺过程= NULL;
DataOutputStream类DataOutputStream类= NULL;
尝试 {
流程=调用Runtime.getRuntime()EXEC(素)。
DataOutputStream类=新DataOutputStream类(process.getOutputStream());
dataOutputStream.writeBytes(搭配chmod 0755 __AppCachePath __ / java的-1 / ffmpeg的\ N);
dataOutputStream.writeBytes(退出\ n);
dataOutputStream.flush();
process.waitFor();
}赶上(例外五){
} 最后 {
尝试 {
如果(DataOutputStream类!= NULL){
dataOutputStream.close();
}
process.destroy();
}赶上(例外五){
}
}
在此文件的权限问题消失了。
I'm developing phonegap app and right now I'm trying to write a plugin to convert .amr files to .mp3 files. I'm using JAVE to do this conversion and while it's working on desktop it fails on android with this exception:
java.io.IOException: Error running exec().
Command: [/data/data/<my_package>/cache/jave-1/ffmpeg, -i, /sdcard/<my_filename>.amr, -vn, -acodec, libmp3lame, -f, mp3, -y, /sdcard/<my_filename>.mp3]
Working Directory: null Enviroment: null
I'm trying to do conversion like this:
private void convert(String input_file, CallbackContext callbackContext){
File input = new File(input_file);
File output = new File(input_file.replace(".amr", ".mp3"));
Encoder encoder = new Encoder();
EncodingAttributes encodingAttributes = new EncodingAttributes();
AudioAttributes audioAttributes = new AudioAttributes();
audioAttributes.setCodec("libmp3lame");
encodingAttributes.setAudioAttributes(audioAttributes);
encodingAttributes.setFormat("mp3");
try{
encoder.encode(input, output, encodingAttributes);
input.delete();
callbackContext.success("finished");
}
catch(Exception e){
callbackContext.error(e.getMessage());
}
}
I found this answer and I understand why error happens but the answer doesn't provide any solution. Is there a way to get this working in Phonegap project? Do I need to package ffmpeg library together with plugin and copy it to correct folder when app invokes the plugin?
/data/data/<my_package>/cache/jave-1
解决方案
Stucked with same problem. For now i found that there is problem with file ffmpeg permissions. JAVE trying to set them, but for some reason it not working. So i set this permission by myself like this:
Process process = null;
DataOutputStream dataOutputStream = null;
try {
process = Runtime.getRuntime().exec("su");
dataOutputStream = new DataOutputStream(process.getOutputStream());
dataOutputStream.writeBytes("chmod 0755 __AppCachePath__/jave-1/ffmpeg\n");
dataOutputStream.writeBytes("exit\n");
dataOutputStream.flush();
process.waitFor();
} catch (Exception e) {
} finally {
try {
if (dataOutputStream != null) {
dataOutputStream.close();
}
process.destroy();
} catch (Exception e) {
}
}
After this File permission problem goes away.