integrate alternative codec for voice recorder via attachment settings

This commit is contained in:
Christian Schneppe 2020-02-09 21:39:57 +01:00
parent b10b73caad
commit db952297c5
No known key found for this signature in database
GPG key ID: F30B8D686B44D87E
6 changed files with 27 additions and 4 deletions

View file

@ -1009,6 +1009,10 @@ public class XmppConnectionService extends Service {
return getBooleanPreference(SettingsActivity.AWAY_WHEN_SCREEN_IS_OFF, R.bool.away_when_screen_off);
}
public boolean alternativeVoiceSettings() {
return getBooleanPreference("alternative_voice_settings", R.bool.alternative_voice_settings);
}
public int getCompressImageResolutionPreference() {
switch (getPreferences().getString("image_compression", getResources().getString(R.string.image_compression))) {
case "low":

View file

@ -1799,6 +1799,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
break;
case ATTACHMENT_CHOICE_RECORD_VOICE:
intent = new Intent(getActivity(), RecordingActivity.class);
intent.putExtra("ALTERNATIVE_CODEC", activity.xmppConnectionService.alternativeVoiceSettings());
break;
case ATTACHMENT_CHOICE_LOCATION:
intent = new Intent(getActivity(), ShareLocationActivity.class);

View file

@ -12,6 +12,7 @@ import android.os.Handler;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
@ -39,6 +40,7 @@ public class RecordingActivity extends AppCompatActivity implements View.OnClick
private MediaRecorder mRecorder;
private long mStartTime = 0;
private boolean alternativeCodec = false;
private CountDownLatch outputFileWrittenLatch = new CountDownLatch(1);
@ -59,6 +61,7 @@ public class RecordingActivity extends AppCompatActivity implements View.OnClick
protected void onCreate(Bundle savedInstanceState) {
setTheme(ThemeHelper.findDialog(this));
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_recording);
this.setTitle(R.string.attach_record_voice);
this.binding.cancelButton.setOnClickListener(this);
@ -70,6 +73,8 @@ public class RecordingActivity extends AppCompatActivity implements View.OnClick
@Override
protected void onStart() {
super.onStart();
Intent intent = getIntent();
alternativeCodec = intent != null && intent.getBooleanExtra("ALTERNATIVE_CODEC", getResources().getBoolean(R.bool.alternative_voice_settings));
if (!startRecording()) {
this.binding.shareButton.setEnabled(false);
this.binding.timer.setTextAppearance(this, R.style.TextAppearance_Conversations_Title);
@ -92,10 +97,15 @@ public class RecordingActivity extends AppCompatActivity implements View.OnClick
private boolean startRecording() {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mRecorder.setAudioEncodingBitRate(96000);
mRecorder.setAudioSamplingRate(22050);
if (alternativeCodec) {
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
} else {
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mRecorder.setAudioEncodingBitRate(96000);
mRecorder.setAudioSamplingRate(22050);
}
setupOutputFile();
mRecorder.setOutputFile(mOutputFile.getAbsolutePath());

View file

@ -72,6 +72,7 @@
<string name="default_font_size">small</string>
<string name="default_channel_discovery">JABBER_NETWORK</string>
<bool name="use_unicolored_chatbg">false</bool>
<bool name="alternative_voice_settings">false</bool>
<string-array name="domains">
<item>pix-art.de</item>

View file

@ -998,4 +998,6 @@
<string name="your_server_invitation">Your server invitation</string>
<string name="pref_use_unicolored_chatbg_summary">Use unicolored background in chats.</string>
<string name="pref_use_unicolored_chatbg">Use unicolored background</string>
<string name="pref_alternative_voice_settings_summary">If you have problems during voice recording, use this setting to change the codec.</string>
<string name="pref_alternative_voice_settings">Alternative voice recording method</string>
</resources>

View file

@ -251,6 +251,11 @@
android:key="video_compression"
android:summary="@string/pref_video_quality_summary"
android:title="@string/pref_video_quality" />
<CheckBoxPreference
android:defaultValue="@bool/alternative_voice_settings"
android:key="alternative_voice_settings"
android:summary="@string/pref_alternative_voice_settings_summary"
android:title="@string/pref_alternative_voice_settings" />
</PreferenceScreen>
<!--status-->
<PreferenceScreen