|
|
|
@ -46,6 +46,8 @@ import com.alibaba.android.arouter.launcher.ARouter; |
|
|
|
import org.greenrobot.eventbus.EventBus; |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import qianmu.container.R; |
|
|
|
import qianmu.container.activity.BaseActivity; |
|
|
|
@ -86,6 +88,8 @@ public class WebViewActivity extends BaseActivity { |
|
|
|
private AICloudASRIntent aiCloudASRIntent; |
|
|
|
private TTSUtil ttsUtil; |
|
|
|
private String oldString=""; |
|
|
|
private Map<String, Uri> videoMap = new HashMap<>(); |
|
|
|
private String videoAfter=""; |
|
|
|
|
|
|
|
Handler handler = new Handler() { |
|
|
|
@SuppressLint("HandlerLeak") |
|
|
|
@ -143,11 +147,40 @@ public class WebViewActivity extends BaseActivity { |
|
|
|
// 设置背景透明度
|
|
|
|
binding.web.setBackgroundColor(0); |
|
|
|
binding.web.getBackground().setAlpha(0); |
|
|
|
|
|
|
|
loadingbgVideo(true); |
|
|
|
//初始化视频列表
|
|
|
|
Uri videoUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.bg); |
|
|
|
//小红帽背景
|
|
|
|
videoMap.put("hat_bg", videoUri); |
|
|
|
//小红帽打招呼
|
|
|
|
Uri videoUri1 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.hello); |
|
|
|
videoMap.put("hat_hello", videoUri1); |
|
|
|
//小红帽讲话
|
|
|
|
Uri videoUri2 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.speek); |
|
|
|
videoMap.put("hat_speek", videoUri2); |
|
|
|
|
|
|
|
//小红帽变身贵妇
|
|
|
|
Uri videoUri3 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.hatto); |
|
|
|
videoMap.put("hat_to", videoUri3); |
|
|
|
//贵妇变身小红帽
|
|
|
|
Uri videoUri4 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.hatback); |
|
|
|
videoMap.put("hat_back", videoUri4); |
|
|
|
//贵妇背景
|
|
|
|
Uri videoUri5 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.bg1); |
|
|
|
videoMap.put("hat_bg1", videoUri5); |
|
|
|
Uri videoUri6 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.hello1); |
|
|
|
videoMap.put("hat_hello1", videoUri6); |
|
|
|
Uri videoUri7 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.speek1); |
|
|
|
videoMap.put("hat_speek1", videoUri7); |
|
|
|
|
|
|
|
loadingbgVideo(); |
|
|
|
currentVideo = binding.bgVideo; |
|
|
|
loadingHelloVideo(); |
|
|
|
loadingSpeekVideo(); |
|
|
|
loadingToVideo(); |
|
|
|
loadingBackVideo(); |
|
|
|
loadingbgVideo1(); |
|
|
|
loadingHelloVideo1(); |
|
|
|
loadingSpeekVideo1(); |
|
|
|
//设置密码
|
|
|
|
initPass(); |
|
|
|
if("sbc".equals(Constant.TTSFac)){ // 思必驰
|
|
|
|
@ -156,9 +189,8 @@ public class WebViewActivity extends BaseActivity { |
|
|
|
ttsUtil.initTts(); |
|
|
|
} |
|
|
|
} |
|
|
|
private void loadingbgVideo(Boolean isplay){ |
|
|
|
Uri videoUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.bg); |
|
|
|
binding.bgVideo.setVideoURI(videoUri); |
|
|
|
private void loadingbgVideo(){ |
|
|
|
binding.bgVideo.setVideoURI(videoMap.get("hat_bg")); |
|
|
|
binding.bgVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { |
|
|
|
@Override |
|
|
|
public void onPrepared(MediaPlayer mp) { |
|
|
|
@ -175,8 +207,7 @@ public class WebViewActivity extends BaseActivity { |
|
|
|
}); |
|
|
|
} |
|
|
|
private void loadingHelloVideo(){ |
|
|
|
Uri videoUri1 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.hello); |
|
|
|
binding.helloVideo.setVideoURI(videoUri1); |
|
|
|
binding.helloVideo.setVideoURI(videoMap.get("hat_hello")); |
|
|
|
binding.helloVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { |
|
|
|
@Override |
|
|
|
public void onPrepared(MediaPlayer mp) { |
|
|
|
@ -193,8 +224,7 @@ public class WebViewActivity extends BaseActivity { |
|
|
|
}); |
|
|
|
} |
|
|
|
private void loadingSpeekVideo(){ |
|
|
|
Uri videoUri2 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.speek); |
|
|
|
binding.speekVideo.setVideoURI(videoUri2); |
|
|
|
binding.speekVideo.setVideoURI(videoMap.get("hat_speek")); |
|
|
|
binding.speekVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { |
|
|
|
@Override |
|
|
|
public void onPrepared(MediaPlayer mp) { |
|
|
|
@ -210,27 +240,167 @@ public class WebViewActivity extends BaseActivity { |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
//小红帽变 to
|
|
|
|
private void loadingToVideo(){ |
|
|
|
binding.toVideo.setVideoURI(videoMap.get("hat_to")); |
|
|
|
binding.toVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { |
|
|
|
@Override |
|
|
|
public void onPrepared(MediaPlayer mp) { |
|
|
|
binding.toVideo.start(); |
|
|
|
} |
|
|
|
}); |
|
|
|
binding.toVideo.setOnErrorListener(new MediaPlayer.OnErrorListener() { |
|
|
|
@Override |
|
|
|
public boolean onError(MediaPlayer mp, int what, int extra) { |
|
|
|
LoggerUtil.e("changeVideo: ","toVideo 播放失败"); |
|
|
|
return true; // 返回true表示已处理,不会弹出系统默认提示
|
|
|
|
} |
|
|
|
}); |
|
|
|
binding.toVideo.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { |
|
|
|
@Override |
|
|
|
public void onCompletion(MediaPlayer mp) { |
|
|
|
changeVideo("bg"); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
//小红帽回 back
|
|
|
|
private void loadingBackVideo(){ |
|
|
|
binding.backVideo.setVideoURI(videoMap.get("hat_back")); |
|
|
|
binding.backVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { |
|
|
|
@Override |
|
|
|
public void onPrepared(MediaPlayer mp) { |
|
|
|
binding.backVideo.start(); |
|
|
|
} |
|
|
|
}); |
|
|
|
binding.backVideo.setOnErrorListener(new MediaPlayer.OnErrorListener() { |
|
|
|
@Override |
|
|
|
public boolean onError(MediaPlayer mp, int what, int extra) { |
|
|
|
LoggerUtil.e("changeVideo: ","backVideo 播放失败"); |
|
|
|
return true; // 返回true表示已处理,不会弹出系统默认提示
|
|
|
|
} |
|
|
|
}); |
|
|
|
binding.backVideo.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { |
|
|
|
@Override |
|
|
|
public void onCompletion(MediaPlayer mp) { |
|
|
|
changeVideo("bg"); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
//彩蛋背景视频
|
|
|
|
private void loadingbgVideo1(){ |
|
|
|
binding.bgVideo1.setVideoURI(videoMap.get("hat_bg1")); |
|
|
|
binding.bgVideo1.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { |
|
|
|
@Override |
|
|
|
public void onPrepared(MediaPlayer mp) { |
|
|
|
mp.setLooping(true); // 可选:设置循环播
|
|
|
|
binding.bgVideo1.start(); |
|
|
|
} |
|
|
|
}); |
|
|
|
binding.bgVideo1.setOnErrorListener(new MediaPlayer.OnErrorListener() { |
|
|
|
@Override |
|
|
|
public boolean onError(MediaPlayer mp, int what, int extra) { |
|
|
|
LoggerUtil.e("changeVideo: ","backVideo 播放失败"); |
|
|
|
return true; // 返回true表示已处理,不会弹出系统默认提示
|
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
//彩蛋hello视频
|
|
|
|
private void loadingHelloVideo1(){ |
|
|
|
binding.helloVideo1.setVideoURI(videoMap.get("hat_hello1")); |
|
|
|
binding.helloVideo1.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { |
|
|
|
@Override |
|
|
|
public void onPrepared(MediaPlayer mp) { |
|
|
|
mp.setLooping(true); // 可选:设置循环播
|
|
|
|
binding.helloVideo1.start(); |
|
|
|
} |
|
|
|
}); |
|
|
|
binding.helloVideo1.setOnErrorListener(new MediaPlayer.OnErrorListener() { |
|
|
|
@Override |
|
|
|
public boolean onError(MediaPlayer mp, int what, int extra) { |
|
|
|
LoggerUtil.e("changeVideo: ","helloVideo1 播放失败"); |
|
|
|
return true; // 返回true表示已处理,不会弹出系统默认提示
|
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
//彩蛋Speek视频
|
|
|
|
private void loadingSpeekVideo1(){ |
|
|
|
binding.speekVideo1.setVideoURI(videoMap.get("hat_speek1")); |
|
|
|
binding.speekVideo1.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { |
|
|
|
@Override |
|
|
|
public void onPrepared(MediaPlayer mp) { |
|
|
|
mp.setLooping(true); |
|
|
|
binding.speekVideo1.start(); |
|
|
|
} |
|
|
|
}); |
|
|
|
binding.speekVideo1.setOnErrorListener(new MediaPlayer.OnErrorListener() { |
|
|
|
@Override |
|
|
|
public boolean onError(MediaPlayer mp, int what, int extra) { |
|
|
|
LoggerUtil.e("changeVideo: ","speekVideo1 播放失败"); |
|
|
|
return true; // 返回true表示已处理,不会弹出系统默认提示
|
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
//切换视频状态
|
|
|
|
private void changeVideoAfter(){ |
|
|
|
try{ |
|
|
|
if("".equals(videoAfter)){ //新状态正常
|
|
|
|
changeVideo("back"); |
|
|
|
}else{ //新状态彩蛋
|
|
|
|
changeVideo("to"); |
|
|
|
} |
|
|
|
}catch (Exception e){ |
|
|
|
LoggerUtil.e("ERROR: ",e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//切换视频
|
|
|
|
public void changeVideo(String type){ |
|
|
|
LoggerUtil.e("changeVideo", type); |
|
|
|
VideoView nextVideo; |
|
|
|
currentVideo.clearAnimation(); |
|
|
|
if("bg".equals(type.trim())){ |
|
|
|
if(currentVideo == binding.bgVideo){ |
|
|
|
return; |
|
|
|
} |
|
|
|
nextVideo = binding.bgVideo; |
|
|
|
}else if("answer".equals(type.trim())){ |
|
|
|
if(currentVideo == binding.speekVideo){ |
|
|
|
return; |
|
|
|
} |
|
|
|
nextVideo = binding.speekVideo; |
|
|
|
}else{ |
|
|
|
if(currentVideo == binding.helloVideo){ |
|
|
|
return; |
|
|
|
} |
|
|
|
nextVideo = binding.helloVideo; |
|
|
|
switch(type.trim()){ |
|
|
|
case "back" : |
|
|
|
if(currentVideo == binding.backVideo){ |
|
|
|
return; |
|
|
|
} |
|
|
|
nextVideo = binding.backVideo; |
|
|
|
break; |
|
|
|
case "to" : |
|
|
|
if(currentVideo == binding.toVideo){ |
|
|
|
return; |
|
|
|
} |
|
|
|
nextVideo = binding.toVideo; |
|
|
|
break; |
|
|
|
case "bg" : |
|
|
|
if(currentVideo == binding.bgVideo && "".equals(videoAfter)){ |
|
|
|
return; |
|
|
|
} |
|
|
|
if(currentVideo == binding.bgVideo1 && "1".equals(videoAfter)){ |
|
|
|
return; |
|
|
|
} |
|
|
|
nextVideo = "".equals(videoAfter) ? binding.bgVideo : binding.bgVideo1; |
|
|
|
break; |
|
|
|
case "answer" : |
|
|
|
if(currentVideo == binding.speekVideo && "".equals(videoAfter)){ |
|
|
|
return; |
|
|
|
} |
|
|
|
if(currentVideo == binding.speekVideo1 && "1".equals(videoAfter)){ |
|
|
|
return; |
|
|
|
} |
|
|
|
nextVideo = "".equals(videoAfter) ? binding.speekVideo : binding.speekVideo1; |
|
|
|
break; |
|
|
|
case "hello" : |
|
|
|
if(currentVideo == binding.helloVideo && "".equals(videoAfter)){ |
|
|
|
return; |
|
|
|
} |
|
|
|
if(currentVideo == binding.helloVideo1 && "1".equals(videoAfter)){ |
|
|
|
return; |
|
|
|
} |
|
|
|
nextVideo = "".equals(videoAfter) ? binding.helloVideo : binding.helloVideo1; |
|
|
|
break; |
|
|
|
default: |
|
|
|
nextVideo = "".equals(videoAfter) ? binding.bgVideo : binding.bgVideo1; |
|
|
|
} |
|
|
|
|
|
|
|
// 新视频淡入动画
|
|
|
|
@ -450,6 +620,18 @@ public class WebViewActivity extends BaseActivity { |
|
|
|
handler.removeMessages(TYPE_REFURBISH_WEBVIEW); |
|
|
|
handler.sendEmptyMessageDelayed(TYPE_REFURBISH_WEBVIEW,3000); |
|
|
|
} |
|
|
|
// h5调用android:彩蛋
|
|
|
|
@JavascriptInterface |
|
|
|
public void changeVideoState(String txt) { |
|
|
|
LoggerUtil.e(TAG,"JS调用了Android的方法:changeVideoState()"); |
|
|
|
videoAfter = txt; |
|
|
|
runOnUiThread(new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
changeVideoAfter(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
// h5调用android:开始识别语音
|
|
|
|
@JavascriptInterface |
|
|
|
public void startRecord() { |
|
|
|
|