|
|
@ -115,16 +115,11 @@ public class WebViewActivity extends BaseActivity { |
|
|
//static String HtmlUrl = "http://192.168.0.105:5173/";
|
|
|
//static String HtmlUrl = "http://192.168.0.105:5173/";
|
|
|
int time = 0; |
|
|
int time = 0; |
|
|
String interfaceRequestData=""; |
|
|
String interfaceRequestData=""; |
|
|
private VideoView currentVideo; //当前
|
|
|
|
|
|
private VideoView proVideo; //上一个视频
|
|
|
|
|
|
private boolean isChatMan=false; //是否是数字人项目
|
|
|
|
|
|
// 语音听写对象
|
|
|
// 语音听写对象
|
|
|
private AICloudASREngine mEngine; |
|
|
private AICloudASREngine mEngine; |
|
|
private AICloudASRIntent aiCloudASRIntent; |
|
|
private AICloudASRIntent aiCloudASRIntent; |
|
|
private TTSUtil ttsUtil; |
|
|
private TTSUtil ttsUtil; |
|
|
private String oldString=""; |
|
|
private String oldString=""; |
|
|
private Map<String, VideoView> videoMap = new HashMap<>(); |
|
|
|
|
|
private String videoAfter=""; |
|
|
|
|
|
|
|
|
|
|
|
// 语音听写对象
|
|
|
// 语音听写对象
|
|
|
private ASR mAsr; |
|
|
private ASR mAsr; |
|
|
@ -191,72 +186,6 @@ public class WebViewActivity extends BaseActivity { |
|
|
DeviceUtil.screenType(this); |
|
|
DeviceUtil.screenType(this); |
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
|
|
binding = DataBindingUtil.setContentView(this, R.layout.activity_webview); |
|
|
binding = DataBindingUtil.setContentView(this, R.layout.activity_webview); |
|
|
|
|
|
|
|
|
String jsonString = FileUtil.readLocalJsonForStorage(this, StringUtil.strSplice(Constant.CACHE_PATH3,"/JSON/getChatManVideo.json")); |
|
|
|
|
|
if(!StringUtil.isEmpty(jsonString) && MyApplication.getInstance().duiliteConfig){ //是AI
|
|
|
|
|
|
// 设置背景透明度
|
|
|
|
|
|
binding.web.setBackgroundColor(Color.TRANSPARENT); |
|
|
|
|
|
isChatMan = true; |
|
|
|
|
|
try { |
|
|
|
|
|
JSONObject jsonObject = new JSONObject(jsonString); |
|
|
|
|
|
JSONArray dataArray = jsonObject.getJSONArray("data"); |
|
|
|
|
|
for (int i = 0; i < dataArray.length(); i++) { |
|
|
|
|
|
JSONObject videoObj = dataArray.getJSONObject(i).getJSONObject("content"); |
|
|
|
|
|
String vType = videoObj.getString("type"); |
|
|
|
|
|
Uri videoUri = Uri.parse(StringUtil.strSplice(Constant.CACHE_PATH3,videoObj.getJSONArray("url").getString(0))); |
|
|
|
|
|
|
|
|
|
|
|
VideoView video = new VideoView(this); |
|
|
|
|
|
video.setId(View.generateViewId()); |
|
|
|
|
|
FrameLayout.LayoutParams videoParams = new FrameLayout.LayoutParams( |
|
|
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT, // 宽度匹配父布局
|
|
|
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT // 高度匹配父布局
|
|
|
|
|
|
); |
|
|
|
|
|
video.setLayoutParams(videoParams); |
|
|
|
|
|
if("bg".equals(vType)){ |
|
|
|
|
|
currentVideo = video; |
|
|
|
|
|
proVideo = video; |
|
|
|
|
|
video.setVisibility(View.VISIBLE); |
|
|
|
|
|
}else{ |
|
|
|
|
|
video.setVisibility(View.GONE); |
|
|
|
|
|
} |
|
|
|
|
|
binding.videoLayout.addView(video); |
|
|
|
|
|
video.setVideoURI(videoUri); |
|
|
|
|
|
if("chatback".equals(vType) || "chatto".equals(vType)){ |
|
|
|
|
|
video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onPrepared(MediaPlayer mp) { |
|
|
|
|
|
video.start(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
video.setOnErrorListener(new MediaPlayer.OnErrorListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public boolean onError(MediaPlayer mp, int what, int extra) { |
|
|
|
|
|
return true; // 返回true表示已处理,不会弹出系统默认提示
|
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
video.setOnCompletionListener( mp -> changeVideo("bg")); |
|
|
|
|
|
}else{ |
|
|
|
|
|
video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onPrepared(MediaPlayer mp) { |
|
|
|
|
|
mp.setLooping(true); // 可选:设置循环播
|
|
|
|
|
|
video.start(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
video.setOnErrorListener(new MediaPlayer.OnErrorListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public boolean onError(MediaPlayer mp, int what, int extra) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
videoMap.put(vType, video); |
|
|
|
|
|
} |
|
|
|
|
|
}catch (JSONException e){ |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//设置密码
|
|
|
//设置密码
|
|
|
initPass(); |
|
|
initPass(); |
|
|
try{ |
|
|
try{ |
|
|
@ -273,87 +202,6 @@ public class WebViewActivity extends BaseActivity { |
|
|
LoggerUtil.e("语音ASR:","初始化失败!"); |
|
|
LoggerUtil.e("语音ASR:","初始化失败!"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
//切换视频状态
|
|
|
|
|
|
private void changeVideoAfter(){ |
|
|
|
|
|
if("".equals(videoAfter)){ //新状态正常
|
|
|
|
|
|
changeVideo("back"); |
|
|
|
|
|
}else{ //新状态彩蛋
|
|
|
|
|
|
changeVideo("to"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//切换视频
|
|
|
|
|
|
public void changeVideo(String type){ |
|
|
|
|
|
if(!isChatMan){ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
VideoView nextVideo; |
|
|
|
|
|
proVideo.clearAnimation(); |
|
|
|
|
|
currentVideo.clearAnimation(); |
|
|
|
|
|
|
|
|
|
|
|
switch(type.trim()){ |
|
|
|
|
|
case "back" : |
|
|
|
|
|
nextVideo = videoMap.get("chatback"); |
|
|
|
|
|
break; |
|
|
|
|
|
case "to" : |
|
|
|
|
|
nextVideo = videoMap.get("chatto"); |
|
|
|
|
|
break; |
|
|
|
|
|
case "bg" : |
|
|
|
|
|
nextVideo = "".equals(videoAfter) ? videoMap.get("bg") : videoMap.get("bg1"); |
|
|
|
|
|
break; |
|
|
|
|
|
case "answer" : |
|
|
|
|
|
nextVideo = "".equals(videoAfter) ? videoMap.get("speek") : videoMap.get("speek1"); |
|
|
|
|
|
break; |
|
|
|
|
|
case "hello" : |
|
|
|
|
|
nextVideo = "".equals(videoAfter) ? videoMap.get("hello") : videoMap.get("hello1"); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
nextVideo = "".equals(videoAfter) ? videoMap.get("bg") : videoMap.get("bg1"); |
|
|
|
|
|
} |
|
|
|
|
|
// 检查是否是重复切换
|
|
|
|
|
|
if (nextVideo == currentVideo) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LoggerUtil.e("切换视频", type.trim()); |
|
|
|
|
|
proVideo = currentVideo; |
|
|
|
|
|
|
|
|
|
|
|
proVideo.animate() |
|
|
|
|
|
.alpha(0.5f) |
|
|
|
|
|
.setDuration(240) |
|
|
|
|
|
.setListener(new AnimatorListenerAdapter() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onAnimationEnd(Animator animation) { |
|
|
|
|
|
super.onAnimationEnd(animation); |
|
|
|
|
|
// proVideo.seekTo(0);
|
|
|
|
|
|
proVideo.pause(); |
|
|
|
|
|
//proVideo.stopPlayback();
|
|
|
|
|
|
proVideo.setVisibility(View.GONE); |
|
|
|
|
|
proVideo.setAlpha(1.0f); |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
.start(); |
|
|
|
|
|
|
|
|
|
|
|
nextVideo.setAlpha(0.5f); |
|
|
|
|
|
nextVideo.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
|
|
|
|
currentVideo = nextVideo; |
|
|
|
|
|
// 开始淡入动画
|
|
|
|
|
|
currentVideo.animate() |
|
|
|
|
|
.alpha(1.0f) |
|
|
|
|
|
.setDuration(300) |
|
|
|
|
|
.setListener(new AnimatorListenerAdapter() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onAnimationEnd(Animator animation) { |
|
|
|
|
|
super.onAnimationEnd(animation); |
|
|
|
|
|
currentVideo.seekTo(0); |
|
|
|
|
|
currentVideo.start(); |
|
|
|
|
|
currentVideo.setAlpha(1.0f); |
|
|
|
|
|
LoggerUtil.e("切换视频:","动画播放完成"); |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
.start(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected void setData() { |
|
|
protected void setData() { |
|
|
@ -577,13 +425,6 @@ public class WebViewActivity extends BaseActivity { |
|
|
@JavascriptInterface |
|
|
@JavascriptInterface |
|
|
public void changeVideoState(String txt) { |
|
|
public void changeVideoState(String txt) { |
|
|
LoggerUtil.e(TAG,"JS调用了Android的方法:changeVideoState()"); |
|
|
LoggerUtil.e(TAG,"JS调用了Android的方法:changeVideoState()"); |
|
|
videoAfter = txt; |
|
|
|
|
|
runOnUiThread(new Runnable() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void run() { |
|
|
|
|
|
changeVideoAfter(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
// h5调用android:开始识别语音
|
|
|
// h5调用android:开始识别语音
|
|
|
@JavascriptInterface |
|
|
@JavascriptInterface |
|
|
@ -633,12 +474,6 @@ public class WebViewActivity extends BaseActivity { |
|
|
LoggerUtil.e(TAG,"JS调用了Android的方法:stopTTS()"); |
|
|
LoggerUtil.e(TAG,"JS调用了Android的方法:stopTTS()"); |
|
|
if("sbc".equals(Constant.TTSHome)){ |
|
|
if("sbc".equals(Constant.TTSHome)){ |
|
|
ttsUtil.stopTTs(); |
|
|
ttsUtil.stopTTs(); |
|
|
runOnUiThread(new Runnable() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void run() { |
|
|
|
|
|
changeVideo("bg"); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}else if("kdxf".equals(Constant.TTSHome)){ |
|
|
}else if("kdxf".equals(Constant.TTSHome)){ |
|
|
kxdfttsUtil.stopTTs(); |
|
|
kxdfttsUtil.stopTTs(); |
|
|
} |
|
|
} |
|
|
@ -647,12 +482,6 @@ public class WebViewActivity extends BaseActivity { |
|
|
@JavascriptInterface |
|
|
@JavascriptInterface |
|
|
public void playAudio(String str) { |
|
|
public void playAudio(String str) { |
|
|
LoggerUtil.e("JS调用了Android的方法:playAudio", str); |
|
|
LoggerUtil.e("JS调用了Android的方法:playAudio", str); |
|
|
runOnUiThread(new Runnable() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void run() { |
|
|
|
|
|
changeVideo(str); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
// h5调用android:新版指路机传入的数据
|
|
|
// h5调用android:新版指路机传入的数据
|
|
|
@JavascriptInterface |
|
|
@JavascriptInterface |
|
|
@ -816,7 +645,6 @@ public class WebViewActivity extends BaseActivity { |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case Constant.VOID_STOP: |
|
|
case Constant.VOID_STOP: |
|
|
changeVideo("bg"); |
|
|
|
|
|
runOnUiThread(new Runnable() { |
|
|
runOnUiThread(new Runnable() { |
|
|
@Override |
|
|
@Override |
|
|
public void run() { |
|
|
public void run() { |
|
|
|