add error check for mic paused
This commit is contained in:
parent
dd0d92a781
commit
f27a5c3b2e
16 changed files with 69 additions and 33 deletions
|
|
@ -7,7 +7,6 @@ import android.content.SharedPreferences;
|
|||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
|
|
@ -40,7 +39,6 @@ public class MainActivity extends AppCompatThemeActivity {
|
|||
public static final int RESULT_PERMS = 1;
|
||||
|
||||
FloatingActionButton fab;
|
||||
Handler handler = new Handler();
|
||||
|
||||
ListView list;
|
||||
Recordings recordings;
|
||||
|
|
@ -211,7 +209,7 @@ public class MainActivity extends AppCompatThemeActivity {
|
|||
if (selected != -1) {
|
||||
recordings.select(selected);
|
||||
list.smoothScrollToPosition(selected);
|
||||
handler.post(new Runnable() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
list.setSelection(selected);
|
||||
|
|
@ -267,7 +265,7 @@ public class MainActivity extends AppCompatThemeActivity {
|
|||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
handler.post(new Runnable() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
list.smoothScrollToPosition(recordings.getSelected());
|
||||
|
|
|
|||
|
|
@ -100,6 +100,12 @@ public class RecordingActivity extends AppCompatThemeActivity {
|
|||
pitch.add((Double) msg.obj);
|
||||
if (msg.what == AudioApplication.RecordingStorage.UPDATESAMPLES)
|
||||
updateSamples((Long) msg.obj);
|
||||
if (msg.what == AudioApplication.RecordingStorage.PAUSED) {
|
||||
muted = ErrorDialog.Error(RecordingActivity.this, getString(R.string.mic_paused));
|
||||
RecordingActivity.startActivity(RecordingActivity.this);
|
||||
AutoClose run = new AutoClose(muted);
|
||||
run.run();
|
||||
}
|
||||
if (msg.what == AudioApplication.RecordingStorage.MUTED) {
|
||||
if (Build.VERSION.SDK_INT >= 28)
|
||||
muted = new ErrorDialog(RecordingActivity.this, getString(R.string.mic_muted_pie)).setTitle(getString(R.string.mic_muted_error)).show();
|
||||
|
|
@ -109,28 +115,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
|
|||
}
|
||||
if (msg.what == AudioApplication.RecordingStorage.UNMUTED) {
|
||||
if (muted != null) {
|
||||
Runnable run = new Runnable() {
|
||||
int count = 5;
|
||||
AlertDialog d = muted;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (count <= 0) {
|
||||
d.dismiss();
|
||||
return;
|
||||
}
|
||||
Button b = d.getButton(DialogInterface.BUTTON_NEUTRAL);
|
||||
b.setText(getString(R.string.auto_close, count));
|
||||
b.setVisibility(View.VISIBLE);
|
||||
b.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
}
|
||||
});
|
||||
count--;
|
||||
handler.postDelayed(this, 1000);
|
||||
}
|
||||
};
|
||||
AutoClose run = new AutoClose(muted);
|
||||
run.run();
|
||||
muted = null;
|
||||
}
|
||||
|
|
@ -169,6 +154,33 @@ public class RecordingActivity extends AppCompatThemeActivity {
|
|||
context.startActivity(i);
|
||||
}
|
||||
|
||||
public class AutoClose implements Runnable {
|
||||
int count = 5;
|
||||
AlertDialog d;
|
||||
|
||||
public AutoClose(AlertDialog muted) {
|
||||
d = muted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (count <= 0) {
|
||||
d.dismiss();
|
||||
return;
|
||||
}
|
||||
Button b = d.getButton(DialogInterface.BUTTON_NEUTRAL);
|
||||
b.setText(d.getContext().getString(R.string.auto_close, count));
|
||||
b.setVisibility(View.VISIBLE);
|
||||
b.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
}
|
||||
});
|
||||
count--;
|
||||
handler.postDelayed(this, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
class RecordingReceiver extends BluetoothReceiver {
|
||||
@Override
|
||||
public void onConnected() {
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli
|
|||
public static final int ERROR = 4;
|
||||
public static final int MUTED = 5;
|
||||
public static final int UNMUTED = 6;
|
||||
public static final int PAUSED = 7;
|
||||
|
||||
public Context context;
|
||||
public final ArrayList<Handler> handlers = new ArrayList<>();
|
||||
|
|
@ -196,8 +197,11 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli
|
|||
boolean silenceDetected = false;
|
||||
long silence = samplesTime; // last non silence frame
|
||||
|
||||
long start = System.currentTimeMillis(); // recording start time
|
||||
long session = 0; // samples count from start of recording
|
||||
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
long last = System.currentTimeMillis();
|
||||
recorder.startRecording();
|
||||
|
||||
int samplesTimeCount = 0;
|
||||
|
|
@ -216,19 +220,22 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli
|
|||
int readSize = recorder.read(buffer, 0, buffer.length);
|
||||
if (readSize < 0)
|
||||
return;
|
||||
long end = System.currentTimeMillis();
|
||||
long now = System.currentTimeMillis();
|
||||
long diff = (now - last) * sampleRate / 1000;
|
||||
last = now;
|
||||
|
||||
long diff = (end - start) * sampleRate / 1000;
|
||||
|
||||
start = end;
|
||||
|
||||
int samples = readSize / Sound.getChannels(context);
|
||||
int samples = readSize / Sound.getChannels(context); // mono samples (for booth channels)
|
||||
|
||||
if (stableRefresh || diff >= samples) {
|
||||
stableRefresh = true;
|
||||
|
||||
e.encode(buffer, 0, readSize);
|
||||
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
}catch(InterruptedException e) {
|
||||
}
|
||||
|
||||
short[] dbBuf;
|
||||
int dbSize;
|
||||
int readSizeUpdate;
|
||||
|
|
@ -267,6 +274,7 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli
|
|||
Post(UPDATESAMPLES, samplesTime);
|
||||
samplesTimeCount -= samplesTimeUpdate;
|
||||
}
|
||||
session += samples;
|
||||
|
||||
if (samplesTime - silence > 2 * sampleRate) { // 2 second of mic muted
|
||||
if (!silenceDetected) {
|
||||
|
|
@ -279,6 +287,11 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli
|
|||
Post(UNMUTED, null);
|
||||
}
|
||||
}
|
||||
diff = (now - start) * sampleRate / 1000; // number of samples we expect by this moment
|
||||
if (diff - session > 2 * sampleRate) { // 2 second of silence / paused by os
|
||||
Post(PAUSED, null);
|
||||
session = diff; // reset
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final RuntimeException e) {
|
||||
|
|
|
|||
|
|
@ -70,4 +70,5 @@
|
|||
<string name="auto_close">Auto close in (%1$d)</string>
|
||||
<string name="mic_muted_error">Mic muted</string>
|
||||
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
|
||||
<string name="mic_paused">Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -64,4 +64,5 @@
|
|||
<string name="auto_close">Auto close in (%1$d)</string>
|
||||
<string name="mic_muted_error">Mic muted</string>
|
||||
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
|
||||
<string name="mic_paused">Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -70,4 +70,5 @@
|
|||
<string name="auto_close">Auto close in (%1$d)</string>
|
||||
<string name="mic_muted_error">Mic muted</string>
|
||||
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
|
||||
<string name="mic_paused">Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -70,4 +70,5 @@
|
|||
<string name="auto_close">Auto close in (%1$d)</string>
|
||||
<string name="mic_muted_error">Mic muted</string>
|
||||
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
|
||||
<string name="mic_paused">Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -70,4 +70,5 @@
|
|||
<string name="auto_close">Auto close in (%1$d)</string>
|
||||
<string name="mic_muted_error">Mic muted</string>
|
||||
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
|
||||
<string name="mic_paused">Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -70,4 +70,5 @@
|
|||
<string name="auto_close">Auto close in (%1$d)</string>
|
||||
<string name="mic_muted_error">Mic muted</string>
|
||||
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
|
||||
<string name="mic_paused">Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -70,4 +70,5 @@
|
|||
<string name="auto_close">Auto close in (%1$d)</string>
|
||||
<string name="mic_muted_error">Mic muted</string>
|
||||
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
|
||||
<string name="mic_paused">Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -70,4 +70,5 @@
|
|||
<string name="auto_close">Auto close in (%1$d)</string>
|
||||
<string name="mic_muted_error">Mic muted</string>
|
||||
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
|
||||
<string name="mic_paused">Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -70,4 +70,5 @@
|
|||
<string name="auto_close">Auto close in (%1$d)</string>
|
||||
<string name="mic_muted_error">Mic muted</string>
|
||||
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
|
||||
<string name="mic_paused">Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -70,4 +70,5 @@
|
|||
<string name="auto_close">Auto close in (%1$d)</string>
|
||||
<string name="mic_muted_error">Mic muted</string>
|
||||
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
|
||||
<string name="mic_paused">Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -72,4 +72,5 @@
|
|||
<string name="auto_close">Auto close in (%1$d)</string>
|
||||
<string name="mic_muted_error">Mic muted</string>
|
||||
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
|
||||
<string name="mic_paused">Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -70,4 +70,5 @@
|
|||
<string name="auto_close">Auto close in (%1$d)</string>
|
||||
<string name="mic_muted_error">Mic muted</string>
|
||||
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
|
||||
<string name="mic_paused">Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enougth for selected settings</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -70,4 +70,5 @@
|
|||
<string name="auto_close">Auto close in (%1$d)</string>
|
||||
<string name="mic_muted_error">Mic muted</string>
|
||||
<string name="mic_muted_pie">Android Pie and above prevent idle background apps from using microphone. Please disable selinux or install previous android version!</string>
|
||||
<string name="mic_paused">Mic paused by OS, recording time is less then data recorded, check if you device supports background recording or it is fast enough for selected settings</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue