File tree Expand file tree Collapse file tree 4 files changed +27
-21
lines changed
app/src/main/java/cafe/adriel/androidaudioconverter/sample
lib/src/main/java/cafe/adriel/androidaudioconverter Expand file tree Collapse file tree 4 files changed +27
-21
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ public class App extends Application {
3434 // Great!
3535 }
3636 @Override
37- public void onFailure (FFmpegNotSupportedException error ) {
37+ public void onFailure (Exception error ) {
3838 // FFmpeg is not supported by device
3939 }
4040 });
@@ -44,7 +44,7 @@ public class App extends Application {
4444
45453 - Convert audio files async
4646``` java
47- File wavFile = new File (Environment . getExternalStorageDirectory(), " my_audio.flac" );
47+ File flacFile = new File (Environment . getExternalStorageDirectory(), " my_audio.flac" );
4848IConvertCallback callback = new IConvertCallback () {
4949 @Override
5050 public void onSuccess (File convertedFile ) {
@@ -57,11 +57,15 @@ IConvertCallback callback = new IConvertCallback() {
5757};
5858AndroidAudioConverter . with(this )
5959 // Your current audio file
60- .setFile(wavFile)
60+ .setFile(flacFile)
61+
6162 // Your desired audio format
62- .setFormat(AndroidAudioConverter . AudioFormat . MP3 )
63+ .setFormat(AudioFormat . MP3 )
64+
6365 // An callback to know when conversion is finished
6466 .setCallback(callback)
67+
68+ // Start conversion
6569 .convert();
6670```
6771
@@ -75,7 +79,7 @@ repositories {
7579}
7680
7781dependencies {
78- compile 'com.github.adrielcafe:AndroidAudioConverter:0.0.7 '
82+ compile 'com.github.adrielcafe:AndroidAudioConverter:0.0.8 '
7983}
8084```
8185
Original file line number Diff line number Diff line change 1212
1313import cafe .adriel .androidaudioconverter .AndroidAudioConverter ;
1414import cafe .adriel .androidaudioconverter .callback .IConvertCallback ;
15+ import cafe .adriel .androidaudioconverter .model .AudioFormat ;
1516
1617public class MainActivity extends AppCompatActivity {
1718
@@ -48,7 +49,7 @@ public void onFailure(Exception error) {
4849 Toast .makeText (this , "Converting audio file..." , Toast .LENGTH_SHORT ).show ();
4950 AndroidAudioConverter .with (this )
5051 .setFile (wavFile )
51- .setFormat (AndroidAudioConverter . AudioFormat .MP3 )
52+ .setFormat (AudioFormat .MP3 )
5253 .setCallback (callback )
5354 .convert ();
5455 }
Original file line number Diff line number Diff line change 1111
1212import cafe .adriel .androidaudioconverter .callback .IConvertCallback ;
1313import cafe .adriel .androidaudioconverter .callback .ILoadCallback ;
14+ import cafe .adriel .androidaudioconverter .model .AudioFormat ;
1415
1516public class AndroidAudioConverter {
1617
17- public enum AudioFormat {
18- AAC ,
19- MP3 ,
20- M4A ,
21- WMA ,
22- WAV ,
23- FLAC ;
24-
25- @ Override
26- public String toString () {
27- return name ().toLowerCase ();
28- }
29- }
30-
3118 private static boolean loaded ;
3219
3320 private Context context ;
@@ -142,7 +129,7 @@ public void onFinish() {
142129
143130 private static File getConvertedFile (File originalFile , AudioFormat format ){
144131 String [] f = originalFile .getPath ().split ("\\ ." );
145- String filePath = originalFile .getPath ().replace (f [f .length - 1 ], format .toString ());
132+ String filePath = originalFile .getPath ().replace (f [f .length - 1 ], format .getFormat ());
146133 return new File (filePath );
147134 }
148135}
Original file line number Diff line number Diff line change 1+ package cafe .adriel .androidaudioconverter .model ;
2+
3+ public enum AudioFormat {
4+ AAC ,
5+ MP3 ,
6+ M4A ,
7+ WMA ,
8+ WAV ,
9+ FLAC ;
10+
11+ public String getFormat () {
12+ return name ().toLowerCase ();
13+ }
14+ }
You can’t perform that action at this time.
0 commit comments