vue-audio-visual icon indicating copy to clipboard operation
vue-audio-visual copied to clipboard

Can I programmatically play audio?

Open mikethewolf83 opened this issue 3 years ago • 6 comments

Can I programmatically play audio? I mean by function instead by the controls? For example, I hide controls with:

:audio-controls="false"

The lets say by means of a function y play audio...can be done?

Thanks

mikethewolf83 avatar Oct 21 '21 19:10 mikethewolf83

You can have external element and use direct audio javascript API to play/pause. See "ref-link" in the documentation

staskobzar avatar Oct 21 '21 19:10 staskobzar

How you will do that?

ChileNetwork avatar Feb 18 '22 20:02 ChileNetwork

Thanks, that also works for changing the current audio time!

<audio
  :src="blobUrl + '#t=00:03:26'"
  controls
  ref="foo"
  preload="auto"
></audio>
<av-waveform
  ref-link="foo"
  :canv-width="500"
  :canv-height="120"
  :playtime-line-width="0.8"
  :playtime-with-ms="false"
></av-waveform>

titushartm avatar Apr 18 '22 13:04 titushartm

Hello !

Since ref-link isn't working on my side, I've found a solution, use the the .audio object of your <av-... /> tag eg :

<av-waveform
  ref="channel1"
  
  canv-class="full-width"
  :canv-height="25"
  
  audio-src="songs/andale.mp3"
  :audio-controls="false"
  :playtime="false"
  />
this.$refs.channel1.audio.play()
this.$refs.channel1.audio.pause()

Julien-cpsn avatar Oct 15 '22 19:10 Julien-cpsn

vue3 JSON.parse(JSON.stringify(currentInstance.ctx.$refs. channel1)) Audio. play() not found

loneyao avatar Feb 28 '23 02:02 loneyao

try this one:

watch(
  // pretend you have a getData getter in store
  () => audioStore.playing,
  (oldVal) => {
    // if playing = true
    if (oldVal) {
      // set time of audio element
      audioRef.value.play();
    } else {
      //else false
      audioRef.value.pause();
    }
  }
);

got the original idea from here: https://stackoverflow.com/questions/67775761/vue3-composition-api-watch-store-value

titushartm avatar Feb 28 '23 06:02 titushartm