diff --git a/app/build.gradle b/app/build.gradle index b07e9bc..303cc47 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "com.github.axet.audiorecorder" minSdkVersion 9 targetSdkVersion 23 - versionCode 99 - versionName "1.3.1" + versionCode 100 + versionName "1.3.2" } signingConfigs { release { @@ -43,6 +43,6 @@ dependencies { compile 'com.android.support:design:25.1.1' compile 'com.google.android.gms:play-services-appindexing:9.8.0' compile 'org.apache.commons:commons-math3:3.6.1' - compile 'com.github.axet:android-library:1.8.2' // compile project(':android-library') + compile 'com.github.axet:android-library:1.9.0' // compile project(':android-library') compile 'com.github.axet:jebml:0.0.1' // compile project(':jebml') } diff --git a/app/src/main/java/com/github/axet/audiorecorder/activities/MainActivity.java b/app/src/main/java/com/github/axet/audiorecorder/activities/MainActivity.java index 2b798a6..332941d 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/activities/MainActivity.java +++ b/app/src/main/java/com/github/axet/audiorecorder/activities/MainActivity.java @@ -388,6 +388,8 @@ public class MainActivity extends AppCompatActivity implements AbsListView.OnScr } if (!playing) { + playerStop(); // clear player instance + updatePlayerText(v, f); // update length return; } diff --git a/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java b/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java index 78e83c4..cfbea02 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java +++ b/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java @@ -10,7 +10,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager; -import android.graphics.drawable.ColorDrawable; import android.media.AudioFormat; import android.media.AudioRecord; import android.media.AudioTrack; @@ -44,11 +43,8 @@ import com.github.axet.audiorecorder.app.Sound; import com.github.axet.audiorecorder.app.Storage; import com.github.axet.audiorecorder.encoders.Encoder; import com.github.axet.audiorecorder.encoders.EncoderInfo; +import com.github.axet.audiorecorder.encoders.Factory; import com.github.axet.audiorecorder.encoders.FileEncoder; -import com.github.axet.audiorecorder.encoders.Format3GP; -import com.github.axet.audiorecorder.encoders.FormatM4A; -import com.github.axet.audiorecorder.encoders.FormatMKA; -import com.github.axet.audiorecorder.encoders.FormatWAV; import com.github.axet.audiorecorder.services.RecordingService; import com.github.axet.audiorecorder.widgets.PitchView; @@ -786,18 +782,7 @@ public class RecordingActivity extends AppCompatActivity { final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this); String ext = shared.getString(MainApplication.PREFERENCE_ENCODING, ""); - if (ext.equals("wav")) { - e = new FormatWAV(info, out); - } - if (ext.equals("m4a")) { - e = new FormatM4A(info, out); - } - if (ext.equals("3gp")) { - e = new Format3GP(info, out); - } - if (ext.equals("mka")) { - e = new FormatMKA(info, out); - } + e = Factory.getEncoder(ext, info, out); encoder = new FileEncoder(this, in, e); diff --git a/app/src/main/java/com/github/axet/audiorecorder/activities/SettingsActivity.java b/app/src/main/java/com/github/axet/audiorecorder/activities/SettingsActivity.java index d7961b5..847e1bf 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/activities/SettingsActivity.java +++ b/app/src/main/java/com/github/axet/audiorecorder/activities/SettingsActivity.java @@ -27,6 +27,7 @@ import android.widget.Toast; import com.github.axet.audiorecorder.R; import com.github.axet.audiorecorder.app.MainApplication; +import com.github.axet.audiorecorder.encoders.Factory; import com.github.axet.audiorecorder.encoders.MuxerMP4; import java.lang.reflect.Array; @@ -276,24 +277,15 @@ public class SettingsActivity extends AppCompatPreferenceActivity implements Sha if (Build.VERSION.SDK_INT < 16) { // Android 4.1 getPreferenceScreen().removePreference(enc); } else { - if (Build.VERSION.SDK_INT < 18) { // MediaMuxer - String v = enc.getValue(); - int i = enc.findIndexOfValue("m4a"); - CharSequence[] ee = enc.getEntries(); - CharSequence[] vv = enc.getEntryValues(); - ee = removeElement(CharSequence.class, ee, i); - vv = removeElement(CharSequence.class, vv, i); - enc.setEntries(ee); - enc.setEntryValues(vv); + String v = enc.getValue(); + enc.setEntryValues(Factory.getEncodingValues(getActivity())); + enc.setEntries(Factory.getEncodingTexts(getActivity())); + + int i = enc.findIndexOfValue(v); + if (i == -1) { enc.setValueIndex(0); - i = enc.findIndexOfValue(v); - if (i == -1) { - enc.setValue("wav"); - enc.setValueIndex(0); - } else { - enc.setValueIndex(i); - enc.setValue(v); - } + } else { + enc.setValueIndex(i); } Map mime = MuxerMP4.findEncoder("audio/mp4"); diff --git a/app/src/main/java/com/github/axet/audiorecorder/app/Sound.java b/app/src/main/java/com/github/axet/audiorecorder/app/Sound.java index e1f62d6..e4f25cb 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/app/Sound.java +++ b/app/src/main/java/com/github/axet/audiorecorder/app/Sound.java @@ -7,7 +7,7 @@ import android.media.AudioManager; import android.media.AudioTrack; import android.preference.PreferenceManager; -public class Sound extends com.github.axet.androidlibrary.app.Sound { +public class Sound extends com.github.axet.androidlibrary.sound.Sound { public Sound(Context context) { super(context); diff --git a/app/src/main/java/com/github/axet/audiorecorder/app/Storage.java b/app/src/main/java/com/github/axet/audiorecorder/app/Storage.java index 9c35bac..efefa77 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/app/Storage.java +++ b/app/src/main/java/com/github/axet/audiorecorder/app/Storage.java @@ -4,13 +4,13 @@ import android.Manifest; import android.content.Context; import android.content.SharedPreferences; import android.content.pm.PackageManager; -import android.media.AudioFormat; import android.os.Build; import android.os.StatFs; import android.preference.PreferenceManager; import android.support.v4.content.ContextCompat; import com.github.axet.audiorecorder.R; +import com.github.axet.audiorecorder.encoders.Factory; import java.io.File; import java.io.FileInputStream; @@ -179,7 +179,7 @@ public class Storage { for (File f : ff) { if (f.length() > 0) { - String[] ee = context.getResources().getStringArray(R.array.encodings_values); + String[] ee = Factory.getEncodingValues(context); String n = f.getName().toLowerCase(); for (String e : ee) { if (n.endsWith("." + e)) @@ -197,36 +197,8 @@ public class Storage { int rate = Integer.parseInt(shared.getString(MainApplication.PREFERENCE_RATE, "")); String ext = shared.getString(MainApplication.PREFERENCE_ENCODING, ""); - if (ext.equals("m4a") || ext.equals("mka")) { - long y1 = 365723; // one minute sample 16000Hz - long x1 = 16000; // at 16000 - long y2 = 493743; // one minute sample - long x2 = 44000; // at 44000 - long x = rate; - long y = (x - x1) * (y2 - y1) / (x2 - x1) + y1; - - int m = MainApplication.getChannels(context); - long perSec = (y / 60) * m; - return free / perSec * 1000; - } - - if (ext.equals("mka")) { - long y1 = 365723; // one minute sample 16000Hz - long x1 = 16000; // at 16000 - long y2 = 493743; // one minute sample - long x2 = 44000; // at 44000 - long x = rate; - long y = (x - x1) * (y2 - y1) / (x2 - x1) + y1; - - int m = MainApplication.getChannels(context); - long perSec = (y / 60) * m; - return free / perSec * 1000; - } - - // default raw int m = MainApplication.getChannels(context); - int c = RawSamples.AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 2 : 1; - long perSec = (c * m * rate); + long perSec = Factory.getEncoderRate(ext, rate) * m; return free / perSec * 1000; } diff --git a/app/src/main/java/com/github/axet/audiorecorder/encoders/Factory.java b/app/src/main/java/com/github/axet/audiorecorder/encoders/Factory.java new file mode 100644 index 0000000..86746b8 --- /dev/null +++ b/app/src/main/java/com/github/axet/audiorecorder/encoders/Factory.java @@ -0,0 +1,78 @@ +package com.github.axet.audiorecorder.encoders; + +import android.content.Context; +import android.media.AudioFormat; +import android.os.Build; + +import com.github.axet.audiorecorder.R; +import com.github.axet.audiorecorder.app.RawSamples; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; + +public class Factory { + + public static CharSequence[] getEncodingTexts(Context context) { + String[] aa = context.getResources().getStringArray(R.array.encodings_text); + ArrayList ll = new ArrayList<>(Arrays.asList(aa)); + if (Build.VERSION.SDK_INT >= 18) + ll.add(".m4a"); + ll.add(".mka"); + ll.add(".ogg"); + return ll.toArray(new String[]{}); + } + + public static String[] getEncodingValues(Context context) { + String[] aa = context.getResources().getStringArray(R.array.encodings_values); + ArrayList ll = new ArrayList<>(Arrays.asList(aa)); + if (Build.VERSION.SDK_INT >= 18) + ll.add("m4a"); + ll.add("mka"); + ll.add("ogg"); + return ll.toArray(new String[]{}); + } + + public static Encoder getEncoder(String ext, EncoderInfo info, File out) { + if (ext.equals("wav")) { + return new FormatWAV(info, out); + } + if (ext.equals("3gp")) { + return new Format3GP(info, out); + } + if (ext.equals("m4a")) { + return new FormatM4A(info, out); + } + if (ext.equals("mka")) { + return new FormatMKA(info, out); + } + return null; + } + + public static long getEncoderRate(String ext, int rate) { + if (ext.equals("m4a") || ext.equals("mka")) { + long y1 = 365723; // one minute sample 16000Hz + long x1 = 16000; // at 16000 + long y2 = 493743; // one minute sample + long x2 = 44000; // at 44000 + long x = rate; + long y = (x - x1) * (y2 - y1) / (x2 - x1) + y1; + + return y / 60; + } + + if (ext.equals("mka")) { + long y1 = 365723; // one minute sample 16000Hz + long x1 = 16000; // at 16000 + long y2 = 493743; // one minute sample + long x2 = 44000; // at 44000 + long x = rate; + long y = (x - x1) * (y2 - y1) / (x2 - x1) + y1; + return y / 60; + } + + // default raw + int c = RawSamples.AUDIO_FORMAT == AudioFormat.ENCODING_PCM_16BIT ? 2 : 1; + return c * rate; + } +} diff --git a/app/src/main/java/com/github/axet/audiorecorder/encoders/FormatMKA.java b/app/src/main/java/com/github/axet/audiorecorder/encoders/FormatMKA.java index 565a438..7d4c2c1 100755 --- a/app/src/main/java/com/github/axet/audiorecorder/encoders/FormatMKA.java +++ b/app/src/main/java/com/github/axet/audiorecorder/encoders/FormatMKA.java @@ -90,6 +90,8 @@ public class FormatMKA implements Encoder { return clone; } + public static final int BUFFER_FLAG_KEY_FRAME = 1; // MediaCodec.BUFFER_FLAG_KEY_FRAME + boolean encode() { MediaCodec.BufferInfo outputInfo = new MediaCodec.BufferInfo(); int outputIndex = encoder.dequeueOutputBuffer(outputInfo, 0); @@ -125,7 +127,7 @@ public class FormatMKA implements Encoder { encoder.releaseOutputBuffer(outputIndex, false); } else { MatroskaFileFrame frame = new MatroskaFileFrame(); - frame.setKeyFrame((outputInfo.flags & MediaCodec.BUFFER_FLAG_KEY_FRAME) == MediaCodec.BUFFER_FLAG_KEY_FRAME); + frame.setKeyFrame((outputInfo.flags & BUFFER_FLAG_KEY_FRAME) == BUFFER_FLAG_KEY_FRAME); frame.setTimecode(outputInfo.presentationTimeUs / 1000); frame.setTrackNo(track.getTrackNo()); frame.setData(clone(output)); diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index f5421c6..ca3a019 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -18,8 +18,6 @@ .wav (по умолчанию) - .m4a - .mka diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 54f5883..cd7f48f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -23,14 +23,10 @@ .wav (default) - .m4a - .mka wav - m4a - mka