【发布时间】:2018-09-05 07:04:52
【问题描述】:
我正在使用MediaRecorder 录制音频。而且,我想显示该录制过程的进度条。
我在记录器模板中的代码:
<p id="countdowntimer">Current Status: Beginning in<span id="countdown">10</span> seconds</p>
<progress ref="seekbar" value="0" max="1" id="progressbar"></progress>
我的功能:
mounted() {
let timeleft = 10;
const timeToStop = 20000;
const timeToStart = 1000;
const downloadTimer = setInterval(() => {
timeleft -= 1;
document.getElementById('countdown').textContent = timeleft;
if (timeleft <= 0) {
clearInterval(downloadTimer);
document.getElementById('countdowntimer').textContent = 'Current Status: Recording';
const that = this;
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia;
navigator.getUserMedia({ audio: true, video: false }, (stream) => {
that.stream = stream;
that.audioRecorder = new MediaRecorder(stream, {
mimeType: 'audio/webm;codecs=opus',
audioBitsPerSecond: 96000,
});
that.audioRecorder.ondataavailable = (event) => {
that.recordingData.push(event.data);
};
that.audioRecorder.onstop = () => {
const blob = new Blob(that.recordingData, { type: 'audio/ogg' });
that.dataUrl = window.URL.createObjectURL(blob);
// document.getElementById('audio').src = window.URL.createObjectURL(blob);
};
that.audioRecorder.start();
console.log('Media recorder started');
setTimeout(() => {
that.audioRecorder.stop();
document.getElementById('countdowntimer').textContent = 'Current Status: Stopped';
console.log('Stopped');
}, timeToStop);
}, (error) => {
console.log(JSON.stringify(error));
});
}
}, timeToStart);
}
对于我正在尝试做的进度条:
const progressbar = document.getElementById('progressbar');
progressbar.value = some value;
这里,我需要根据录制过程增加进度条..如何实现呢?
【问题讨论】:
-
我对您的代码有疑问:
-
@MátéWiszt progress 是和 html 标签! :)
-
@Margon:感谢您提供的信息,我从未使用过 :) 这里的重点是如何获得实际进度值。如果 Shrijana 可以将其保存在数据变量中,则可以为其创建一个观察者以始终更新进度条的值。
-
@MátéWiszt 我编辑了答案以完全匹配 shrijana 在理论上需要做的事情......顺便说一下,如果没有良好的 css 样式,请不要使用进度条,因为它很丑啊啊跨度>
标签: javascript vue.js progress-bar mediarecorder