Play recorded audio with chronometer counter
I'm creating a recorder app with chronometer counter, the chronometer is working fine with start record, stop record and stop play.
My problem is only with start play, when pressing start play button, the chronometer start from 0 but I couldn't stop the chronometer when the audio file stops.
This is the start play code, please help. Any help I greatly appreciated
playAudio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) throws IllegalArgumentException,
SecurityException, IllegalStateException {
stopRecord.setEnabled(false);
startRecord.setEnabled(false);
stopAudio.setEnabled(true);
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(AudioSavePathInDevice);
mediaPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
if (!running) {
myChronometer.setBase(SystemClock.elapsedRealtime() - pauseOffset);
myChronometer.start();
running = true;
// myChronometer.stop();
}
mediaPlayer.start();
Toast.makeText(MainActivity.this, "Recording Playing",
Toast.LENGTH_LONG).show();
}
});
Sir, this the code of stop audio
stopAudio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (running) {
myChronometer.stop();
myChronometer.setBase(SystemClock.elapsedRealtime());
pauseOffset = 0;
pauseOffset = SystemClock.elapsedRealtime() - myChronometer.getBase();
running = false;
}
stopRecord.setEnabled(false);
startRecord.setEnabled(true);
stopAudio.setEnabled(false);
playAudio.setEnabled(true);
if(mediaPlayer != null){
mediaPlayer.stop();
mediaPlayer.release();
// MediaRecorderReady();
//resetmymyChronometer
myChronometer.setBase(SystemClock.elapsedRealtime());
pauseOffset = 0;
}
}
});
this is the code of stop record
stopRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (running) {
myChronometer.stop();
myChronometer.setBase(SystemClock.elapsedRealtime());
pauseOffset = 0;
pauseOffset = SystemClock.elapsedRealtime() - myChronometer.getBase();
running = false;
}
mediaRecorder.stop();
stopRecord.setEnabled(false);
playAudio.setEnabled(true);
startRecord.setEnabled(true);
stopAudio.setEnabled(false);
Toast.makeText(MainActivity.this, "Recording Completed",
Toast.LENGTH_LONG).show();
}
});
MediaRecorderReady method
public void MediaRecorderReady(){
//myChronometer start
if (!running) {
myChronometer.setBase(SystemClock.elapsedRealtime() - pauseOffset);
myChronometer.start();
running = true;
//***********************
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
mediaRecorder.setOutputFile(AudioSavePathInDevice);
}
}
startRecord Listener
startRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(checkPermission()) {
AudioSavePathInDevice =
Environment.getExternalStorageDirectory().getAbsolutePath() + "/" +
CreateRandomAudioFileName(5) + "AudioRecording.3gp";
MediaRecorderReady();
try {
startRecord.setEnabled(true);
mediaRecorder.prepare();
mediaRecorder.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
startRecord.setEnabled(false);
stopRecord.setEnabled(true);
Toast.makeText(MainActivity.this, "Recording started",
Toast.LENGTH_LONG).show();
} else {
requestPermission();
}
}
});
android android-studio jave
add a comment |
I'm creating a recorder app with chronometer counter, the chronometer is working fine with start record, stop record and stop play.
My problem is only with start play, when pressing start play button, the chronometer start from 0 but I couldn't stop the chronometer when the audio file stops.
This is the start play code, please help. Any help I greatly appreciated
playAudio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) throws IllegalArgumentException,
SecurityException, IllegalStateException {
stopRecord.setEnabled(false);
startRecord.setEnabled(false);
stopAudio.setEnabled(true);
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(AudioSavePathInDevice);
mediaPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
if (!running) {
myChronometer.setBase(SystemClock.elapsedRealtime() - pauseOffset);
myChronometer.start();
running = true;
// myChronometer.stop();
}
mediaPlayer.start();
Toast.makeText(MainActivity.this, "Recording Playing",
Toast.LENGTH_LONG).show();
}
});
Sir, this the code of stop audio
stopAudio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (running) {
myChronometer.stop();
myChronometer.setBase(SystemClock.elapsedRealtime());
pauseOffset = 0;
pauseOffset = SystemClock.elapsedRealtime() - myChronometer.getBase();
running = false;
}
stopRecord.setEnabled(false);
startRecord.setEnabled(true);
stopAudio.setEnabled(false);
playAudio.setEnabled(true);
if(mediaPlayer != null){
mediaPlayer.stop();
mediaPlayer.release();
// MediaRecorderReady();
//resetmymyChronometer
myChronometer.setBase(SystemClock.elapsedRealtime());
pauseOffset = 0;
}
}
});
this is the code of stop record
stopRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (running) {
myChronometer.stop();
myChronometer.setBase(SystemClock.elapsedRealtime());
pauseOffset = 0;
pauseOffset = SystemClock.elapsedRealtime() - myChronometer.getBase();
running = false;
}
mediaRecorder.stop();
stopRecord.setEnabled(false);
playAudio.setEnabled(true);
startRecord.setEnabled(true);
stopAudio.setEnabled(false);
Toast.makeText(MainActivity.this, "Recording Completed",
Toast.LENGTH_LONG).show();
}
});
MediaRecorderReady method
public void MediaRecorderReady(){
//myChronometer start
if (!running) {
myChronometer.setBase(SystemClock.elapsedRealtime() - pauseOffset);
myChronometer.start();
running = true;
//***********************
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
mediaRecorder.setOutputFile(AudioSavePathInDevice);
}
}
startRecord Listener
startRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(checkPermission()) {
AudioSavePathInDevice =
Environment.getExternalStorageDirectory().getAbsolutePath() + "/" +
CreateRandomAudioFileName(5) + "AudioRecording.3gp";
MediaRecorderReady();
try {
startRecord.setEnabled(true);
mediaRecorder.prepare();
mediaRecorder.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
startRecord.setEnabled(false);
stopRecord.setEnabled(true);
Toast.makeText(MainActivity.this, "Recording started",
Toast.LENGTH_LONG).show();
} else {
requestPermission();
}
}
});
android android-studio jave
Please post the code of your stopButton's onClick callback
– matdev
Nov 27 '18 at 15:48
add a comment |
I'm creating a recorder app with chronometer counter, the chronometer is working fine with start record, stop record and stop play.
My problem is only with start play, when pressing start play button, the chronometer start from 0 but I couldn't stop the chronometer when the audio file stops.
This is the start play code, please help. Any help I greatly appreciated
playAudio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) throws IllegalArgumentException,
SecurityException, IllegalStateException {
stopRecord.setEnabled(false);
startRecord.setEnabled(false);
stopAudio.setEnabled(true);
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(AudioSavePathInDevice);
mediaPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
if (!running) {
myChronometer.setBase(SystemClock.elapsedRealtime() - pauseOffset);
myChronometer.start();
running = true;
// myChronometer.stop();
}
mediaPlayer.start();
Toast.makeText(MainActivity.this, "Recording Playing",
Toast.LENGTH_LONG).show();
}
});
Sir, this the code of stop audio
stopAudio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (running) {
myChronometer.stop();
myChronometer.setBase(SystemClock.elapsedRealtime());
pauseOffset = 0;
pauseOffset = SystemClock.elapsedRealtime() - myChronometer.getBase();
running = false;
}
stopRecord.setEnabled(false);
startRecord.setEnabled(true);
stopAudio.setEnabled(false);
playAudio.setEnabled(true);
if(mediaPlayer != null){
mediaPlayer.stop();
mediaPlayer.release();
// MediaRecorderReady();
//resetmymyChronometer
myChronometer.setBase(SystemClock.elapsedRealtime());
pauseOffset = 0;
}
}
});
this is the code of stop record
stopRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (running) {
myChronometer.stop();
myChronometer.setBase(SystemClock.elapsedRealtime());
pauseOffset = 0;
pauseOffset = SystemClock.elapsedRealtime() - myChronometer.getBase();
running = false;
}
mediaRecorder.stop();
stopRecord.setEnabled(false);
playAudio.setEnabled(true);
startRecord.setEnabled(true);
stopAudio.setEnabled(false);
Toast.makeText(MainActivity.this, "Recording Completed",
Toast.LENGTH_LONG).show();
}
});
MediaRecorderReady method
public void MediaRecorderReady(){
//myChronometer start
if (!running) {
myChronometer.setBase(SystemClock.elapsedRealtime() - pauseOffset);
myChronometer.start();
running = true;
//***********************
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
mediaRecorder.setOutputFile(AudioSavePathInDevice);
}
}
startRecord Listener
startRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(checkPermission()) {
AudioSavePathInDevice =
Environment.getExternalStorageDirectory().getAbsolutePath() + "/" +
CreateRandomAudioFileName(5) + "AudioRecording.3gp";
MediaRecorderReady();
try {
startRecord.setEnabled(true);
mediaRecorder.prepare();
mediaRecorder.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
startRecord.setEnabled(false);
stopRecord.setEnabled(true);
Toast.makeText(MainActivity.this, "Recording started",
Toast.LENGTH_LONG).show();
} else {
requestPermission();
}
}
});
android android-studio jave
I'm creating a recorder app with chronometer counter, the chronometer is working fine with start record, stop record and stop play.
My problem is only with start play, when pressing start play button, the chronometer start from 0 but I couldn't stop the chronometer when the audio file stops.
This is the start play code, please help. Any help I greatly appreciated
playAudio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) throws IllegalArgumentException,
SecurityException, IllegalStateException {
stopRecord.setEnabled(false);
startRecord.setEnabled(false);
stopAudio.setEnabled(true);
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(AudioSavePathInDevice);
mediaPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
if (!running) {
myChronometer.setBase(SystemClock.elapsedRealtime() - pauseOffset);
myChronometer.start();
running = true;
// myChronometer.stop();
}
mediaPlayer.start();
Toast.makeText(MainActivity.this, "Recording Playing",
Toast.LENGTH_LONG).show();
}
});
Sir, this the code of stop audio
stopAudio.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (running) {
myChronometer.stop();
myChronometer.setBase(SystemClock.elapsedRealtime());
pauseOffset = 0;
pauseOffset = SystemClock.elapsedRealtime() - myChronometer.getBase();
running = false;
}
stopRecord.setEnabled(false);
startRecord.setEnabled(true);
stopAudio.setEnabled(false);
playAudio.setEnabled(true);
if(mediaPlayer != null){
mediaPlayer.stop();
mediaPlayer.release();
// MediaRecorderReady();
//resetmymyChronometer
myChronometer.setBase(SystemClock.elapsedRealtime());
pauseOffset = 0;
}
}
});
this is the code of stop record
stopRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (running) {
myChronometer.stop();
myChronometer.setBase(SystemClock.elapsedRealtime());
pauseOffset = 0;
pauseOffset = SystemClock.elapsedRealtime() - myChronometer.getBase();
running = false;
}
mediaRecorder.stop();
stopRecord.setEnabled(false);
playAudio.setEnabled(true);
startRecord.setEnabled(true);
stopAudio.setEnabled(false);
Toast.makeText(MainActivity.this, "Recording Completed",
Toast.LENGTH_LONG).show();
}
});
MediaRecorderReady method
public void MediaRecorderReady(){
//myChronometer start
if (!running) {
myChronometer.setBase(SystemClock.elapsedRealtime() - pauseOffset);
myChronometer.start();
running = true;
//***********************
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
mediaRecorder.setOutputFile(AudioSavePathInDevice);
}
}
startRecord Listener
startRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(checkPermission()) {
AudioSavePathInDevice =
Environment.getExternalStorageDirectory().getAbsolutePath() + "/" +
CreateRandomAudioFileName(5) + "AudioRecording.3gp";
MediaRecorderReady();
try {
startRecord.setEnabled(true);
mediaRecorder.prepare();
mediaRecorder.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
startRecord.setEnabled(false);
stopRecord.setEnabled(true);
Toast.makeText(MainActivity.this, "Recording started",
Toast.LENGTH_LONG).show();
} else {
requestPermission();
}
}
});
android android-studio jave
android android-studio jave
edited Nov 27 '18 at 17:42
colla
asked Nov 27 '18 at 15:40
collacolla
14
14
Please post the code of your stopButton's onClick callback
– matdev
Nov 27 '18 at 15:48
add a comment |
Please post the code of your stopButton's onClick callback
– matdev
Nov 27 '18 at 15:48
Please post the code of your stopButton's onClick callback
– matdev
Nov 27 '18 at 15:48
Please post the code of your stopButton's onClick callback
– matdev
Nov 27 '18 at 15:48
add a comment |
2 Answers
2
active
oldest
votes
You can use OnCompletionListener, for example:
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
// your code to stop record
}
});
for more information :
https://developer.android.com/reference/android/media/MediaPlayer.OnCompletionListener
how I can use this listener, please
– colla
Nov 27 '18 at 18:10
It's called when the end of a media source is reached during playback , so you can use it after you initialize MediaPlayer , and put your code to stop the chrono into onCompletion(MediaPlayer mp) [mp parameter : the MediaPlayer that reached the end of the file]
– Sofiane Majdoub
Nov 27 '18 at 19:02
it's work, thank you ver y much
– colla
Nov 27 '18 at 20:12
Sir, how I can display the audio file location to share it?
– colla
Nov 27 '18 at 20:50
you have in your code : AudioSavePathInDevice = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + CreateRandomAudioFileName(5) + "AudioRecording.3gp";
– Sofiane Majdoub
Nov 27 '18 at 22:14
|
show 5 more comments
The line
myChronometer.stop();
is never called.
In your playAudio's onClick() method, you should set
running = true
That's an other problem.
– matdev
Nov 27 '18 at 16:25
running = true it's already there Sir in playAudio
– colla
Nov 27 '18 at 16:31
No it is not, you just check for running value
– matdev
Nov 27 '18 at 16:40
Sir, in playAudio I called (MediaRecorderReady) and there is running = true, SORRY i didn't mention it in my question, question updated
– colla
Nov 27 '18 at 16:59
Based on the code you posted, MediaRecorderReady() is not called in playAudio's onClick, only in stopAudio's
– matdev
Nov 27 '18 at 17:03
|
show 7 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53503154%2fplay-recorded-audio-with-chronometer-counter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use OnCompletionListener, for example:
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
// your code to stop record
}
});
for more information :
https://developer.android.com/reference/android/media/MediaPlayer.OnCompletionListener
how I can use this listener, please
– colla
Nov 27 '18 at 18:10
It's called when the end of a media source is reached during playback , so you can use it after you initialize MediaPlayer , and put your code to stop the chrono into onCompletion(MediaPlayer mp) [mp parameter : the MediaPlayer that reached the end of the file]
– Sofiane Majdoub
Nov 27 '18 at 19:02
it's work, thank you ver y much
– colla
Nov 27 '18 at 20:12
Sir, how I can display the audio file location to share it?
– colla
Nov 27 '18 at 20:50
you have in your code : AudioSavePathInDevice = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + CreateRandomAudioFileName(5) + "AudioRecording.3gp";
– Sofiane Majdoub
Nov 27 '18 at 22:14
|
show 5 more comments
You can use OnCompletionListener, for example:
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
// your code to stop record
}
});
for more information :
https://developer.android.com/reference/android/media/MediaPlayer.OnCompletionListener
how I can use this listener, please
– colla
Nov 27 '18 at 18:10
It's called when the end of a media source is reached during playback , so you can use it after you initialize MediaPlayer , and put your code to stop the chrono into onCompletion(MediaPlayer mp) [mp parameter : the MediaPlayer that reached the end of the file]
– Sofiane Majdoub
Nov 27 '18 at 19:02
it's work, thank you ver y much
– colla
Nov 27 '18 at 20:12
Sir, how I can display the audio file location to share it?
– colla
Nov 27 '18 at 20:50
you have in your code : AudioSavePathInDevice = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + CreateRandomAudioFileName(5) + "AudioRecording.3gp";
– Sofiane Majdoub
Nov 27 '18 at 22:14
|
show 5 more comments
You can use OnCompletionListener, for example:
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
// your code to stop record
}
});
for more information :
https://developer.android.com/reference/android/media/MediaPlayer.OnCompletionListener
You can use OnCompletionListener, for example:
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
// your code to stop record
}
});
for more information :
https://developer.android.com/reference/android/media/MediaPlayer.OnCompletionListener
answered Nov 27 '18 at 17:19
Sofiane MajdoubSofiane Majdoub
11117
11117
how I can use this listener, please
– colla
Nov 27 '18 at 18:10
It's called when the end of a media source is reached during playback , so you can use it after you initialize MediaPlayer , and put your code to stop the chrono into onCompletion(MediaPlayer mp) [mp parameter : the MediaPlayer that reached the end of the file]
– Sofiane Majdoub
Nov 27 '18 at 19:02
it's work, thank you ver y much
– colla
Nov 27 '18 at 20:12
Sir, how I can display the audio file location to share it?
– colla
Nov 27 '18 at 20:50
you have in your code : AudioSavePathInDevice = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + CreateRandomAudioFileName(5) + "AudioRecording.3gp";
– Sofiane Majdoub
Nov 27 '18 at 22:14
|
show 5 more comments
how I can use this listener, please
– colla
Nov 27 '18 at 18:10
It's called when the end of a media source is reached during playback , so you can use it after you initialize MediaPlayer , and put your code to stop the chrono into onCompletion(MediaPlayer mp) [mp parameter : the MediaPlayer that reached the end of the file]
– Sofiane Majdoub
Nov 27 '18 at 19:02
it's work, thank you ver y much
– colla
Nov 27 '18 at 20:12
Sir, how I can display the audio file location to share it?
– colla
Nov 27 '18 at 20:50
you have in your code : AudioSavePathInDevice = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + CreateRandomAudioFileName(5) + "AudioRecording.3gp";
– Sofiane Majdoub
Nov 27 '18 at 22:14
how I can use this listener, please
– colla
Nov 27 '18 at 18:10
how I can use this listener, please
– colla
Nov 27 '18 at 18:10
It's called when the end of a media source is reached during playback , so you can use it after you initialize MediaPlayer , and put your code to stop the chrono into onCompletion(MediaPlayer mp) [mp parameter : the MediaPlayer that reached the end of the file]
– Sofiane Majdoub
Nov 27 '18 at 19:02
It's called when the end of a media source is reached during playback , so you can use it after you initialize MediaPlayer , and put your code to stop the chrono into onCompletion(MediaPlayer mp) [mp parameter : the MediaPlayer that reached the end of the file]
– Sofiane Majdoub
Nov 27 '18 at 19:02
it's work, thank you ver y much
– colla
Nov 27 '18 at 20:12
it's work, thank you ver y much
– colla
Nov 27 '18 at 20:12
Sir, how I can display the audio file location to share it?
– colla
Nov 27 '18 at 20:50
Sir, how I can display the audio file location to share it?
– colla
Nov 27 '18 at 20:50
you have in your code : AudioSavePathInDevice = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + CreateRandomAudioFileName(5) + "AudioRecording.3gp";
– Sofiane Majdoub
Nov 27 '18 at 22:14
you have in your code : AudioSavePathInDevice = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + CreateRandomAudioFileName(5) + "AudioRecording.3gp";
– Sofiane Majdoub
Nov 27 '18 at 22:14
|
show 5 more comments
The line
myChronometer.stop();
is never called.
In your playAudio's onClick() method, you should set
running = true
That's an other problem.
– matdev
Nov 27 '18 at 16:25
running = true it's already there Sir in playAudio
– colla
Nov 27 '18 at 16:31
No it is not, you just check for running value
– matdev
Nov 27 '18 at 16:40
Sir, in playAudio I called (MediaRecorderReady) and there is running = true, SORRY i didn't mention it in my question, question updated
– colla
Nov 27 '18 at 16:59
Based on the code you posted, MediaRecorderReady() is not called in playAudio's onClick, only in stopAudio's
– matdev
Nov 27 '18 at 17:03
|
show 7 more comments
The line
myChronometer.stop();
is never called.
In your playAudio's onClick() method, you should set
running = true
That's an other problem.
– matdev
Nov 27 '18 at 16:25
running = true it's already there Sir in playAudio
– colla
Nov 27 '18 at 16:31
No it is not, you just check for running value
– matdev
Nov 27 '18 at 16:40
Sir, in playAudio I called (MediaRecorderReady) and there is running = true, SORRY i didn't mention it in my question, question updated
– colla
Nov 27 '18 at 16:59
Based on the code you posted, MediaRecorderReady() is not called in playAudio's onClick, only in stopAudio's
– matdev
Nov 27 '18 at 17:03
|
show 7 more comments
The line
myChronometer.stop();
is never called.
In your playAudio's onClick() method, you should set
running = true
The line
myChronometer.stop();
is never called.
In your playAudio's onClick() method, you should set
running = true
answered Nov 27 '18 at 16:17
matdevmatdev
92731331
92731331
That's an other problem.
– matdev
Nov 27 '18 at 16:25
running = true it's already there Sir in playAudio
– colla
Nov 27 '18 at 16:31
No it is not, you just check for running value
– matdev
Nov 27 '18 at 16:40
Sir, in playAudio I called (MediaRecorderReady) and there is running = true, SORRY i didn't mention it in my question, question updated
– colla
Nov 27 '18 at 16:59
Based on the code you posted, MediaRecorderReady() is not called in playAudio's onClick, only in stopAudio's
– matdev
Nov 27 '18 at 17:03
|
show 7 more comments
That's an other problem.
– matdev
Nov 27 '18 at 16:25
running = true it's already there Sir in playAudio
– colla
Nov 27 '18 at 16:31
No it is not, you just check for running value
– matdev
Nov 27 '18 at 16:40
Sir, in playAudio I called (MediaRecorderReady) and there is running = true, SORRY i didn't mention it in my question, question updated
– colla
Nov 27 '18 at 16:59
Based on the code you posted, MediaRecorderReady() is not called in playAudio's onClick, only in stopAudio's
– matdev
Nov 27 '18 at 17:03
That's an other problem.
– matdev
Nov 27 '18 at 16:25
That's an other problem.
– matdev
Nov 27 '18 at 16:25
running = true it's already there Sir in playAudio
– colla
Nov 27 '18 at 16:31
running = true it's already there Sir in playAudio
– colla
Nov 27 '18 at 16:31
No it is not, you just check for running value
– matdev
Nov 27 '18 at 16:40
No it is not, you just check for running value
– matdev
Nov 27 '18 at 16:40
Sir, in playAudio I called (MediaRecorderReady) and there is running = true, SORRY i didn't mention it in my question, question updated
– colla
Nov 27 '18 at 16:59
Sir, in playAudio I called (MediaRecorderReady) and there is running = true, SORRY i didn't mention it in my question, question updated
– colla
Nov 27 '18 at 16:59
Based on the code you posted, MediaRecorderReady() is not called in playAudio's onClick, only in stopAudio's
– matdev
Nov 27 '18 at 17:03
Based on the code you posted, MediaRecorderReady() is not called in playAudio's onClick, only in stopAudio's
– matdev
Nov 27 '18 at 17:03
|
show 7 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53503154%2fplay-recorded-audio-with-chronometer-counter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please post the code of your stopButton's onClick callback
– matdev
Nov 27 '18 at 15:48