diff --git a/README.md b/README.md index d6a3ba6..8e6b4e4 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ public class App extends Application { // Great! } @Override - public void onFailure(FFmpegNotSupportedException error) { + public void onFailure(Exception error) { // FFmpeg is not supported by device } }); @@ -44,7 +44,7 @@ public class App extends Application { 3 - Convert audio files async ```java -File wavFile = new File(Environment.getExternalStorageDirectory(), "my_audio.flac"); +File flacFile = new File(Environment.getExternalStorageDirectory(), "my_audio.flac"); IConvertCallback callback = new IConvertCallback() { @Override public void onSuccess(File convertedFile) { @@ -57,11 +57,15 @@ IConvertCallback callback = new IConvertCallback() { }; AndroidAudioConverter.with(this) // Your current audio file - .setFile(wavFile) + .setFile(flacFile) + // Your desired audio format - .setFormat(AndroidAudioConverter.AudioFormat.MP3) + .setFormat(AudioFormat.MP3) + // An callback to know when conversion is finished .setCallback(callback) + + // Start conversion .convert(); ``` @@ -75,7 +79,7 @@ repositories { } dependencies { - compile 'com.github.adrielcafe:AndroidAudioConverter:0.0.7' + compile 'com.github.adrielcafe:AndroidAudioConverter:0.0.8' } ``` diff --git a/app/src/main/java/cafe/adriel/androidaudioconverter/sample/MainActivity.java b/app/src/main/java/cafe/adriel/androidaudioconverter/sample/MainActivity.java index 1e8c58c..243b7f3 100644 --- a/app/src/main/java/cafe/adriel/androidaudioconverter/sample/MainActivity.java +++ b/app/src/main/java/cafe/adriel/androidaudioconverter/sample/MainActivity.java @@ -12,6 +12,7 @@ import cafe.adriel.androidaudioconverter.AndroidAudioConverter; import cafe.adriel.androidaudioconverter.callback.IConvertCallback; +import cafe.adriel.androidaudioconverter.model.AudioFormat; public class MainActivity extends AppCompatActivity { @@ -48,7 +49,7 @@ public void onFailure(Exception error) { Toast.makeText(this, "Converting audio file...", Toast.LENGTH_SHORT).show(); AndroidAudioConverter.with(this) .setFile(wavFile) - .setFormat(AndroidAudioConverter.AudioFormat.MP3) + .setFormat(AudioFormat.MP3) .setCallback(callback) .convert(); } diff --git a/lib/src/main/java/cafe/adriel/androidaudioconverter/AndroidAudioConverter.java b/lib/src/main/java/cafe/adriel/androidaudioconverter/AndroidAudioConverter.java index aeda380..95bf226 100644 --- a/lib/src/main/java/cafe/adriel/androidaudioconverter/AndroidAudioConverter.java +++ b/lib/src/main/java/cafe/adriel/androidaudioconverter/AndroidAudioConverter.java @@ -11,23 +11,10 @@ import cafe.adriel.androidaudioconverter.callback.IConvertCallback; import cafe.adriel.androidaudioconverter.callback.ILoadCallback; +import cafe.adriel.androidaudioconverter.model.AudioFormat; public class AndroidAudioConverter { - public enum AudioFormat { - AAC, - MP3, - M4A, - WMA, - WAV, - FLAC; - - @Override - public String toString() { - return name().toLowerCase(); - } - } - private static boolean loaded; private Context context; @@ -142,7 +129,7 @@ public void onFinish() { private static File getConvertedFile(File originalFile, AudioFormat format){ String[] f = originalFile.getPath().split("\\."); - String filePath = originalFile.getPath().replace(f[f.length - 1], format.toString()); + String filePath = originalFile.getPath().replace(f[f.length - 1], format.getFormat()); return new File(filePath); } } \ No newline at end of file diff --git a/lib/src/main/java/cafe/adriel/androidaudioconverter/model/AudioFormat.java b/lib/src/main/java/cafe/adriel/androidaudioconverter/model/AudioFormat.java new file mode 100644 index 0000000..4bc2ac8 --- /dev/null +++ b/lib/src/main/java/cafe/adriel/androidaudioconverter/model/AudioFormat.java @@ -0,0 +1,14 @@ +package cafe.adriel.androidaudioconverter.model; + +public enum AudioFormat { + AAC, + MP3, + M4A, + WMA, + WAV, + FLAC; + + public String getFormat() { + return name().toLowerCase(); + } +} \ No newline at end of file