0

I am developing an android application for mixing 2 audio files.And i use android ffmpeg for that.I use following lib. from GitHub https://github.com/guardianproject/android-ffmpeg-java

I use following code to mix 2 audio files from activity .

try {
             File fileAppRoot = new File(getApplicationInfo().dataDir);
             SoxController sxCon = new SoxController(fileAppRoot, new ShellUtils.ShellCallback() {
                    @Override
                    public void shellOut(String shellLine) {

                        System.out.println(shellLine);
                    }

                    @Override
                    public void processComplete(int exitValue) {

                    System.out.println("hello");
                    }
                });
             List<String> files=new ArrayList<String>();
             files.add(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Testing/me.mp3");
             files.add(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Testing/il.mp3");
             sxCon.combineMix(files,Environment.getExternalStorageDirectory().getAbsolutePath()+"/Testing/ial.mp3");

but this return exit value 2 on processComplete and no new file generated for mix audio. This will return following problem in logs no handler for file extension `mp3'

Thanks for any help on this..

2 Answers2

0

You cannot mix files mp3 with this library.

It cans mix files ".wave" only.

Let's convert your mp3 file to wave file then uset this lib to mix files wave.

I hope this response is good for you.

Thanks,

sonida
  • 4,411
  • 1
  • 38
  • 40
0

https://github.com/bravobit/FFmpeg-Android

implementation 'nl.bravobit:android-ffmpeg:1.1.7'

public boolean mergeAudio(final Context context, File[] voiceFile, String file_name) {

    final ProgressDialog asyncDialog = new ProgressDialog(context);
    asyncDialog.setMessage("Audio Merging Start..");
    asyncDialog.setCancelable(false);

    final boolean[] isSuccess = {false};
    if (file_name != null) {
        file_name = Environment.getExternalStorageDirectory() + "/podmod/" + file_name + "_.mp3";

    } else {
        file_name = getMusicFilename();
    }
    File ffmpegFile = new File(file_name);
    if (ffmpegFile.exists()) {
        ffmpegFile.delete();
    }

    for (File f : voiceFile) {
        if (!f.exists()) {
            Log.d("AudioMergingFailure", "File ot Exist");
            return isSuccess[0];
        }
    }
    String s = "";
    String s_index = "";
    String fileSize = "n=" + voiceFile.length;
    for (int i = 0; i < voiceFile.length; i++) {
        s = s + "-i@" + voiceFile[i].getPath() + "@";
        s_index = s_index + "[" + i + ":0]";

    }

    String str_cmd = s + "-filter_complex@" + s_index + "concat=" + fileSize + ":v=0:a=1[out]@-map@[out]@" + file_name;
    Log.d("str_cmd", str_cmd);

    String[] cmd = str_cmd.split("@");
    final String finalFile_name = file_name;
    try {
        if (FFmpeg.getInstance(context).isSupported()) {
            FFmpeg ffmpeg = FFmpeg.getInstance(context);
            // to execute "ffmpeg -version" command you just need to pass "-version"
            ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
                @Override
                public void onStart() {
                    asyncDialog.show();
                }

                @Override
                public void onProgress(String message) {
                }

                @Override
                public void onFailure(String message) {
                    Log.d("AudioMergingFailure", message);
                    asyncDialog.dismiss();
                    Toast.makeText(context, "Audio Merging Failed", 
                    Toast.LENGTH_LONG).show();

                }

                @Override
                public void onSuccess(String message) {
                    asyncDialog.dismiss();


                    Log.v("onSuccess", message);

                    File ffmpegFile_ = new File(finalFile_name);
                    Toast.makeText(context, "Audio onSuccess", 
                    Toast.LENGTH_LONG).show();


                    isSuccess[0] = true;
                }

                @Override
                public void onFinish() {

                    asyncDialog.dismiss();

                }

            });


        } else {

            asyncDialog.dismiss();

        }


    } catch (Exception e) {
        asyncDialog.dismiss();
        Log.d("NotException_", e.getMessage());
    }
    return isSuccess[0];
}

public static String getMusicFilename() {
    return Environment.getExternalStorageDirectory() + "/podmod/Merged_Audio_" + getRandomNumber(0, 100000) + ".mp3";
}