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?
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>
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.
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.
Hey one question; is there any way to have a video texture running muted by default & the option of unmuting via trigger?
There is no dedicated extension for this, but you can achieve it with the following:
var video = WALK.getViewer().findMaterial('NAME-OF-YOUR-MATERIAL-WITH-VIDEO').baseColorTexture;
video.muted = !video.muted;
If you encounter problems, you can check if the Chrome Developer Tools, Console displays any errors related to this code.
Thank you so much! Works like a dream: 3D scene