如何在ffmpeg库中使用SoxController类在android中?任何例子

时间:2013-07-18 06:05:54

标签: android

使用SoxController类时遇到问题。 。 Can可以在SoxController类中给我一个trimaudio函数的例子。 。

1 个答案:

答案 0 :(得分:0)

试试这个,我觉得它对你来说很完美,因为我已经测过了。它运作良好

/**
 * Trim File Wave
 */
public class TrimFileWave extends AsyncTask<String, Void, Void> {
    private ProgressDialogUtil progressDialogUtil;
    private Context            context;

    public TrimFileWave(Context context) {
        this.context = context;
        progressDialogUtil = new ProgressDialogUtil(context, R.string.progressing);
    }

    @Override
    protected void onPreExecute() {
        progressDialogUtil.show();
    }

    @Override
    protected Void doInBackground(String... params) {
        startTrimFile();
        return null;
    }

    @Override
    protected void onPostExecute(Void unused) {
        progressDialogUtil.dismiss();
    }

    private void startTrimFile() {
        File fileAppRoot = new File(context.getApplicationInfo().dataDir);
        try {
            SoxController sxCon = new SoxController(context, fileAppRoot, new ShellUtils.ShellCallback() {
                @Override
                public void shellOut(String shellLine) {
                    DebugUtil.log(new Exception(), shellLine);
                }

                @Override
                public void processComplete(int exitValue) {
                    DebugUtil.log(new Exception(), exitValue);
                }
            });
            double length = sxCon.getLength(MyApplication.FILE_NAME_RECORDED_WAVE);
            DebugUtil.log(new Exception(), "[length]" + length);
            // sxCon.trimAudio(MyApplication.FILE_MERGE_WAVE, 0, length);
            // Type {"q", "h", "t", "l", "p"}
            sxCon.fadeAudio(MyApplication.FILE_MERGE_WAVE, "t", 0, length, 1);
        }
        catch (Exception e) {
            DebugUtil.logInfo(new Exception(), e.toString());
        }
    }

}