0
我想將MP4文件轉換爲MP3文件。所以我只是用Jave來做。它在Windows平臺上運行得非常好,但它在Android中引發錯誤。爲什麼不在Android上工作?
02-29 21:08:41.440 6946-7718/com.example.pulltorefreshtest W/System.err: it.sauronsoftware.jave.EncoderException: java.io.IOException: Error running exec(). Command: [/data/data/com.example.pulltorefreshtest/cache/jave-1/ffmpeg, -i, /storage/emulated/0/Android/data/com.example.pulltorefreshtest/cache/input.mp4, -vn, -acodec, libmp3lame, -ab, 64000, -ac, 2, -ar, 44100, -f, mp3, -y, /storage/emulated/0/Android/data/com.example.pulltorefreshtest/cache/hk2.mp3] Working Directory: null Environment: null
02-29 21:08:41.440 6946-7718/com.example.pulltorefreshtest W/System.err: at it.sauronsoftware.jave.Encoder.encode(Encoder.java:831)
02-29 21:08:41.440 6946-7718/com.example.pulltorefreshtest W/System.err: at com.example.pulltorefreshtest.Mp4ToMp3.run(Mp4ToMp3.java:47)
02-29 21:08:41.440 6946-7718/com.example.pulltorefreshtest W/System.err: Caused by: java.io.IOException: Error running exec(). Command: [/data/data/com.example.pulltorefreshtest/cache/jave-1/ffmpeg, -i, /storage/emulated/0/Android/data/com.example.pulltorefreshtest/cache/input.mp4, -vn, -acodec, libmp3lame, -ab, 64000, -ac, 2, -ar, 44100, -f, mp3, -y, /storage/emulated/0/Android/data/com.example.pulltorefreshtest/cache/hk2.mp3] Working Directory: null Environment: null
02-29 21:08:41.440 6946-7718/com.example.pulltorefreshtest W/System.err: at java.lang.ProcessManager.exec(ProcessManager.java:211)
02-29 21:08:41.440 6946-7718/com.example.pulltorefreshtest W/System.err: at java.lang.Runtime.exec(Runtime.java:173)
02-29 21:08:41.440 6946-7718/com.example.pulltorefreshtest W/System.err: at java.lang.Runtime.exec(Runtime.java:128)
02-29 21:08:41.440 6946-7718/com.example.pulltorefreshtest W/System.err: at it.sauronsoftware.jave.FFMPEGExecutor.execute(FFMPEGExecutor.java:103)
02-29 21:08:41.440 6946-7718/com.example.pulltorefreshtest W/System.err: at it.sauronsoftware.jave.Encoder.encode(Encoder.java:829)
02-29 21:08:41.440 6946-7718/com.example.pulltorefreshtest W/System.err: ... 1 more
02-29 21:08:41.440 6946-7718/com.example.pulltorefreshtest W/System.err: Caused by: java.io.IOException: Permission denied
02-29 21:08:41.440 6946-7718/com.example.pulltorefreshtest W/System.err: at java.lang.ProcessManager.exec(Native Method)
02-29 21:08:41.440 6946-7718/com.example.pulltorefreshtest W/System.err: at java.lang.ProcessManager.exec(ProcessManager.java:209)
02-29 21:08:41.440 6946-7718/com.example.pulltorefreshtest W/System.err: ... 5 more
這是我的代碼,它在encoder.encoder函數中拋出一個錯誤。
package com.example.pulltorefreshtest;
import android.util.Log;
import android.widget.Toast;
import java.io.File;
import it.sauronsoftware.jave.AudioAttributes;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.EncodingAttributes;
import it.sauronsoftware.jave.MultimediaInfo;
import it.sauronsoftware.jave.Encoder;
/**
* Created by kankan on 2016/2/28.
*/
public class Mp4ToMp3 extends Thread {
Encoder encoder = null;
AudioAttributes audioAttributes = null;
EncodingAttributes encodingAttributes = null;
MyListener myListener = null;
File source = null;
File target = null;
public Mp4ToMp3(String inputFile, String outFile){
source = new File(inputFile);
target = new File(outFile);
audioAttributes = new AudioAttributes();
audioAttributes.setCodec("libmp3lame");
audioAttributes.setBitRate(new Integer(64000));
audioAttributes.setChannels(new Integer(2));
audioAttributes.setSamplingRate(new Integer(44100));
encodingAttributes = new EncodingAttributes();
encodingAttributes.setFormat("mp3");
encodingAttributes.setAudioAttributes(audioAttributes);
}
@Override
public void run() {
// MyListener myListener = new MyListener();
Encoder encoder = new Encoder();
try {
Log.i("hk","run");
encoder.encode(source, target, encodingAttributes, myListener);
} catch (EncoderException e) {
e.printStackTrace();
}
}
class MyListener implements it.sauronsoftware.jave.EncoderProgressListener{
@Override
public void message(String arg0) {
// TODO Auto-generated method stub
// System.out.println(arg0);
}
@Override
public void progress(int arg0) {
// TODO Auto-generated method stub
//System.out.print(arg0);
//System.out.println(arg0);
String string = String .format("%d",arg0);
Log.d("hk",string);
}
@Override
public void sourceInfo(MultimediaInfo arg0) {
// TODO Auto-generated method stub
String string = arg0.toString();
//System.out.println(string);
}
}
}
我不認爲java的是在Android的實施做出..... – Opiatefuchs