[mirotalksfu] - improve volume indicator
هذا الالتزام موجود في:
@@ -457,33 +457,29 @@ th {
|
|||||||
# Settings - microphone volume indicator
|
# Settings - microphone volume indicator
|
||||||
--------------------------------------------------------------*/
|
--------------------------------------------------------------*/
|
||||||
|
|
||||||
#volumeContainer {
|
.volume-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-color: var(--body-bg);
|
background-color: var(--body-bg);
|
||||||
border-radius: 10px;
|
border-radius: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#volumeBar {
|
.volume-bar {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
height: 5px;
|
height: 5px;
|
||||||
background-color: #000000;
|
margin: 0 2px;
|
||||||
position: relative;
|
background-color: #ddd;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
#volumeLevel {
|
.active {
|
||||||
height: 100%;
|
background-color: #3498db;
|
||||||
background-color: #007bff;
|
|
||||||
border-radius: 5px;
|
|
||||||
transition: width 100ms ease-in-out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#volumeText {
|
.inactive {
|
||||||
margin-left: 10px;
|
background-color: #ddd;
|
||||||
font-weight: bold;
|
|
||||||
color: #333;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------
|
/*--------------------------------------------------------------
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ const _PEER = {
|
|||||||
sendVideo: '<i class="fab fa-youtube"></i>',
|
sendVideo: '<i class="fab fa-youtube"></i>',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const bars = document.querySelectorAll('.volume-bar');
|
||||||
|
|
||||||
const userAgent = navigator.userAgent.toLowerCase();
|
const userAgent = navigator.userAgent.toLowerCase();
|
||||||
const isTabletDevice = isTablet(userAgent);
|
const isTabletDevice = isTablet(userAgent);
|
||||||
const isIPadDevice = isIpad(userAgent);
|
const isIPadDevice = isIpad(userAgent);
|
||||||
@@ -404,8 +406,8 @@ function getMicrophoneVolumeIndicator(stream) {
|
|||||||
sum += inputBuffer[i] * inputBuffer[i];
|
sum += inputBuffer[i] * inputBuffer[i];
|
||||||
}
|
}
|
||||||
const rms = Math.sqrt(sum / inputBuffer.length);
|
const rms = Math.sqrt(sum / inputBuffer.length);
|
||||||
const volume = Math.max(0, Math.min(1, rms * 10)) * 100;
|
const volume = Math.max(0, Math.min(1, rms * 10));
|
||||||
if (volume > 1) updateVolumeIndicator(volume);
|
updateVolumeIndicator(volume);
|
||||||
};
|
};
|
||||||
microphone.connect(scriptProcessor);
|
microphone.connect(scriptProcessor);
|
||||||
scriptProcessor.connect(audioContext.destination);
|
scriptProcessor.connect(audioContext.destination);
|
||||||
@@ -416,17 +418,16 @@ function stopMicrophoneProcessing() {
|
|||||||
scriptProcessor.disconnect();
|
scriptProcessor.disconnect();
|
||||||
scriptProcessor = null;
|
scriptProcessor = null;
|
||||||
}
|
}
|
||||||
volumeLevel.style.width = '0%';
|
bars.forEach((bar) => {
|
||||||
//volumeText.textContent = '0%';
|
bar.classList.toggle('inactive');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateVolumeIndicator(volume) {
|
function updateVolumeIndicator(volume) {
|
||||||
const MIN_VOLUME = 0;
|
const activeBars = Math.ceil(volume * bars.length);
|
||||||
const MAX_VOLUME = 100;
|
bars.forEach((bar, index) => {
|
||||||
const clampedVolume = Math.min(MAX_VOLUME, Math.max(MIN_VOLUME, volume));
|
bar.classList.toggle('active', index < activeBars);
|
||||||
const volumePercentage = ((clampedVolume - MIN_VOLUME) / (MAX_VOLUME - MIN_VOLUME)) * 100;
|
});
|
||||||
volumeLevel.style.width = `${volumePercentage}%`;
|
|
||||||
//volumeText.textContent = `${clampedVolume.toFixed(0)}%`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ####################################################
|
// ####################################################
|
||||||
|
|||||||
@@ -321,11 +321,17 @@ access to use this app.
|
|||||||
</div>
|
</div>
|
||||||
<select id="microphoneSelect" class="form-select text-light bg-dark"></select>
|
<select id="microphoneSelect" class="form-select text-light bg-dark"></select>
|
||||||
<br />
|
<br />
|
||||||
<div id="volumeContainer">
|
<div class="volume-container">
|
||||||
<div id="volumeBar">
|
<div class="volume-bar"></div>
|
||||||
<div id="volumeLevel"></div>
|
<div class="volume-bar"></div>
|
||||||
</div>
|
<div class="volume-bar"></div>
|
||||||
<!-- <span id="volumeText">0%</span> -->
|
<div class="volume-bar"></div>
|
||||||
|
<div class="volume-bar"></div>
|
||||||
|
<div class="volume-bar"></div>
|
||||||
|
<div class="volume-bar"></div>
|
||||||
|
<div class="volume-bar"></div>
|
||||||
|
<div class="volume-bar"></div>
|
||||||
|
<div class="volume-bar"></div>
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
<div id="speakerSelectDiv">
|
<div id="speakerSelectDiv">
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم