Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions app/src/main/java/com/danielkim/soundrecorder/RecordingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,19 @@ public void setFileNameAndPath(){
}

public void stopRecording() {
mRecorder.stop();
mElapsedMillis = (System.currentTimeMillis() - mStartingTimeMillis);
mRecorder.release();
Toast.makeText(this, getString(R.string.toast_recording_finish) + " " + mFilePath, Toast.LENGTH_LONG).show();
try {
mRecorder.stop();
mRecorder.release();

mElapsedMillis = (System.currentTimeMillis() - mStartingTimeMillis);
Toast.makeText(this, getString(R.string.toast_recording_finish) + " " + mFilePath, Toast.LENGTH_LONG).show();

mDatabase.addRecording(mFileName, mFilePath, mElapsedMillis);

} catch (Exception e) {
mRecorder.release();
Log.e(LOG_TAG, "exception", e);
}

//remove notification
if (mIncrementTimerTask != null) {
Expand All @@ -133,13 +142,6 @@ public void stopRecording() {
}

mRecorder = null;

try {
mDatabase.addRecording(mFileName, mFilePath, mElapsedMillis);

} catch (Exception e){
Log.e(LOG_TAG, "exception", e);
}
}

private void startTimer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ public void onBindViewHolder(final RecordingsViewHolder holder, int position) {
long minutes = TimeUnit.MILLISECONDS.toMinutes(itemDuration);
long seconds = TimeUnit.MILLISECONDS.toSeconds(itemDuration)
- TimeUnit.MINUTES.toSeconds(minutes);
long milliseconds = itemDuration - TimeUnit.MINUTES.toMillis(minutes)
- TimeUnit.SECONDS.toMillis(seconds);

holder.vName.setText(item.getName());
holder.vLength.setText(String.format("%02d:%02d", minutes, seconds));
holder.vLength.setText(String.format("%02d:%02d:%03d", minutes, seconds, milliseconds));
holder.vDateAdded.setText(
DateUtils.formatDateTime(
mContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class PlaybackFragment extends DialogFragment{
//stores minutes and seconds of the length of the file.
long minutes = 0;
long seconds = 0;
long milliseconds = 0;

public PlaybackFragment newInstance(RecordingItem item) {
PlaybackFragment f = new PlaybackFragment();
Expand All @@ -68,6 +69,8 @@ public void onCreate(Bundle savedInstanceState) {
minutes = TimeUnit.MILLISECONDS.toMinutes(itemDuration);
seconds = TimeUnit.MILLISECONDS.toSeconds(itemDuration)
- TimeUnit.MINUTES.toSeconds(minutes);
milliseconds = itemDuration - TimeUnit.MINUTES.toMillis(minutes)
- TimeUnit.SECONDS.toMillis(seconds);
}

@Override
Expand Down Expand Up @@ -104,7 +107,10 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
long minutes = TimeUnit.MILLISECONDS.toMinutes(mMediaPlayer.getCurrentPosition());
long seconds = TimeUnit.MILLISECONDS.toSeconds(mMediaPlayer.getCurrentPosition())
- TimeUnit.MINUTES.toSeconds(minutes);
mCurrentProgressTextView.setText(String.format("%02d:%02d", minutes,seconds));
long milliseconds = mMediaPlayer.getCurrentPosition() - TimeUnit.MINUTES.toMillis(minutes)
- TimeUnit.SECONDS.toMillis(seconds);

mCurrentProgressTextView.setText(String.format("%02d:%02d:%02d", minutes, seconds, milliseconds/10));

updateSeekBar();

Expand All @@ -131,7 +137,10 @@ public void onStopTrackingTouch(SeekBar seekBar) {
long minutes = TimeUnit.MILLISECONDS.toMinutes(mMediaPlayer.getCurrentPosition());
long seconds = TimeUnit.MILLISECONDS.toSeconds(mMediaPlayer.getCurrentPosition())
- TimeUnit.MINUTES.toSeconds(minutes);
mCurrentProgressTextView.setText(String.format("%02d:%02d", minutes,seconds));
long milliseconds = mMediaPlayer.getCurrentPosition() - TimeUnit.MINUTES.toMillis(minutes)
- TimeUnit.SECONDS.toMillis(seconds);

mCurrentProgressTextView.setText(String.format("%02d:%02d:%02d", minutes, seconds, milliseconds/10));
updateSeekBar();
}
}
Expand All @@ -147,7 +156,7 @@ public void onClick(View v) {
});

mFileNameTextView.setText(item.getName());
mFileLengthTextView.setText(String.format("%02d:%02d", minutes,seconds));
mFileLengthTextView.setText(String.format("%02d:%02d:%02d", minutes, seconds, milliseconds/10));

builder.setView(view);

Expand Down Expand Up @@ -307,14 +316,17 @@ public void run() {
long minutes = TimeUnit.MILLISECONDS.toMinutes(mCurrentPosition);
long seconds = TimeUnit.MILLISECONDS.toSeconds(mCurrentPosition)
- TimeUnit.MINUTES.toSeconds(minutes);
mCurrentProgressTextView.setText(String.format("%02d:%02d", minutes, seconds));
long milliseconds = mCurrentPosition - TimeUnit.MINUTES.toMillis(minutes)
- TimeUnit.SECONDS.toMillis(seconds);

mCurrentProgressTextView.setText(String.format("%02d:%02d:%02d", minutes, seconds, milliseconds/10));

updateSeekBar();
}
}
};

private void updateSeekBar() {
mHandler.postDelayed(mRunnable, 1000);
mHandler.postDelayed(mRunnable, 50);
}
}