codekraft-studio / vue-record

VueJs components for MediaRecorder API
https://codekraft-studio.github.io/vue-record/
MIT License
95 stars 57 forks source link

How to use it programmatically? #4

Closed supakornkim closed 4 years ago

supakornkim commented 4 years ago

Hello,

Is there a way to trigger to recording audio from JS code without pressing button by user?

Thank you.

b4dnewz commented 4 years ago

Hi, you can use refs to access the component and then call the exposed methods such as: start, stop, pause, resume

Unfortunately are still undocumented right now but you can see them in the source code

supakornkim commented 4 years ago

Hello,

I try .. but error <VueRecordAudio ref="voicerecord" @result="onResult" :mode="recMode" /> this.$refs.voicerecord.start() VM4033:37 [Vue warn]: Error in v-on handler: "TypeError: this.$refs.voicerecord.start is not a function"

but I use this and it works <VueRecordAudio id="voicerecord" @result="onResult" :mode="recMode" /> document.getElementById('voicerecord').dispatchEvent(new Event('mouseup'))

b4dnewz commented 4 years ago

Hi, this is really strange because the methods are defined, checkout this screenshot:

<vue-record-audio ref="Recorder" />
export default {
  mounted() {
    console.log(this.$refs.Recorder.start)
  }
}

image

Probably is something else in your code, If you copy n paste an extract of it, I try to help

supakornkim commented 4 years ago

Hello, ok. it is work now.

It does not work because I have multiple of components. So, when I make it to have only 1 component, start() and stop() now work!

Thank you so much

b4dnewz commented 4 years ago

It does not work because I have multiple of components. So, when I make it to have only 1 component, start() and stop() now work!

multiple vue-record components? if so, it sound like a bug to me, maybe I should check.. can you paste some of the code, i'm a little bit curious