音频弹窗提示取消
This commit is contained in:
@ -25,6 +25,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import chaoran.business.BrandEnum;
|
||||
@ -206,6 +207,11 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
||||
duPlayer.release();
|
||||
duPlayer = null;
|
||||
}
|
||||
if (dingPlayer != null) {
|
||||
dingPlayer.stop();
|
||||
dingPlayer.release();
|
||||
dingPlayer = null;
|
||||
}
|
||||
if (vibrator != null) {
|
||||
vibrator.cancel();
|
||||
}
|
||||
@ -252,27 +258,31 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
||||
}
|
||||
private MediaPlayer diPlayer = null;
|
||||
private MediaPlayer duPlayer = null;
|
||||
private MediaPlayer dingPlayer = null;
|
||||
private String ttsNr;
|
||||
public Vibrator vibrator;
|
||||
|
||||
@JavascriptInterface
|
||||
public void play(String msg, String type, int isZd) {
|
||||
public void play(String msg, String type, int isZd) throws IOException {
|
||||
ttsNr = msg;
|
||||
if ("1".equals(type)) {
|
||||
diPlayer = null;
|
||||
diPlayer = MediaPlayer.create(this, R.raw.didi);
|
||||
diPlayer.setOnCompletionListener(completionListener);
|
||||
if (diPlayer == null) {
|
||||
diPlayer = MediaPlayer.create(this, R.raw.didi);
|
||||
diPlayer.setOnCompletionListener(completionListener);
|
||||
}
|
||||
diPlayer.start();
|
||||
} else if ("2".equals(type)) {
|
||||
diPlayer = null;
|
||||
duPlayer = MediaPlayer.create(this, R.raw.dudu);
|
||||
duPlayer.setOnCompletionListener(completionListener);
|
||||
if (duPlayer == null) {
|
||||
duPlayer = MediaPlayer.create(this, R.raw.dudu);
|
||||
duPlayer.setOnCompletionListener(completionListener);
|
||||
}
|
||||
duPlayer.start();
|
||||
} else if ("10".equals(type)) {
|
||||
diPlayer = null;
|
||||
duPlayer = MediaPlayer.create(this, R.raw.ding);
|
||||
duPlayer.setOnCompletionListener(completionListener);
|
||||
duPlayer.start();
|
||||
if (dingPlayer == null) {
|
||||
dingPlayer = MediaPlayer.create(this, R.raw.ding);
|
||||
dingPlayer.setOnCompletionListener(completionListener);
|
||||
}
|
||||
dingPlayer.start();
|
||||
} else {
|
||||
//isZd = 1;
|
||||
if (voiceEngine != null) {
|
||||
@ -286,6 +296,7 @@ public class MainActivity extends AppCompatActivity implements ResultListener{
|
||||
vibrator.vibrate(2000);
|
||||
}
|
||||
}
|
||||
|
||||
private MediaPlayer.OnCompletionListener completionListener = new MediaPlayer.OnCompletionListener() {
|
||||
// @Override
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
|
||||
@ -109,22 +109,22 @@ public class TekVoiceEngine extends OfflineVoiceEngine {
|
||||
String info) {
|
||||
// 合成进度
|
||||
mPercentForBuffering = percent;
|
||||
showTip(String.format(context.getString(R.string.tts_toast_format),
|
||||
mPercentForBuffering, mPercentForPlaying));
|
||||
// showTip(String.format(context.getString(R.string.tts_toast_format),
|
||||
// mPercentForBuffering, mPercentForPlaying));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpeakProgress(int percent, int beginPos, int endPos) {
|
||||
// 播放进度
|
||||
mPercentForPlaying = percent;
|
||||
showTip(String.format(context.getString(R.string.tts_toast_format),
|
||||
mPercentForBuffering, mPercentForPlaying));
|
||||
// showTip(String.format(context.getString(R.string.tts_toast_format),
|
||||
// mPercentForBuffering, mPercentForPlaying));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted(SpeechError error) {
|
||||
if (error == null) {
|
||||
showTip("播放完成");
|
||||
// showTip("播放完成");
|
||||
} else if (error != null) {
|
||||
showTip(error.getPlainDescription(true));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user