2014-07-21 2 views
0

phonegap 앱을 개발 중이며 .amr 파일을 .mp3 파일로 변환하는 플러그인을 작성하려고합니다. 나는이 변환을 수행하는 JAVE를 사용하고 있는데이 바탕 화면에 일하고있는 동안이 예외와 안드로이드에 실패phonegap Android 프로젝트에서 sauronsoftware의 Jave 사용

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는 다음과 같이 변환 할 노력하고있어 : 내가 this answer을 발견

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()); 
    } 
} 

왜 오류가 발생하는지 이해하지만 대답은 해결책을 제공하지 않습니다. Phonegap 프로젝트에서이 작업을 수행 할 수있는 방법이 있습니까? 플러그인과 함께 ffmpeg 라이브러리를 패키징하고 앱이 플러그인을 호출 할 때 올바른 폴더에 복사해야합니까?

/data/data/<my_package>/cache/jave-1 

답변

0

같은 문제가 있습니다. 지금은 파일 ffmpeg 사용 권한에 문제가 있음을 발견했습니다. JAVE가 설정하려고했지만 어떤 이유로 작동하지 않습니다. 그래서 나는이 같은 자신에 의해이 권한을 설정 :이 파일 권한 문제가 사라집니다

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) { 
     } 
    } 

후.

+0

어떻게하면 ffmpeg를 실행할 수 있습니까? – patrick

관련 문제