better encoding

This commit is contained in:
Alexey Kuznetsov 2017-02-26 11:56:16 +03:00
commit a70ecb9e9b
3 changed files with 27 additions and 9 deletions

View file

@ -45,5 +45,5 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.github.axet:android-audio-library:0.0.2' // compile project(':android-audio-library')
compile 'com.github.axet:android-audio-library:0.0.3' // compile project(':android-audio-library')
}

View file

@ -36,8 +36,6 @@ import android.widget.Toast;
import com.github.axet.androidlibrary.animations.MarginBottomAnimation;
import com.github.axet.androidlibrary.app.MainLibrary;
import com.github.axet.audiorecorder.R;
import com.github.axet.audiorecorder.app.MainApplication;
import com.github.axet.audiolibrary.app.RawSamples;
import com.github.axet.audiolibrary.app.Sound;
import com.github.axet.audiolibrary.app.Storage;
@ -45,8 +43,10 @@ import com.github.axet.audiolibrary.encoders.Encoder;
import com.github.axet.audiolibrary.encoders.EncoderInfo;
import com.github.axet.audiolibrary.encoders.Factory;
import com.github.axet.audiolibrary.encoders.FileEncoder;
import com.github.axet.audiorecorder.services.RecordingService;
import com.github.axet.audiolibrary.widgets.PitchView;
import com.github.axet.audiorecorder.R;
import com.github.axet.audiorecorder.app.MainApplication;
import com.github.axet.audiorecorder.services.RecordingService;
import java.io.File;
@ -323,7 +323,7 @@ public class RecordingActivity extends AppCompatActivity {
boolean recording = thread != null;
RecordingService.startService(this, targetFile.getName(), recording);
RecordingService.startService(this, targetFile.getName(), recording, encoder != null);
if (recording) {
pitch.record();
@ -348,7 +348,7 @@ public class RecordingActivity extends AppCompatActivity {
stopRecording();
RecordingService.startService(this, targetFile.getName(), thread != null);
RecordingService.startService(this, targetFile.getName(), thread != null, encoder != null);
pitch.setOnTouchListener(new View.OnTouchListener() {
@Override
@ -553,6 +553,11 @@ public class RecordingActivity extends AppCompatActivity {
tm.listen(pscl, PhoneStateListener.LISTEN_NONE);
pscl = null;
}
if (encoder != null) {
encoder.close();
encoder = null;
}
}
void startRecording() {
@ -686,7 +691,7 @@ public class RecordingActivity extends AppCompatActivity {
}, "RecordingThread");
thread.start();
RecordingService.startService(this, targetFile.getName(), thread != null);
RecordingService.startService(this, targetFile.getName(), thread != null, encoder != null);
}
// calcuale buffer length dynamically, this way we can reduce thread cycles when activity in background
@ -790,6 +795,8 @@ public class RecordingActivity extends AppCompatActivity {
encoder = new FileEncoder(this, in, e);
RecordingService.startService(this, targetFile.getName(), thread != null, encoder != null);
final ProgressDialog d = new ProgressDialog(this);
d.setTitle(getString(R.string.encoding_title));
d.setMessage(".../" + targetFile.getName());

View file

@ -12,6 +12,7 @@ import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.view.View;
import android.widget.RemoteViews;
import com.github.axet.audiorecorder.R;
@ -38,6 +39,7 @@ public class RecordingService extends Service {
String targetFile;
boolean recording;
boolean encoding;
public class RecordingReceiver extends BroadcastReceiver {
@Override
@ -51,10 +53,12 @@ public class RecordingService extends Service {
}
}
public static void startService(Context context, String targetFile, boolean recording) {
public static void startService(Context context, String targetFile, boolean recording, boolean encoding) {
context.startService(new Intent(context, RecordingService.class)
.putExtra("targetFile", targetFile)
.putExtra("recording", recording));
.putExtra("recording", recording)
.putExtra("encoding", encoding)
);
}
public static void stopService(Context context) {
@ -85,6 +89,7 @@ public class RecordingService extends Service {
if (a == null) {
targetFile = intent.getStringExtra("targetFile");
recording = intent.getBooleanExtra("recording", false);
encoding = intent.getBooleanExtra("encoding", false);
showNotificationAlarm(true);
} else if (a.equals(PAUSE_BUTTON)) {
Intent i = new Intent(RecordingActivity.PAUSE_BUTTON);
@ -141,7 +146,13 @@ public class RecordingService extends Service {
String title = getString(R.string.recording_title);
String text = ".../" + targetFile;
if (encoding) {
view.setViewVisibility(R.id.notification_pause, View.GONE);
title = getString(R.string.encoding_title);
}
view.setOnClickPendingIntent(R.id.status_bar_latest_event_content, main);
view.setTextViewText(R.id.notification_title, title);
view.setTextViewText(R.id.notification_text, text);
view.setOnClickPendingIntent(R.id.notification_pause, pe);
view.setImageViewResource(R.id.notification_pause, !recording ? R.drawable.ic_play_arrow_black_24dp : R.drawable.ic_pause_black_24dp);