How to play a video texture with audio?

How to play a video texture with audio?

Due to video policy this will need to start on a click or user interaction for calling the play() method. So in the option of the VideoTexture you will want to use autoPlay: false and mute: false

OK thanks xD

There is some way for the sound to come out from the object as in audio.attachToMesh (box) ?

1 Like

Not with the video texture, but i wonder if you could pass down the audio track of the video as a stream to the sound api

2 Likes

Stumbled onto that almost 3 years later, and got some code in case anyone has the same issue :
To extract the audio track from a video and make it spatial :

                          const audioContext = Engine.audioEngine?.audioContext;
                          if (!audioContext) {
                              return;
                          }

                          // video is the html <video> node in the DOM
                          const sourceNode = audioContext.createMediaElementSource(video);
                          const destinationNode = audioContext.createMediaStreamDestination();
                          sourceNode.connect(destinationNode);
                          const sound = new Sound('sound', destinationNode.stream, scene);

Hope it helps

3 Likes

You can also now directly create a Sound from a video element :slight_smile:

1 Like