A
A
Alexander2020-05-20 10:05:04
Vue.js
Alexander, 2020-05-20 10:05:04

Why doesn't audioTrack.pause() work in vuejs?

Wrote this code:

methods: {
    startAudio (audio) {
      let audioTrack = new Audio(audio)
      if (this.isTargeted === false) {
        audioTrack.play()
        this.isTargeted = true
      } else {
        audioTrack.pause()
        audioTrack.currentTime = 0
        this.isTargeted = false
      }
    }
  }


I work with the function like this:
v-on:click="startAudio( attachment.audio.audio )"

The audio file starts but when I click again to stop the music, it does not stop.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-05-20
@AlexVue

when I press again to stop the music, it does not stop

Each time the startAudio method is called, a new object is created, play on one, and pause on the other. It is necessary to save the created audio between calls to startAudio.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question