I
I
Ibishka2020-02-26 20:00:46
JavaScript
Ibishka, 2020-02-26 20:00:46

How to stop background audio when playing video or audio in components?

There is a template in app vue that has a router-view for rendering other pages and there is an audio in the header, it needs to be stopped if another audio or video is played on the site. How to dynamically stop audio in menu if video or audio is playing?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2020-02-26
@Ibishka

Subscribe to the playing event, for example. (or choose the one that suits you best)
something like this:

document.addEventListener('playing', stopBackgroundAudio)

A
Alex, 2020-02-26
@Kozack

Read about eventbus.
The idea is this: in one component, you subscribe to an event, conditionally, somthing-playingand stop the audio on this event.
And in all other components, when you start an audio or video, you call this event.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question