/**
* Function to convert a given audio file to MP3 format
*
* @param fileName - input file name
* @param errorCallback - function called if the file could not be converted
* @param successCallback - function called if the conversion was successful
*/
@ReactMethod
public void convertAudioFile(String fileName,
final Callback errorCallback,
final Callback successCallback) {
File flacFile = new File(Environment.getExternalStorageDirectory(), fileName);
Log.d("Output file location", Environment.getExternalStorageDirectory().toString() + fileName);
IConvertCallback callback = new IConvertCallback() {
@Override
public void onSuccess(File convertedFile) {
// So fast? Love it!
Log.d("rnaac notice", "convert success");
successCallback.invoke("convert success");
}
@Override
public void onFailure(Exception error) {
// Oops! Something went wrong
errorCallback.invoke("convert failure: " + error.toString());
Log.d("rnaac notice", error.toString());
error.printStackTrace();
}
};
AndroidAudioConverter.with(this.getReactApplicationContext())
// Your current audio file
.setFile(flacFile)
// Your desired audio format
.setFormat(AudioFormat.MP3)
// An callback to know when conversion is finished
.setCallback(callback)
// Start conversion
.convert();
}
ReactNativeAndroidAudioConverterModule.java 文件源码
java
阅读 30
收藏 0
点赞 0
评论 0
项目:ReactNativeAndroidAudioConverter
作者:
评论列表
文章目录