Add random ID for each record

This commit is contained in:
Gennady Grishkovtsov
2018-09-30 15:48:57 +03:00
parent 83ccce2374
commit 860f7e6158

View File

@@ -23,7 +23,7 @@ export default class {
navigator.mediaDevices.getUserMedia({audio: true}) navigator.mediaDevices.getUserMedia({audio: true})
.then(this._micCaptured.bind(this)) .then(this._micCaptured.bind(this))
.catch(this._micError.bind(this)) .catch(this._micError.bind(this))
this.isPause = false this.isPause = false
this.isRecording = true this.isRecording = true
} }
@@ -34,26 +34,28 @@ export default class {
this.context.close() this.context.close()
let encoder = new WavEncoder({ let encoder = new WavEncoder({
bufferSize: this.bufferSize, bufferSize : this.bufferSize,
sampleRate: this.context.sampleRate, sampleRate : this.context.sampleRate,
samples: this.samples samples : this.samples
}) })
let audioBlob = encoder.getData() let audioBlob = encoder.getData()
let audioUrl = URL.createObjectURL(audioBlob) let audioUrl = URL.createObjectURL(audioBlob)
this.samples = [] this.samples = []
this.records.push({ this.records.push({
blob: audioBlob, id : Date.now(),
url: audioUrl, blob : audioBlob,
duration: convertTimeMMSS(this.duration) duration : convertTimeMMSS(this.duration),
url : audioUrl
}) })
this.isPause = false
this.isRecording = false
this._duration = 0 this._duration = 0
this.duration = 0 this.duration = 0
this.isPause = false
this.isRecording = false
if (this.afterStop) { if (this.afterStop) {
this.afterStop() this.afterStop()
@@ -79,11 +81,11 @@ export default class {
} }
_micCaptured (stream) { _micCaptured (stream) {
this.context = new(window.AudioContext || window.webkitAudioContext)() this.context = new(window.AudioContext || window.webkitAudioContext)()
this.input = this.context.createMediaStreamSource(stream) this.duration = this._duration
this.processor = this.context.createScriptProcessor(this.bufferSize, 1, 1) this.input = this.context.createMediaStreamSource(stream)
this.duration = this._duration this.processor = this.context.createScriptProcessor(this.bufferSize, 1, 1)
this.stream = stream this.stream = stream
this.processor.onaudioprocess = (ev) => { this.processor.onaudioprocess = (ev) => {
let sample = ev.inputBuffer.getChannelData(0) let sample = ev.inputBuffer.getChannelData(0)