为什么不在Android上工作?

时间:2016-02-29 13:33:30

标签: android mp3 mp4

我想将MP4文件转换为MP3文件。所以我只是用Jave来做。它在Windows平台上运行得很好,但它在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);
    }

}
}

2 个答案:

答案 0 :(得分:0)

事实上,我之前编写的代码效果非常好。

答案 1 :(得分:0)

您正在尝试运行可执行文件。如果你的设备中有cache / jave-1 / ffmpeg意味着这将运行,否则它不会。检查路径中的文件,否则指定正确的路径。