将Webm或m4a文件转换为mp3

时间:2018-04-02 09:46:13

标签: java android type-conversion mp3 webm

有没有办法将webm和m4a文件转换为mp3在android studio中。 因为更改文件扩展名使它看起来像mp3文件,但在更改扩展名后无法访问... webm和m4a文件只包含音频。

2 个答案:

答案 0 :(得分:1)

您可以轻松地执行https://github.com/adrielcafe/AndroidAudioConverter

您需要使用

将其导入项目
repositories {
  maven {
    url "https://jitpack.io"
  }
}

dependencies {
  compile 'com.github.adrielcafe:AndroidAudioConverter:0.0.8'
}

并且根据github页面,您还需要编译com.github.hiteshsondhi88.libffmpeg dependencie。

答案 1 :(得分:1)

这是我用过的ffmpeg的功能.....我只是导入了ffmpeg库..

private void calculate(final String title , final String Type, final int id){
    FFmpeg ffmpeg = FFmpeg.getInstance(getApplicationContext());
    try {
        // to execute "ffmpeg -version" command you just need to pass "-version"
        ffmpeg.execute(new String[]{"-i",Environment.getExternalStoragePublicDirectory(DIRECTORY_MUSIC)+"/"+title+"."+Type, Environment.getExternalStoragePublicDirectory(DIRECTORY_MUSIC)+"/"+title+".mp3"}, new ExecuteBinaryResponseHandler() {

            @Override
            public void onStart() {}

            @Override
            public void onProgress(String message) {
                Log.d("ffmpegevent", "onProgress: "+message);
            }

            @Override
            public void onFailure(String message) {
                Log.d("ffmpegevent", "onProgress: "+message);
                Log.d("ffmpegevent", "onFailure: ");
            }

            @Override
            public void onSuccess(String message) {
                Log.d("ffmpegevent", "onSuccess: ");

            }

            @Override
            public void onFinish() {
                Log.d("ffmpegevent", "onProgress: Finished");
            }
        });
    } catch (FFmpegCommandAlreadyRunningException e) {
        // Handle if FFmpeg is already running
    }

}