Back to the Shapespark home page

Video texture doesn't play sound

Hi.

I have a video texture lying on a hidden surface. My wish is that when I use a trigger to enable the view which unhides the surface the movie starts playing. It does, but unfortunately without any sound. Is this on purpose?

The videos play without sound by default and you need to use the Video Texture Control extension to change this. If you configure the extension without a trigger, it will just enable sound for the video. In your case I’m afraid that the video is playing even when it is hidden, so if you configure it to play with sound, the sound will be playing immediately after the scene is loaded, not when the hidden surface is shown.

That’s a problem then. Is the a way to solve this?
I need to create a virtual assistant which starts when I enable a trigger. It should appear when I start a trigger. Actually, I would go with a start-stop trigger. But because transparency is not possible in video files, even if the transparency is at the beginning of a file, I cannot use this solution.
Maybe there is another way to solve this? By programming a trigger?

With API you can get notifications when a view is entered (see View switch in this doc.

You can achieve what you need with the following body-end.html file (you need to replace YOUR-MATERIAL-NAME with the name of the material with video, and YOUR-VIEW-NAME with the name of the view where the video should play):

<script>

(function() {
  var viewer = WALK.getViewer();

  viewer.onViewSwitchDone(function(viewName) {
    var videoTexture = viewer.findMaterial('YOUR-METARIAL-NAME').baseColorTexture;
    videoTexture.video.addEventListener('ended', function() {
     viewer.switchToView('YOUR-VIEW-NAME-WHERE-ASISTANT-IS-HIDDEN', 0, true);
    });
    if (viewName === 'YOUR-VIEW-NAME-WHERE-ASISTANT-IS-VISIBLE') {
      videoTexture.isPlaying = true;
      videoTexture.video.muted = false;
      videoTexture.video.loop = false;
    } else {
      videoTexture.isPlaying = false;
    }
  });
}());

</script>
1 Like

Thank you @jan

Is it also possible this way to switch to another view after the movie stopped playing? This way I would start the movie (enabling the view with the hidden plane) incl. sound. After the movie ran in full length it stops (I saw there is an API for his) and switches to another view (hiding the plane with the movie texture again)?

You need to use a browser API to detect when a video stops playing. Browsers expose ‘ended’ event of a video element for this. I’ve updated the code above.

Looks interesting. I will test it.

Thank you @jan Jan, for the superb support here in the forum!

Unfortunately, this is not working. The plane appears but the video is not playing.

Could you upload the scene? You could also take a look at the JavaScript console (F12 in Chrome) to check if there are any errors that indicate what is the source of the problem.

You can find the scene here: booth

I get an error:
walk.min.js:776 Assertion failed: Can’t access material, call ViewerApi.setMaterialEditable(‘M1’) before the scene is loaded.

You can go to the view “get in contact” where you can find the orange trigger which enables the dummy video.

@tim the code below fixes the problem, but you need to also change the Change view extension to move the camera. It turns out the view switch notification events are not delivered if the camera doesn’t switch to view, only view object visibility is applied. Is this a big issue in your case? I think it could make sense for the camera to move to face the virtual assistance when the trigger that starts the video is clicked.

<script>

(function() {
  var viewer = WALK.getViewer();
  viewer.setMaterialEditable('M1');
  viewer.onViewSwitchDone(function(viewName) {
    var videoTexture = viewer.findMaterial('M1').baseColorTexture;
    videoTexture.video.addEventListener('ended', function() {
     viewer.switchToView('neutral', 0, true);
    });
    if (viewName === 'help Contact') {
      videoTexture.isPlaying = true;
      videoTexture.video.muted = false;
      videoTexture.video.loop = false;
    } else {
      videoTexture.isPlaying = false;
    }
  });
}());

</script>

I agree, this is actually an advantage. I will test it!
Thanks @jan

Works very well! Thank you, @jan

I’m having some problems with this. If I configure the Video Texture Control without trigger, the video never starts.

I think the problem was not there a few weeks ago when I last tried the same thing. Could this problem have occured in the last update?

Thanks, @ville. We’re looking into it.

1 Like

We have fixed the issue. Could you verify if the Video texture control extension works OK in your online scenes now?

Excellent, it works now! Thanks.