音频弹窗提示取消

This commit is contained in:
wujie
2022-11-07 14:32:46 +08:00
parent 5199147f58
commit f80dd211f1
2 changed files with 27 additions and 16 deletions

View File

@ -25,6 +25,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import java.io.IOException;
import java.util.Map; import java.util.Map;
import chaoran.business.BrandEnum; import chaoran.business.BrandEnum;
@ -206,6 +207,11 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
duPlayer.release(); duPlayer.release();
duPlayer = null; duPlayer = null;
} }
if (dingPlayer != null) {
dingPlayer.stop();
dingPlayer.release();
dingPlayer = null;
}
if (vibrator != null) { if (vibrator != null) {
vibrator.cancel(); vibrator.cancel();
} }
@ -252,27 +258,31 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
} }
private MediaPlayer diPlayer = null; private MediaPlayer diPlayer = null;
private MediaPlayer duPlayer = null; private MediaPlayer duPlayer = null;
private MediaPlayer dingPlayer = null;
private String ttsNr; private String ttsNr;
public Vibrator vibrator; public Vibrator vibrator;
@JavascriptInterface @JavascriptInterface
public void play(String msg, String type, int isZd) { public void play(String msg, String type, int isZd) throws IOException {
ttsNr = msg; ttsNr = msg;
if ("1".equals(type)) { if ("1".equals(type)) {
diPlayer = null; if (diPlayer == null) {
diPlayer = MediaPlayer.create(this, R.raw.didi); diPlayer = MediaPlayer.create(this, R.raw.didi);
diPlayer.setOnCompletionListener(completionListener); diPlayer.setOnCompletionListener(completionListener);
}
diPlayer.start(); diPlayer.start();
} else if ("2".equals(type)) { } else if ("2".equals(type)) {
diPlayer = null; if (duPlayer == null) {
duPlayer = MediaPlayer.create(this, R.raw.dudu); duPlayer = MediaPlayer.create(this, R.raw.dudu);
duPlayer.setOnCompletionListener(completionListener); duPlayer.setOnCompletionListener(completionListener);
}
duPlayer.start(); duPlayer.start();
} else if ("10".equals(type)) { } else if ("10".equals(type)) {
diPlayer = null; if (dingPlayer == null) {
duPlayer = MediaPlayer.create(this, R.raw.ding); dingPlayer = MediaPlayer.create(this, R.raw.ding);
duPlayer.setOnCompletionListener(completionListener); dingPlayer.setOnCompletionListener(completionListener);
duPlayer.start(); }
dingPlayer.start();
} else { } else {
//isZd = 1; //isZd = 1;
if (voiceEngine != null) { if (voiceEngine != null) {
@ -286,6 +296,7 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
vibrator.vibrate(2000); vibrator.vibrate(2000);
} }
} }
private MediaPlayer.OnCompletionListener completionListener = new MediaPlayer.OnCompletionListener() { private MediaPlayer.OnCompletionListener completionListener = new MediaPlayer.OnCompletionListener() {
// @Override // @Override
public void onCompletion(MediaPlayer mp) { public void onCompletion(MediaPlayer mp) {

View File

@ -109,22 +109,22 @@ public class TekVoiceEngine extends OfflineVoiceEngine {
String info) { String info) {
// 合成进度 // 合成进度
mPercentForBuffering = percent; mPercentForBuffering = percent;
showTip(String.format(context.getString(R.string.tts_toast_format), // showTip(String.format(context.getString(R.string.tts_toast_format),
mPercentForBuffering, mPercentForPlaying)); // mPercentForBuffering, mPercentForPlaying));
} }
@Override @Override
public void onSpeakProgress(int percent, int beginPos, int endPos) { public void onSpeakProgress(int percent, int beginPos, int endPos) {
// 播放进度 // 播放进度
mPercentForPlaying = percent; mPercentForPlaying = percent;
showTip(String.format(context.getString(R.string.tts_toast_format), // showTip(String.format(context.getString(R.string.tts_toast_format),
mPercentForBuffering, mPercentForPlaying)); // mPercentForBuffering, mPercentForPlaying));
} }
@Override @Override
public void onCompleted(SpeechError error) { public void onCompleted(SpeechError error) {
if (error == null) { if (error == null) {
showTip("播放完成"); // showTip("播放完成");
} else if (error != null) { } else if (error != null) {
showTip(error.getPlainDescription(true)); showTip(error.getPlainDescription(true));
} }