Fix various bugs
This commit is contained in:
parent
e9fccf4ccd
commit
a9c730e26b
5 changed files with 95 additions and 46 deletions
|
@ -1143,6 +1143,10 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAudioManagerModeNormal() {
|
||||||
|
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
public void setAudioManagerInCallMode() {
|
public void setAudioManagerInCallMode() {
|
||||||
if (mAudioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) {
|
if (mAudioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) {
|
||||||
Log.w("[AudioManager] already in MODE_IN_COMMUNICATION, skipping...");
|
Log.w("[AudioManager] already in MODE_IN_COMMUNICATION, skipping...");
|
||||||
|
|
|
@ -20,6 +20,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Handler;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import org.linphone.LinphoneManager;
|
import org.linphone.LinphoneManager;
|
||||||
|
@ -30,8 +32,6 @@ import org.linphone.mediastream.Log;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -40,16 +40,16 @@ public class Recording implements PlayerListener, Comparable<Recording> {
|
||||||
private Date recordDate;
|
private Date recordDate;
|
||||||
private Player player;
|
private Player player;
|
||||||
private RecordingListener listener;
|
private RecordingListener listener;
|
||||||
private Timer timer;
|
private Handler handler;
|
||||||
private TimerTask updateCurrentPositionTimer;
|
private Runnable updateCurrentPositionTimer;
|
||||||
|
|
||||||
private static final Pattern mRecordPattern = Pattern.compile(".*/(.*)_(\\d{2}-\\d{2}-\\d{4}-\\d{2}-\\d{2}-\\d{2})\\..*");
|
public static final Pattern RECORD_PATTERN = Pattern.compile(".*/(.*)_(\\d{2}-\\d{2}-\\d{4}-\\d{2}-\\d{2}-\\d{2})\\..*");
|
||||||
|
|
||||||
@SuppressLint("SimpleDateFormat")
|
@SuppressLint("SimpleDateFormat")
|
||||||
public Recording(String recordPath) {
|
public Recording(Context context, String recordPath) {
|
||||||
this.recordPath = recordPath;
|
this.recordPath = recordPath;
|
||||||
|
|
||||||
Matcher m = mRecordPattern.matcher(recordPath);
|
Matcher m = RECORD_PATTERN.matcher(recordPath);
|
||||||
if (m.matches()) {
|
if (m.matches()) {
|
||||||
name = m.group(1);
|
name = m.group(1);
|
||||||
|
|
||||||
|
@ -60,17 +60,17 @@ public class Recording implements PlayerListener, Comparable<Recording> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
timer = new Timer();
|
handler = new Handler(context.getMainLooper());
|
||||||
updateCurrentPositionTimer = new TimerTask() {
|
updateCurrentPositionTimer = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (listener != null) listener.currentPositionChanged(getCurrentPosition());
|
if (listener != null) listener.currentPositionChanged(getCurrentPosition());
|
||||||
|
if (isPlaying()) handler.postDelayed(updateCurrentPositionTimer, 20);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
player = LinphoneManager.getLc().createLocalPlayer(null, null, null);
|
player = LinphoneManager.getLc().createLocalPlayer(null, null, null);
|
||||||
player.setListener(this);
|
player.setListener(this);
|
||||||
player.open(recordPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRecordPath() {
|
public String getRecordPath() {
|
||||||
|
@ -90,8 +90,12 @@ public class Recording implements PlayerListener, Comparable<Recording> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void play() {
|
public void play() {
|
||||||
|
if (isClosed()) {
|
||||||
|
player.open(recordPath);
|
||||||
|
}
|
||||||
|
|
||||||
player.start();
|
player.start();
|
||||||
//timer.scheduleAtFixedRate(updateCurrentPositionTimer, 0, 1000);
|
handler.post(updateCurrentPositionTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlaying() {
|
public boolean isPlaying() {
|
||||||
|
@ -101,9 +105,6 @@ public class Recording implements PlayerListener, Comparable<Recording> {
|
||||||
public void pause() {
|
public void pause() {
|
||||||
if (!isClosed()) {
|
if (!isClosed()) {
|
||||||
player.pause();
|
player.pause();
|
||||||
|
|
||||||
timer.cancel();
|
|
||||||
timer.purge();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,10 +117,18 @@ public class Recording implements PlayerListener, Comparable<Recording> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCurrentPosition() {
|
public int getCurrentPosition() {
|
||||||
|
if (isClosed()) {
|
||||||
|
player.open(recordPath);
|
||||||
|
}
|
||||||
|
|
||||||
return player.getCurrentPosition();
|
return player.getCurrentPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDuration() {
|
public int getDuration() {
|
||||||
|
if (isClosed()) {
|
||||||
|
player.open(recordPath);
|
||||||
|
}
|
||||||
|
|
||||||
return player.getDuration();
|
return player.getDuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@ import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class RecordingAdapter extends SelectableAdapter<RecordingViewHolder> {
|
public class RecordingAdapter extends SelectableAdapter<RecordingViewHolder> {
|
||||||
|
@ -112,12 +111,11 @@ public class RecordingAdapter extends SelectableAdapter<RecordingViewHolder> {
|
||||||
viewHolder.name.setText(record.getName());
|
viewHolder.name.setText(record.getName());
|
||||||
viewHolder.date.setText(new SimpleDateFormat("HH:mm").format(record.getRecordDate()));
|
viewHolder.date.setText(new SimpleDateFormat("HH:mm").format(record.getRecordDate()));
|
||||||
|
|
||||||
// int position = record.getCurrentPosition();
|
int position = record.getCurrentPosition();
|
||||||
// viewHolder.currentPosition.setText(String.format("%02d:%02d",
|
viewHolder.currentPosition.setText(String.format("%02d:%02d",
|
||||||
// TimeUnit.MILLISECONDS.toMinutes(position),
|
TimeUnit.MILLISECONDS.toMinutes(position),
|
||||||
// TimeUnit.MILLISECONDS.toSeconds(position) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(position))
|
TimeUnit.MILLISECONDS.toSeconds(position) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(position))
|
||||||
// ));
|
));
|
||||||
viewHolder.currentPosition.setText("00:00");
|
|
||||||
|
|
||||||
int duration = record.getDuration();
|
int duration = record.getDuration();
|
||||||
viewHolder.duration.setText(String.format("%02d:%02d",
|
viewHolder.duration.setText(String.format("%02d:%02d",
|
||||||
|
@ -125,27 +123,26 @@ public class RecordingAdapter extends SelectableAdapter<RecordingViewHolder> {
|
||||||
TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))
|
TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))
|
||||||
));
|
));
|
||||||
|
|
||||||
viewHolder.progressionBar.setMax(100);
|
viewHolder.progressionBar.setMax(record.getDuration());
|
||||||
viewHolder.progressionBar.setProgress(0);
|
viewHolder.progressionBar.setProgress(0);
|
||||||
viewHolder.progressionBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
viewHolder.progressionBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
if (fromUser) {
|
if (fromUser) {
|
||||||
if (progress == 0) {
|
int progressToSet = progress > 0 && progress < seekBar.getMax() ? progress : 0;
|
||||||
record.seek(0);
|
|
||||||
} else if (progress == seekBar.getMax()) {
|
|
||||||
if (record.isPlaying()) record.pause();
|
|
||||||
record.seek(0);
|
|
||||||
seekBar.setProgress(0);
|
|
||||||
} else {
|
|
||||||
record.seek(progress);
|
|
||||||
|
|
||||||
int currentPosition = record.getCurrentPosition();
|
if (progress == seekBar.getMax()) {
|
||||||
viewHolder.currentPosition.setText(String.format("%02d:%02d",
|
if (record.isPlaying()) record.pause();
|
||||||
TimeUnit.MILLISECONDS.toMinutes(currentPosition),
|
|
||||||
TimeUnit.MILLISECONDS.toSeconds(currentPosition) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(currentPosition))
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
record.seek(progressToSet);
|
||||||
|
seekBar.setProgress(progressToSet);
|
||||||
|
|
||||||
|
int currentPosition = record.getCurrentPosition();
|
||||||
|
viewHolder.currentPosition.setText(String.format("%02d:%02d",
|
||||||
|
TimeUnit.MILLISECONDS.toMinutes(currentPosition),
|
||||||
|
TimeUnit.MILLISECONDS.toSeconds(currentPosition) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(currentPosition))
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,9 +160,10 @@ public class RecordingAdapter extends SelectableAdapter<RecordingViewHolder> {
|
||||||
record.setRecordingListener(new RecordingListener() {
|
record.setRecordingListener(new RecordingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void currentPositionChanged(int currentPosition) {
|
public void currentPositionChanged(int currentPosition) {
|
||||||
viewHolder.currentPosition.setText(String.format("%02d:%02",
|
viewHolder.currentPosition.setText(String.format("%02d:%02d",
|
||||||
currentPosition % 60,
|
TimeUnit.MILLISECONDS.toMinutes(currentPosition),
|
||||||
currentPosition - (currentPosition % 60) * 60, Locale.getDefault()));
|
TimeUnit.MILLISECONDS.toSeconds(currentPosition) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(currentPosition))
|
||||||
|
));
|
||||||
viewHolder.progressionBar.setProgress(currentPosition);
|
viewHolder.progressionBar.setProgress(currentPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,6 +172,8 @@ public class RecordingAdapter extends SelectableAdapter<RecordingViewHolder> {
|
||||||
record.pause();
|
record.pause();
|
||||||
record.seek(0);
|
record.seek(0);
|
||||||
viewHolder.progressionBar.setProgress(0);
|
viewHolder.progressionBar.setProgress(0);
|
||||||
|
viewHolder.currentPosition.setText("00:00");
|
||||||
|
viewHolder.playButton.setImageResource(R.drawable.record_play);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,10 @@ import android.widget.AdapterView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.linphone.LinphoneActivity;
|
import org.linphone.LinphoneActivity;
|
||||||
|
import org.linphone.LinphoneManager;
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
import org.linphone.fragments.FragmentsAvailable;
|
import org.linphone.fragments.FragmentsAvailable;
|
||||||
|
import org.linphone.mediastream.Log;
|
||||||
import org.linphone.utils.FileUtils;
|
import org.linphone.utils.FileUtils;
|
||||||
import org.linphone.utils.SelectableHelper;
|
import org.linphone.utils.SelectableHelper;
|
||||||
|
|
||||||
|
@ -86,6 +88,29 @@ public class RecordingListFragment extends Fragment implements View.OnClickListe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeDeletedRecordings() {
|
||||||
|
String recordingsDirectory = FileUtils.getRecordingsDirectory(context);
|
||||||
|
File directory = new File(recordingsDirectory);
|
||||||
|
|
||||||
|
if (directory.exists() && directory.isDirectory()) {
|
||||||
|
File[] existingRecordings = directory.listFiles();
|
||||||
|
|
||||||
|
for(Recording r : recordings) {
|
||||||
|
boolean exists = false;
|
||||||
|
for(File f : existingRecordings) {
|
||||||
|
if (f.getPath().equals(r.getRecordPath())) {
|
||||||
|
exists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!exists) recordings.remove(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(recordings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void searchForRecordings() {
|
public void searchForRecordings() {
|
||||||
String recordingsDirectory = FileUtils.getRecordingsDirectory(context);
|
String recordingsDirectory = FileUtils.getRecordingsDirectory(context);
|
||||||
File directory = new File(recordingsDirectory);
|
File directory = new File(recordingsDirectory);
|
||||||
|
@ -93,7 +118,7 @@ public class RecordingListFragment extends Fragment implements View.OnClickListe
|
||||||
if (directory.exists() && directory.isDirectory()) {
|
if (directory.exists() && directory.isDirectory()) {
|
||||||
File[] existingRecordings = directory.listFiles();
|
File[] existingRecordings = directory.listFiles();
|
||||||
|
|
||||||
for (File f : existingRecordings) {
|
for(File f : existingRecordings) {
|
||||||
boolean exists = false;
|
boolean exists = false;
|
||||||
for(Recording r : recordings) {
|
for(Recording r : recordings) {
|
||||||
if (r.getRecordPath().equals(f.getPath())) {
|
if (r.getRecordPath().equals(f.getPath())) {
|
||||||
|
@ -102,7 +127,11 @@ public class RecordingListFragment extends Fragment implements View.OnClickListe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!exists) recordings.add(new Recording(f.getPath()));
|
if (!exists) {
|
||||||
|
if (Recording.RECORD_PATTERN.matcher(f.getPath()).matches()) {
|
||||||
|
recordings.add(new Recording(context, f.getPath()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(recordings);
|
Collections.sort(recordings);
|
||||||
|
@ -113,10 +142,14 @@ public class RecordingListFragment extends Fragment implements View.OnClickListe
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
|
LinphoneManager.getInstance().setAudioManagerModeNormal();
|
||||||
|
LinphoneManager.getInstance().routeAudioToSpeaker();
|
||||||
|
|
||||||
if (LinphoneActivity.isInstanciated()) {
|
if (LinphoneActivity.isInstanciated()) {
|
||||||
LinphoneActivity.instance().selectMenu(FragmentsAvailable.RECORDING_LIST);
|
LinphoneActivity.instance().selectMenu(FragmentsAvailable.RECORDING_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeDeletedRecordings();
|
||||||
searchForRecordings();
|
searchForRecordings();
|
||||||
|
|
||||||
hideRecordingListAndDisplayMessageIfEmpty();
|
hideRecordingListAndDisplayMessageIfEmpty();
|
||||||
|
@ -130,6 +163,8 @@ public class RecordingListFragment extends Fragment implements View.OnClickListe
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
|
LinphoneManager.getInstance().routeAudioToReceiver();
|
||||||
|
|
||||||
// Close all opened recordings
|
// Close all opened recordings
|
||||||
for (Recording r : recordings) {
|
for (Recording r : recordings) {
|
||||||
if (!r.isClosed()) {
|
if (!r.isClosed()) {
|
||||||
|
@ -148,13 +183,14 @@ public class RecordingListFragment extends Fragment implements View.OnClickListe
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
if (recordingAdapter.isEditionEnabled()) {
|
if (recordingAdapter.isEditionEnabled()) {
|
||||||
Recording record = recordings.get(position);
|
Recording record = recordings.get(position);
|
||||||
recordings.remove(position);
|
|
||||||
|
|
||||||
if (record.isPlaying()) record.pause();
|
if (record.isPlaying()) record.pause();
|
||||||
record.close();
|
record.close();
|
||||||
|
|
||||||
File recordingFile = new File(record.getRecordPath());
|
File recordingFile = new File(record.getRecordPath());
|
||||||
recordingFile.delete();
|
if (recordingFile.delete()) {
|
||||||
|
recordings.remove(record);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,13 +215,14 @@ public class RecordingListFragment extends Fragment implements View.OnClickListe
|
||||||
int size = recordingAdapter.getSelectedItemCount();
|
int size = recordingAdapter.getSelectedItemCount();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
Recording record = (Recording) objectsToDelete[i];
|
Recording record = (Recording) objectsToDelete[i];
|
||||||
recordings.remove(record);
|
|
||||||
|
|
||||||
if (record.isPlaying()) record.pause();
|
if (record.isPlaying()) record.pause();
|
||||||
record.close();
|
record.close();
|
||||||
|
|
||||||
File recordingFile = new File(record.getRecordPath());
|
File recordingFile = new File(record.getRecordPath());
|
||||||
recordingFile.delete();
|
if (recordingFile.delete()) {
|
||||||
|
recordings.remove(record);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,8 +131,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"/>
|
||||||
android:paddingEnd="0dp"/>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue