视频采集卡-采集音频

main
ysn 5 days ago
parent d16546ea10
commit 8456e0bb71
  1. 34
      src/views/videoCommunication/realTimeConsultation.vue

@ -623,7 +623,6 @@ export default {
// ==================== 4 ==================== // ==================== 4 ====================
async switchCaptureCard(deviceId) { async switchCaptureCard(deviceId) {
// 1.
if (this.captureCheckTimer) clearTimeout(this.captureCheckTimer); if (this.captureCheckTimer) clearTimeout(this.captureCheckTimer);
this.closeCaptureCard(); this.closeCaptureCard();
@ -637,8 +636,6 @@ export default {
await this.$nextTick(); await this.$nextTick();
const videoEl = this.$refs.shareVideo; const videoEl = this.$refs.shareVideo;
// 2. Video CSS
// Video
if (videoEl) { if (videoEl) {
videoEl.srcObject = null; videoEl.srcObject = null;
videoEl.load(); videoEl.load();
@ -646,51 +643,38 @@ export default {
videoEl.style.height = "100%"; videoEl.style.height = "100%";
videoEl.style.objectFit = "contain"; videoEl.style.objectFit = "contain";
videoEl.style.background = "#000"; videoEl.style.background = "#000";
videoEl.muted = false; // videoEl.muted = false;
videoEl.volume = 1; //
} }
try { try {
console.log("正在执行最终修复方案:强制30帧 + 无分辨率限制...");
// 3.
const stream = await navigator.mediaDevices.getUserMedia({ const stream = await navigator.mediaDevices.getUserMedia({
video: { video: {
deviceId: { exact: deviceId }, deviceId: { exact: deviceId },
// A 30绿 USB 2.0 线
frameRate: { exact: 30 }, frameRate: { exact: 30 },
// B MJPEG USB 2.0
advanced: [{ chromegfx: "mjpeg" }], advanced: [{ chromegfx: "mjpeg" }],
// width/height 640x480
}, },
audio: true, audio: true,
}); });
console.log( //
"采集成功!实际设置:", stream.getAudioTracks().forEach((track) => (track.enabled = true));
stream.getVideoTracks()[0].getSettings()
);
// 4.
if (videoEl) { if (videoEl) {
videoEl.srcObject = stream; videoEl.srcObject = stream;
// C
const playPromise = videoEl.play(); const playPromise = videoEl.play();
if (playPromise !== undefined) { if (playPromise !== undefined) {
playPromise playPromise
.then(() => { .then(() => {
console.log("视频播放成功启动"); console.log("采集卡音视频播放成功");
this.$message.success("采集卡已连接 (强制30帧/MJPEG)"); this.$message.success("采集卡已连接(带声音)");
}) })
.catch((error) => { .catch((err) => {});
console.error("自动播放被拦截:", error);
this.$message.error("播放被拦截,请尝试点击页面任意位置");
});
} }
} }
} catch (err) { } catch (err) {
console.error("最终方案失败:", err); console.error("采集卡失败", err);
this.$message.error("连接失败: " + err.message); this.$message.error("采集卡失败:" + err.message);
this.isSharing = false; this.isSharing = false;
} }
}, },

Loading…
Cancel
Save