|
|
@@ -223,6 +223,10 @@ const _sfc_main = {
|
|
|
// 添加新的数据属性
|
|
|
showPageDRWarning: false,
|
|
|
//多人提示
|
|
|
+ lastIOSDetectionTime: 0,
|
|
|
+ // iOS检测时间记录
|
|
|
+ isIOSPhotoCapturing: false,
|
|
|
+ // iOS拍照状态标记
|
|
|
followUpQuestion: "",
|
|
|
// 追问问题
|
|
|
followUpAudioUrl: "",
|
|
|
@@ -696,7 +700,7 @@ const _sfc_main = {
|
|
|
this.handleAudioEnd();
|
|
|
},
|
|
|
// 调用面试互动接口
|
|
|
- async callInterviewInteraction(jobPositionQuestionId, retryCount = 0, maxRetries = 3) {
|
|
|
+ async callInterviewInteraction(jobPositionQuestionId, retryCount = 0, maxRetries = 5) {
|
|
|
const userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
|
|
|
const appId = common_vendor.index.getStorageSync("appId");
|
|
|
const positionConfigId = JSON.parse(common_vendor.index.getStorageSync("configData")).id;
|
|
|
@@ -750,57 +754,6 @@ const _sfc_main = {
|
|
|
return false;
|
|
|
}
|
|
|
},
|
|
|
- // 播放追问音频
|
|
|
- async playFollowUpAudio() {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- console.log("开始播放追问音频, URL:", this.followUpAudioUrl);
|
|
|
- if (!this.followUpAudioUrl) {
|
|
|
- console.error("没有音频URL");
|
|
|
- reject(new Error("没有音频URL"));
|
|
|
- return;
|
|
|
- }
|
|
|
- common_vendor.index.showLoading({
|
|
|
- title: "思考中..."
|
|
|
- });
|
|
|
- this.stopAndDestroyAudio();
|
|
|
- try {
|
|
|
- const innerAudioContext = common_vendor.index.createInnerAudioContext();
|
|
|
- this.audioContext = innerAudioContext;
|
|
|
- innerAudioContext.autoplay = true;
|
|
|
- innerAudioContext.obeyMuteSwitch = false;
|
|
|
- innerAudioContext.volume = 1;
|
|
|
- innerAudioContext.onCanplay(() => {
|
|
|
- console.log("音频可以播放");
|
|
|
- common_vendor.index.hideLoading();
|
|
|
- this.isAudioPlaying = true;
|
|
|
- });
|
|
|
- innerAudioContext.onEnded(() => {
|
|
|
- console.log("追问音频播放完成");
|
|
|
- this.isAudioPlaying = false;
|
|
|
- resolve();
|
|
|
- setTimeout(() => {
|
|
|
- this.stopAndDestroyAudio();
|
|
|
- this.prepareToAnswer(true, this.currentFollowUpQuestion);
|
|
|
- }, 100);
|
|
|
- });
|
|
|
- innerAudioContext.onError((res) => {
|
|
|
- console.error("音频播放错误:", res);
|
|
|
- this.isAudioPlaying = false;
|
|
|
- common_vendor.index.hideLoading();
|
|
|
- reject(res);
|
|
|
- this.stopAndDestroyAudio();
|
|
|
- });
|
|
|
- console.log("设置音频源:", this.followUpAudioUrl);
|
|
|
- innerAudioContext.src = this.followUpAudioUrl;
|
|
|
- } catch (error) {
|
|
|
- console.error("创建或播放音频失败:", error);
|
|
|
- this.isAudioPlaying = false;
|
|
|
- common_vendor.index.hideLoading();
|
|
|
- this.stopAndDestroyAudio();
|
|
|
- reject(error);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
// 停止并销毁音频
|
|
|
stopAndDestroyAudio() {
|
|
|
if (!this.audioContext) {
|
|
|
@@ -822,25 +775,6 @@ const _sfc_main = {
|
|
|
}
|
|
|
this.isAudioPlaying = false;
|
|
|
},
|
|
|
- // 绑定音频事件
|
|
|
- bindAudioEvents(audioContext, resolve, reject) {
|
|
|
- audioContext.onCanplay(() => {
|
|
|
- console.log("音频可以播放");
|
|
|
- });
|
|
|
- audioContext.onTimeUpdate(() => {
|
|
|
- console.log("音频播放进度:", audioContext.currentTime);
|
|
|
- });
|
|
|
- audioContext.onEnded(() => {
|
|
|
- console.log("追问音频播放完成");
|
|
|
- this.cleanupAudioContext();
|
|
|
- resolve();
|
|
|
- });
|
|
|
- audioContext.onError((res) => {
|
|
|
- console.error("音频播放错误:", res);
|
|
|
- this.cleanupAudioContext();
|
|
|
- reject(res);
|
|
|
- });
|
|
|
- },
|
|
|
// 修改准备回答方法
|
|
|
prepareToAnswer(isFollowUp = false, questionData = null) {
|
|
|
this.isRecording = false;
|
|
|
@@ -1387,14 +1321,22 @@ const _sfc_main = {
|
|
|
console.log("开始录制用户回答");
|
|
|
this.isRecording = true;
|
|
|
this.lastFrameCaptureAt = 0;
|
|
|
+ this.lastIOSDetectionTime = 0;
|
|
|
try {
|
|
|
if (this.personDetectionSocket && this.personDetectionSocket.readyState === 1) {
|
|
|
- if (!this.hiddenCanvasReady) {
|
|
|
- this.initHiddenCanvasNode(false, 3);
|
|
|
+ const systemInfo2 = common_vendor.index.getSystemInfoSync();
|
|
|
+ const isIOS = systemInfo2.platform === "ios";
|
|
|
+ if (isIOS) {
|
|
|
+ console.log("iOS录制开始,使用特殊检测逻辑");
|
|
|
+ } else {
|
|
|
+ if (!this.hiddenCanvasReady) {
|
|
|
+ this.initHiddenCanvasNode(false, 3);
|
|
|
+ }
|
|
|
+ this.startFrameStreamCapture();
|
|
|
}
|
|
|
- this.startFrameStreamCapture();
|
|
|
}
|
|
|
} catch (e) {
|
|
|
+ console.warn("录制开始时的检测初始化失败:", e);
|
|
|
}
|
|
|
this.recordingStartTime = Date.now();
|
|
|
this.recordingTimerCount = 0;
|
|
|
@@ -1760,6 +1702,8 @@ const _sfc_main = {
|
|
|
this.showStopRecordingButton = false;
|
|
|
this.isRecording = false;
|
|
|
this.stopFrameStreamCapture();
|
|
|
+ this.isIOSPhotoCapturing = false;
|
|
|
+ this.lastIOSDetectionTime = 0;
|
|
|
const systemInfo = common_vendor.index.getSystemInfoSync();
|
|
|
const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
|
|
|
if (isMiniProgram) {
|
|
|
@@ -1804,18 +1748,45 @@ const _sfc_main = {
|
|
|
this.proceedToNextQuestion();
|
|
|
return;
|
|
|
}
|
|
|
+ let isCompleted = false;
|
|
|
+ const timeoutDuration = 1e4;
|
|
|
+ const timeoutId = setTimeout(() => {
|
|
|
+ if (!isCompleted) {
|
|
|
+ console.warn("停止录制超时,强制继续流程");
|
|
|
+ isCompleted = true;
|
|
|
+ this.proceedToNextQuestion();
|
|
|
+ }
|
|
|
+ }, timeoutDuration);
|
|
|
this.cameraContext.stopRecord({
|
|
|
success: async (res) => {
|
|
|
+ if (isCompleted) {
|
|
|
+ console.log("录制停止回调已超时,忽略结果");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ isCompleted = true;
|
|
|
+ clearTimeout(timeoutId);
|
|
|
console.log("小程序录制停止成功:", res);
|
|
|
const videoPath = res.tempVideoPath;
|
|
|
+ console.log("小程序录制停止成功:", videoPath);
|
|
|
if (videoPath) {
|
|
|
- await this.uploadRecordedVideo(videoPath);
|
|
|
+ try {
|
|
|
+ await this.uploadRecordedVideo(videoPath);
|
|
|
+ } catch (uploadError) {
|
|
|
+ console.error("上传视频失败:", uploadError);
|
|
|
+ this.proceedToNextQuestion();
|
|
|
+ }
|
|
|
} else {
|
|
|
console.error("未获取到录制视频路径");
|
|
|
this.proceedToNextQuestion();
|
|
|
}
|
|
|
},
|
|
|
fail: (err) => {
|
|
|
+ if (isCompleted) {
|
|
|
+ console.log("录制停止失败回调已超时,忽略错误");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ isCompleted = true;
|
|
|
+ clearTimeout(timeoutId);
|
|
|
console.error("小程序录制停止失败:", err);
|
|
|
this.proceedToNextQuestion();
|
|
|
}
|
|
|
@@ -1894,9 +1865,24 @@ const _sfc_main = {
|
|
|
this.startBackgroundUpload(uploadTask);
|
|
|
return Promise.resolve();
|
|
|
} else {
|
|
|
- return new Promise((resolve) => {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let isCompleted = false;
|
|
|
+ const uploadTimeoutDuration = 3e4;
|
|
|
+ const uploadTimeoutId = setTimeout(() => {
|
|
|
+ if (!isCompleted) {
|
|
|
+ console.warn("上传超时,强制继续流程");
|
|
|
+ isCompleted = true;
|
|
|
+ this.hideThinkingLoading();
|
|
|
+ resolve();
|
|
|
+ }
|
|
|
+ }, uploadTimeoutDuration);
|
|
|
const checkUploadStatus = () => {
|
|
|
+ if (isCompleted) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!this.isUploading && this.uploadQueue.length === 0) {
|
|
|
+ isCompleted = true;
|
|
|
+ clearTimeout(uploadTimeoutId);
|
|
|
this.handlePostUploadActions(uploadTask);
|
|
|
resolve();
|
|
|
} else {
|
|
|
@@ -3628,8 +3614,14 @@ const _sfc_main = {
|
|
|
console.warn("人脸检测:相机上下文或WebSocket连接未就绪");
|
|
|
return;
|
|
|
}
|
|
|
+ const systemInfo = common_vendor.index.getSystemInfoSync();
|
|
|
+ const isIOS = systemInfo.platform === "ios";
|
|
|
if (this.isRecording && this.useMiniProgramCameraComponent) {
|
|
|
- this.startFrameStreamCapture();
|
|
|
+ if (isIOS) {
|
|
|
+ this.handleIOSRecordingDetection();
|
|
|
+ } else {
|
|
|
+ this.startFrameStreamCapture();
|
|
|
+ }
|
|
|
} else {
|
|
|
this.stopFrameStreamCapture();
|
|
|
this.safeTakePhotoAndSend();
|
|
|
@@ -3639,6 +3631,90 @@ const _sfc_main = {
|
|
|
}
|
|
|
}, this.frameCaptureIntervalMs || 5e3);
|
|
|
},
|
|
|
+ // 新增方法:处理iOS端录制时的检测逻辑
|
|
|
+ handleIOSRecordingDetection() {
|
|
|
+ if (!this.isRecording) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!this.personDetectionSocket || this.personDetectionSocket.readyState !== 1) {
|
|
|
+ console.warn("iOS录制检测:WebSocket连接未就绪");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!this.cameraContext) {
|
|
|
+ console.warn("iOS录制检测:相机上下文不存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const now = Date.now();
|
|
|
+ if (this.lastIOSDetectionTime && now - this.lastIOSDetectionTime < 5e3) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.lastIOSDetectionTime = now;
|
|
|
+ try {
|
|
|
+ if (this.hiddenCanvasReady) {
|
|
|
+ this.startFrameStreamCapture();
|
|
|
+ } else {
|
|
|
+ this.safeTakePhotoForIOSRecording();
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.warn("iOS录制检测出错,但不影响录制:", error);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 新增方法:iOS录制期间的安全拍照
|
|
|
+ safeTakePhotoForIOSRecording() {
|
|
|
+ if (this.isIOSPhotoCapturing) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.isIOSPhotoCapturing = true;
|
|
|
+ try {
|
|
|
+ this.cameraContext.takePhoto({
|
|
|
+ quality: "low",
|
|
|
+ success: (res) => {
|
|
|
+ const tempFilePath = res && res.tempImagePath;
|
|
|
+ if (!tempFilePath) {
|
|
|
+ this.isIOSPhotoCapturing = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ setTimeout(() => {
|
|
|
+ common_vendor.index.getFileSystemManager().readFile({
|
|
|
+ filePath: tempFilePath,
|
|
|
+ encoding: "base64",
|
|
|
+ success: (r) => {
|
|
|
+ try {
|
|
|
+ const base64Image = r.data;
|
|
|
+ if (this.personDetectionSocket && this.personDetectionSocket.readyState === 1) {
|
|
|
+ this.personDetectionSocket.send({
|
|
|
+ data: JSON.stringify({
|
|
|
+ type: "person_detection",
|
|
|
+ image_data: base64Image,
|
|
|
+ platform: "ios_recording"
|
|
|
+ // 标记为iOS录制期间的检测
|
|
|
+ })
|
|
|
+ });
|
|
|
+ console.log("iOS录制期间检测图片已发送");
|
|
|
+ }
|
|
|
+ } catch (sendError) {
|
|
|
+ console.warn("iOS录制期间发送检测图片失败:", sendError);
|
|
|
+ } finally {
|
|
|
+ this.isIOSPhotoCapturing = false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (readError) => {
|
|
|
+ console.warn("iOS录制期间读取图片文件失败:", readError);
|
|
|
+ this.isIOSPhotoCapturing = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }, 100);
|
|
|
+ },
|
|
|
+ fail: (photoError) => {
|
|
|
+ console.warn("iOS录制期间拍照失败:", photoError);
|
|
|
+ this.isIOSPhotoCapturing = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ console.warn("iOS录制期间拍照异常:", error);
|
|
|
+ this.isIOSPhotoCapturing = false;
|
|
|
+ }
|
|
|
+ },
|
|
|
cleanupPersonDetectionWebSocket() {
|
|
|
if (this.personDetectionInterval) {
|
|
|
clearInterval(this.personDetectionInterval);
|
|
|
@@ -3763,38 +3839,17 @@ const _sfc_main = {
|
|
|
});
|
|
|
this.stopAndDestroyAudio();
|
|
|
try {
|
|
|
- const innerAudioContext = common_vendor.index.createInnerAudioContext();
|
|
|
- this.audioContext = innerAudioContext;
|
|
|
- innerAudioContext.autoplay = true;
|
|
|
- innerAudioContext.obeyMuteSwitch = false;
|
|
|
- innerAudioContext.volume = 1;
|
|
|
- innerAudioContext.onCanplay(() => {
|
|
|
- console.log("音频可以播放");
|
|
|
- common_vendor.index.hideLoading();
|
|
|
- this.isAudioPlaying = true;
|
|
|
- });
|
|
|
- innerAudioContext.onEnded(() => {
|
|
|
- console.log("追问音频播放完成");
|
|
|
- this.isAudioPlaying = false;
|
|
|
- resolve();
|
|
|
- setTimeout(() => {
|
|
|
- this.stopAndDestroyAudio();
|
|
|
- this.prepareToAnswer(true, this.currentFollowUpQuestion);
|
|
|
- }, 100);
|
|
|
- });
|
|
|
- innerAudioContext.onError((res) => {
|
|
|
- console.error("音频播放错误:", res);
|
|
|
- this.isAudioPlaying = false;
|
|
|
- common_vendor.index.hideLoading();
|
|
|
- common_vendor.index.showToast({
|
|
|
- title: "音频播放失败",
|
|
|
- icon: "none"
|
|
|
- });
|
|
|
- reject(res);
|
|
|
- this.stopAndDestroyAudio();
|
|
|
- });
|
|
|
- console.log("设置音频源:", this.followUpAudioUrl);
|
|
|
- innerAudioContext.src = this.followUpAudioUrl;
|
|
|
+ const systemInfo = common_vendor.index.getSystemInfoSync();
|
|
|
+ const isIOS = systemInfo.platform === "ios";
|
|
|
+ const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
|
|
|
+ console.log("平台信息:", { isIOS, isMiniProgram, platform: systemInfo.platform });
|
|
|
+ if (isMiniProgram && isIOS) {
|
|
|
+ this.playIOSMiniProgramFollowUpAudio(resolve, reject);
|
|
|
+ } else if (isIOS) {
|
|
|
+ this.playIOSFollowUpAudio(resolve, reject);
|
|
|
+ } else {
|
|
|
+ this.playGeneralFollowUpAudio(resolve, reject);
|
|
|
+ }
|
|
|
} catch (error) {
|
|
|
console.error("创建或播放音频失败:", error);
|
|
|
this.isAudioPlaying = false;
|
|
|
@@ -3808,6 +3863,208 @@ const _sfc_main = {
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
+ // iOS小程序专用音频播放方法
|
|
|
+ playIOSMiniProgramFollowUpAudio(resolve, reject) {
|
|
|
+ try {
|
|
|
+ const bgAudio = common_vendor.index.getBackgroundAudioManager();
|
|
|
+ bgAudio.title = "追问语音";
|
|
|
+ bgAudio.epname = "Follow Up Question";
|
|
|
+ bgAudio.singer = "Interviewer";
|
|
|
+ bgAudio.onCanplay(() => {
|
|
|
+ try {
|
|
|
+ bgAudio.play();
|
|
|
+ } catch (e) {
|
|
|
+ console.warn("iOS小程序调用 play 失败,稍后重试", e);
|
|
|
+ setTimeout(() => {
|
|
|
+ try {
|
|
|
+ bgAudio.play();
|
|
|
+ } catch (_) {
|
|
|
+ }
|
|
|
+ }, 50);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ bgAudio.onPlay(() => {
|
|
|
+ console.log("iOS小程序追问音频开始播放");
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ this.isAudioPlaying = true;
|
|
|
+ });
|
|
|
+ bgAudio.onEnded(() => {
|
|
|
+ console.log("iOS小程序追问音频播放完成");
|
|
|
+ this.isAudioPlaying = false;
|
|
|
+ try {
|
|
|
+ bgAudio.stop();
|
|
|
+ } catch (_) {
|
|
|
+ }
|
|
|
+ resolve();
|
|
|
+ setTimeout(() => {
|
|
|
+ this.stopAndDestroyAudio();
|
|
|
+ this.prepareToAnswer(true, this.currentFollowUpQuestion);
|
|
|
+ }, 100);
|
|
|
+ });
|
|
|
+ bgAudio.onError((err) => {
|
|
|
+ console.error("iOS小程序追问音频播放错误:", err);
|
|
|
+ this.isAudioPlaying = false;
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ try {
|
|
|
+ bgAudio.stop();
|
|
|
+ } catch (_) {
|
|
|
+ }
|
|
|
+ this.fallbackIOSFollowUpAudio(resolve, reject);
|
|
|
+ });
|
|
|
+ bgAudio.autoplay = true;
|
|
|
+ bgAudio.src = this.followUpAudioUrl;
|
|
|
+ } catch (error) {
|
|
|
+ console.error("iOS小程序音频播放失败:", error);
|
|
|
+ this.fallbackIOSFollowUpAudio(resolve, reject);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // iOS App/H5专用音频播放方法
|
|
|
+ playIOSFollowUpAudio(resolve, reject) {
|
|
|
+ try {
|
|
|
+ this.audioContext = common_vendor.index.createInnerAudioContext();
|
|
|
+ this.audioContext.autoplay = true;
|
|
|
+ this.audioContext.obeyMuteSwitch = false;
|
|
|
+ this.audioContext.volume = 1;
|
|
|
+ this.audioContext.src = this.followUpAudioUrl;
|
|
|
+ this.audioContext.onPlay(() => {
|
|
|
+ console.log("iOS追问音频开始播放");
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ this.isAudioPlaying = true;
|
|
|
+ });
|
|
|
+ this.audioContext.onEnded(() => {
|
|
|
+ console.log("iOS追问音频播放完成");
|
|
|
+ this.isAudioPlaying = false;
|
|
|
+ resolve();
|
|
|
+ setTimeout(() => {
|
|
|
+ this.stopAndDestroyAudio();
|
|
|
+ this.prepareToAnswer(true, this.currentFollowUpQuestion);
|
|
|
+ }, 100);
|
|
|
+ });
|
|
|
+ this.audioContext.onError((err) => {
|
|
|
+ console.error("iOS追问音频播放错误:", err);
|
|
|
+ this.isAudioPlaying = false;
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ this.fallbackIOSFollowUpAudio(resolve, reject);
|
|
|
+ });
|
|
|
+ this.audioContext.onWaiting(() => {
|
|
|
+ console.log("iOS追问音频加载中...");
|
|
|
+ });
|
|
|
+ this.audioContext.onCanplay(() => {
|
|
|
+ console.log("iOS追问音频准备就绪");
|
|
|
+ });
|
|
|
+ setTimeout(() => {
|
|
|
+ if (this.isAudioPlaying && this.audioContext) {
|
|
|
+ console.log("iOS追问音频播放超时,尝试备选方案");
|
|
|
+ this.fallbackIOSFollowUpAudio(resolve, reject);
|
|
|
+ }
|
|
|
+ }, 1e4);
|
|
|
+ } catch (error) {
|
|
|
+ console.error("创建iOS追问音频播放器失败:", error);
|
|
|
+ this.fallbackIOSFollowUpAudio(resolve, reject);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // iOS备选音频播放方案
|
|
|
+ fallbackIOSFollowUpAudio(resolve, reject) {
|
|
|
+ console.log("iOS追问音频备选播放方案");
|
|
|
+ try {
|
|
|
+ this.stopAndDestroyAudio();
|
|
|
+ this.audioContext = common_vendor.index.createInnerAudioContext();
|
|
|
+ this.audioContext.autoplay = true;
|
|
|
+ this.audioContext.obeyMuteSwitch = true;
|
|
|
+ this.audioContext.volume = 0.8;
|
|
|
+ this.audioContext.src = this.followUpAudioUrl;
|
|
|
+ this.audioContext.onPlay(() => {
|
|
|
+ console.log("iOS备选方案:追问音频开始播放");
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ this.isAudioPlaying = true;
|
|
|
+ });
|
|
|
+ this.audioContext.onEnded(() => {
|
|
|
+ console.log("iOS备选方案:追问音频播放结束");
|
|
|
+ this.isAudioPlaying = false;
|
|
|
+ resolve();
|
|
|
+ setTimeout(() => {
|
|
|
+ this.stopAndDestroyAudio();
|
|
|
+ this.prepareToAnswer(true, this.currentFollowUpQuestion);
|
|
|
+ }, 100);
|
|
|
+ });
|
|
|
+ this.audioContext.onError((err) => {
|
|
|
+ console.error("iOS备选方案:追问音频播放错误:", err);
|
|
|
+ this.useIOSFollowUpTextFallback(resolve, reject);
|
|
|
+ });
|
|
|
+ setTimeout(() => {
|
|
|
+ if (this.isAudioPlaying && this.audioContext) {
|
|
|
+ console.log("iOS追问音频播放超时,使用文本回退");
|
|
|
+ this.useIOSFollowUpTextFallback(resolve, reject);
|
|
|
+ }
|
|
|
+ }, 5e3);
|
|
|
+ } catch (e) {
|
|
|
+ console.error("iOS备选追问音频播放失败:", e);
|
|
|
+ this.useIOSFollowUpTextFallback(resolve, reject);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // iOS文本回退方案
|
|
|
+ useIOSFollowUpTextFallback(resolve, reject) {
|
|
|
+ console.log("iOS追问音频使用文本回退方案");
|
|
|
+ this.isAudioPlaying = false;
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "音频播放失败,请查看文字问题",
|
|
|
+ icon: "none",
|
|
|
+ duration: 3e3
|
|
|
+ });
|
|
|
+ resolve();
|
|
|
+ setTimeout(() => {
|
|
|
+ this.stopAndDestroyAudio();
|
|
|
+ this.prepareToAnswer(true, this.currentFollowUpQuestion);
|
|
|
+ }, 100);
|
|
|
+ },
|
|
|
+ // 通用音频播放方法(非iOS平台)
|
|
|
+ playGeneralFollowUpAudio(resolve, reject) {
|
|
|
+ try {
|
|
|
+ const innerAudioContext = common_vendor.index.createInnerAudioContext();
|
|
|
+ this.audioContext = innerAudioContext;
|
|
|
+ innerAudioContext.autoplay = true;
|
|
|
+ innerAudioContext.obeyMuteSwitch = false;
|
|
|
+ innerAudioContext.volume = 1;
|
|
|
+ innerAudioContext.onCanplay(() => {
|
|
|
+ console.log("音频可以播放");
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ this.isAudioPlaying = true;
|
|
|
+ });
|
|
|
+ innerAudioContext.onEnded(() => {
|
|
|
+ console.log("追问音频播放完成");
|
|
|
+ this.isAudioPlaying = false;
|
|
|
+ resolve();
|
|
|
+ setTimeout(() => {
|
|
|
+ this.stopAndDestroyAudio();
|
|
|
+ this.prepareToAnswer(true, this.currentFollowUpQuestion);
|
|
|
+ }, 100);
|
|
|
+ });
|
|
|
+ innerAudioContext.onError((res) => {
|
|
|
+ console.error("音频播放错误:", res);
|
|
|
+ this.isAudioPlaying = false;
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "音频播放失败",
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ reject(res);
|
|
|
+ this.stopAndDestroyAudio();
|
|
|
+ });
|
|
|
+ console.log("设置音频源:", this.followUpAudioUrl);
|
|
|
+ innerAudioContext.src = this.followUpAudioUrl;
|
|
|
+ } catch (error) {
|
|
|
+ console.error("创建或播放音频失败:", error);
|
|
|
+ this.isAudioPlaying = false;
|
|
|
+ common_vendor.index.hideLoading();
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "音频播放失败",
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
+ this.stopAndDestroyAudio();
|
|
|
+ reject(error);
|
|
|
+ }
|
|
|
+ },
|
|
|
// 停止并销毁音频
|
|
|
stopAndDestroyAudio() {
|
|
|
if (!this.audioContext) {
|