Commit 15ab7cd6 by 李宁

1

1 parent 75d6ec4d
......@@ -115,7 +115,7 @@
</div>
</div>
<!-- <audio id="mp3Source" muted playsinline src=""></audio> -->
<audio id="mp3Source" muted playsinline src=""></audio>
<div class="alertDiv" id="accountAlertDiv">
<div class="inner">
......@@ -373,7 +373,7 @@
<script src="js/util.js?1212"></script>
<script src="js/vue.min.js"></script>
<script src="js/vant.min.js"></script>
<script src="js/demo.js?1203334330"></script>
<script src="js/demo.js?272721319"></script>
</body>
</html>
\ No newline at end of file
......@@ -275,7 +275,7 @@ function getProcess(){
// $("#mp3Source")[0].play()
// },350)
let buff = await loadPrompt(res.voiceUrlMp3); // 先解码
let buff = await loadPrompt(res.voiceUrlMp3);
playPrompt(buff);
}
audioSet(false)
......@@ -383,7 +383,7 @@ function audioStart(){
}
})
}
function audioEnd(){
function audioEnd(ifEnd){
util.httpRequest({
url: '/startOrEnd',
data: {
......@@ -394,7 +394,7 @@ function audioEnd(){
}
})
if(stepId.includes('end')){
if(ifEnd){
free()
window.location.replace('result.html?time='+ new Date().getTime())
......@@ -419,14 +419,13 @@ async function startWebAudioChain() {
/* 2. 加载「真实提示音」→ 音量压到 0.0001 → loop 永驻 */
// ① 先加载同一条提示音(已缓存
const buf = await loadPrompt('https://zjaudio.eos-wuxi-5.cmecloud.cn/IqiVe4GU.mp3');
// ② 创建 BufferSource
let shadowBufNode = mainCtx.createBufferSource();
shadowBufNode.buffer = buf;
shadowBufNode.loop = true;
const shadowGain = mainCtx.createGain();
shadowGain.gain.value = 0.0001; // 用户听不见,但系统认为“有声音”
shadowGain.gain.value = 0.0001;
shadowBufNode.connect(shadowGain).connect(mainCtx.destination);
shadowBufNode.start(); // 永不 stop
shadowBufNode.start();
/* 3. 送回 LiveKit */
const dest = mainCtx.createMediaStreamDestination();
......@@ -451,27 +450,32 @@ async function loadPrompt(url) {
return promptBuffer
}
let currentSource = null;
function playPrompt(buffer) {
async function playPrompt(buffer) {
if (!mainCtx) return;
// 1. 停掉上一条
if (currentSource) {
try { currentSource.stop(); } catch (e) { }
try { currentSource.stop(); } catch {}
currentSource = null;
setTimeout(()=>{
playPrompt(buffer)
},300)
return
}
// 2. 创建新节点
const src = mainCtx.createBufferSource();
src.buffer = buffer;
src.connect(mainCtx.destination);
src.start();
currentSource = mainCtx.createBufferSource();
currentSource.buffer = buffer;
currentSource.connect(mainCtx.destination);
currentSource.start(0);
audioStart()
// 3. 记录引用
currentSource = src;
// 4. 播放完毕自动清空
src.onended = () => {
let ifEnd = stepId.includes('end')
currentSource.onended = () => {
currentSource = null;
audioEnd()
audioEnd(ifEnd)
};
}
//---------音频播放新逻辑---------
......@@ -1095,12 +1099,10 @@ async function setEnabled(type, state) {
//声网的入会逻辑
async function initSw(data){
createClient()
options.channel = data.data.data.channel
options.uid = data.data.data.uid
options.token = data.data.data.token
let flag = await join()
if(!flag){
$('#loading').hide()
util.toast('加入频道失败')
......@@ -1111,7 +1113,7 @@ async function initSw(data){
await createTrackAndPublish()
}
//livekit的入会逻辑
async function initLk(){
async function initLk(data){
// 创建房间实例,启用自适应流和动态发布
room = new LivekitClient.Room({
adaptiveStream: true,
......@@ -1157,28 +1159,14 @@ var room = null
var rtcType = ''
var startZjFlag = true
async function init(){
$('#loadingText').text('开启中,请稍候...')
$('#loading').show()
setTimeout(()=>{
if(startZjFlag){
$('#loading').hide()
$('#beginFail').show()
}
},20000)
snInputNum = window.snInputNum||5
noShootNum = window.noShootNum||3
accountInputNum = window.accountInputNum||5
// $("#mp3Source").attr('src', 'https://lgyztest.obs.cidc-rp-12.joint.cmecloud.cn/file/temp/2025-01-08/hhT2XXAj.mp3')
// $("#mp3Source")[0].autoplay = true
// $("#mp3Source")[0].play()
let data = await util.httpRequest({
url: '/createRoom',
data: {
applyId: applyId,
rtcType: '2'
applyId: applyId
}
})
......@@ -1192,7 +1180,7 @@ async function init(){
sessionStorage.setItem('haCallId',callId)
rtcType = data.data.data.rtcType
if(data.data.data.rtcType == 1){
if(rtcType == 1){
await initSw(data)
}else{
await initLk(data)
......@@ -1269,9 +1257,18 @@ $('#videoBegin').click(async ()=>{
}
$('#beginAlert').hide()
$('#loadingText').text('开启中,请稍候...')
$('#loading').show()
setTimeout(()=>{
if(startZjFlag){
$('#loading').hide()
$('#beginFail').show()
}
},20000)
mainCtx = new (window.AudioContext || window.webkitAudioContext)({
latencyHint: 'interactive'
latencyHint: 'interactive',
sinkId: 'default'
});
if (mainCtx.state === 'suspended') await mainCtx.resume();
......@@ -1281,6 +1278,10 @@ $('#videoBegin').click(async ()=>{
await startWebAudioChain()
// $("#mp3Source").attr('src', 'https://lgyztest.obs.cidc-rp-12.joint.cmecloud.cn/file/temp/2025-01-08/hhT2XXAj.mp3')
// $("#mp3Source")[0].autoplay = true
// $("#mp3Source")[0].play()
init()
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!