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;
|
||||
}
|
||||
|
||||
public void setAudioManagerModeNormal() {
|
||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||
}
|
||||
|
||||
public void setAudioManagerInCallMode() {
|
||||
if (mAudioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION) {
|
||||
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.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.linphone.LinphoneManager;
|
||||
|
@ -30,8 +32,6 @@ import org.linphone.mediastream.Log;
|
|||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -40,16 +40,16 @@ public class Recording implements PlayerListener, Comparable<Recording> {
|
|||
private Date recordDate;
|
||||
private Player player;
|
||||
private RecordingListener listener;
|
||||
private Timer timer;
|
||||
private TimerTask updateCurrentPositionTimer;
|
||||
private Handler handler;
|
||||
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")
|
||||
public Recording(String recordPath) {
|
||||
public Recording(Context context, String recordPath) {
|
||||
this.recordPath = recordPath;
|
||||
|
||||
Matcher m = mRecordPattern.matcher(recordPath);
|
||||
Matcher m = RECORD_PATTERN.matcher(recordPath);
|
||||
if (m.matches()) {
|
||||
name = m.group(1);
|
||||
|
||||
|
@ -60,17 +60,17 @@ public class Recording implements PlayerListener, Comparable<Recording> {
|
|||
}
|
||||
}
|
||||
|
||||
timer = new Timer();
|
||||
updateCurrentPositionTimer = new TimerTask() {
|
||||
handler = new Handler(context.getMainLooper());
|
||||
updateCurrentPositionTimer = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (listener != null) listener.currentPositionChanged(getCurrentPosition());
|
||||
if (isPlaying()) handler.postDelayed(updateCurrentPositionTimer, 20);
|
||||
}
|
||||
};
|
||||
|
||||
player = LinphoneManager.getLc().createLocalPlayer(null, null, null);
|
||||
player.setListener(this);
|
||||
player.open(recordPath);
|
||||
}
|
||||
|
||||
public String getRecordPath() {
|
||||
|
@ -90,8 +90,12 @@ public class Recording implements PlayerListener, Comparable<Recording> {
|
|||
}
|
||||
|
||||
public void play() {
|
||||
if (isClosed()) {
|
||||
player.open(recordPath);
|
||||
}
|
||||
|
||||
player.start();
|
||||
//timer.scheduleAtFixedRate(updateCurrentPositionTimer, 0, 1000);
|
||||
handler.post(updateCurrentPositionTimer);
|
||||
}
|
||||
|
||||
public boolean isPlaying() {
|
||||
|
@ -101,9 +105,6 @@ public class Recording implements PlayerListener, Comparable<Recording> {
|
|||
public void pause() {
|
||||
if (!isClosed()) {
|
||||
player.pause();
|
||||
|
||||
timer.cancel();
|
||||
timer.purge();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,10 +117,18 @@ public class Recording implements PlayerListener, Comparable<Recording> {
|
|||
}
|
||||
|
||||
public int getCurrentPosition() {
|
||||
if (isClosed()) {
|
||||
player.open(recordPath);
|
||||
}
|
||||
|
||||
return player.getCurrentPosition();
|
||||
}
|
||||
|
||||
public int getDuration() {
|
||||
if (isClosed()) {
|
||||
player.open(recordPath);
|
||||
}
|
||||
|
||||
return player.getDuration();
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class RecordingAdapter extends SelectableAdapter<RecordingViewHolder> {
|
||||
|
@ -112,12 +111,11 @@ public class RecordingAdapter extends SelectableAdapter<RecordingViewHolder> {
|
|||
viewHolder.name.setText(record.getName());
|
||||
viewHolder.date.setText(new SimpleDateFormat("HH:mm").format(record.getRecordDate()));
|
||||
|
||||
// int position = record.getCurrentPosition();
|
||||
// viewHolder.currentPosition.setText(String.format("%02d:%02d",
|
||||
// TimeUnit.MILLISECONDS.toMinutes(position),
|
||||
// TimeUnit.MILLISECONDS.toSeconds(position) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(position))
|
||||
// ));
|
||||
viewHolder.currentPosition.setText("00:00");
|
||||
int position = record.getCurrentPosition();
|
||||
viewHolder.currentPosition.setText(String.format("%02d:%02d",
|
||||
TimeUnit.MILLISECONDS.toMinutes(position),
|
||||
TimeUnit.MILLISECONDS.toSeconds(position) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(position))
|
||||
));
|
||||
|
||||
int duration = record.getDuration();
|
||||
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))
|
||||
));
|
||||
|
||||
viewHolder.progressionBar.setMax(100);
|
||||
viewHolder.progressionBar.setMax(record.getDuration());
|
||||
viewHolder.progressionBar.setProgress(0);
|
||||
viewHolder.progressionBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (fromUser) {
|
||||
if (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 progressToSet = progress > 0 && progress < seekBar.getMax() ? progress : 0;
|
||||
|
||||
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))
|
||||
));
|
||||
if (progress == seekBar.getMax()) {
|
||||
if (record.isPlaying()) record.pause();
|
||||
}
|
||||
|
||||
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() {
|
||||
@Override
|
||||
public void currentPositionChanged(int currentPosition) {
|
||||
viewHolder.currentPosition.setText(String.format("%02d:%02",
|
||||
currentPosition % 60,
|
||||
currentPosition - (currentPosition % 60) * 60, Locale.getDefault()));
|
||||
viewHolder.currentPosition.setText(String.format("%02d:%02d",
|
||||
TimeUnit.MILLISECONDS.toMinutes(currentPosition),
|
||||
TimeUnit.MILLISECONDS.toSeconds(currentPosition) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(currentPosition))
|
||||
));
|
||||
viewHolder.progressionBar.setProgress(currentPosition);
|
||||
}
|
||||
|
||||
|
@ -174,6 +172,8 @@ public class RecordingAdapter extends SelectableAdapter<RecordingViewHolder> {
|
|||
record.pause();
|
||||
record.seek(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 org.linphone.LinphoneActivity;
|
||||
import org.linphone.LinphoneManager;
|
||||
import org.linphone.R;
|
||||
import org.linphone.fragments.FragmentsAvailable;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.utils.FileUtils;
|
||||
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() {
|
||||
String recordingsDirectory = FileUtils.getRecordingsDirectory(context);
|
||||
File directory = new File(recordingsDirectory);
|
||||
|
@ -93,7 +118,7 @@ public class RecordingListFragment extends Fragment implements View.OnClickListe
|
|||
if (directory.exists() && directory.isDirectory()) {
|
||||
File[] existingRecordings = directory.listFiles();
|
||||
|
||||
for (File f : existingRecordings) {
|
||||
for(File f : existingRecordings) {
|
||||
boolean exists = false;
|
||||
for(Recording r : recordings) {
|
||||
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);
|
||||
|
@ -113,10 +142,14 @@ public class RecordingListFragment extends Fragment implements View.OnClickListe
|
|||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
LinphoneManager.getInstance().setAudioManagerModeNormal();
|
||||
LinphoneManager.getInstance().routeAudioToSpeaker();
|
||||
|
||||
if (LinphoneActivity.isInstanciated()) {
|
||||
LinphoneActivity.instance().selectMenu(FragmentsAvailable.RECORDING_LIST);
|
||||
}
|
||||
|
||||
removeDeletedRecordings();
|
||||
searchForRecordings();
|
||||
|
||||
hideRecordingListAndDisplayMessageIfEmpty();
|
||||
|
@ -130,6 +163,8 @@ public class RecordingListFragment extends Fragment implements View.OnClickListe
|
|||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
LinphoneManager.getInstance().routeAudioToReceiver();
|
||||
|
||||
// Close all opened recordings
|
||||
for (Recording r : recordings) {
|
||||
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) {
|
||||
if (recordingAdapter.isEditionEnabled()) {
|
||||
Recording record = recordings.get(position);
|
||||
recordings.remove(position);
|
||||
|
||||
if (record.isPlaying()) record.pause();
|
||||
record.close();
|
||||
|
||||
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();
|
||||
for (int i = 0; i < size; i++) {
|
||||
Recording record = (Recording) objectsToDelete[i];
|
||||
recordings.remove(record);
|
||||
|
||||
if (record.isPlaying()) record.pause();
|
||||
record.close();
|
||||
|
||||
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_alignParentBottom="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:paddingEnd="0dp"/>
|
||||
android:layout_alignParentEnd="true"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
|
Loading…
Reference in a new issue