Audio and Video Puzzles

These puzzles are used to load and play back audio and video files.

Contents

Puzzles Reference

load sound

Loads an audio file using a specified URL. The audio is played via the HTML5 Audio tag or WebAudio API depending on the chosen type: music or sound respectively. This puzzle also adds the loaded audio to a memory cache so that any subsequent uses of this puzzle with the same URL do not load the same sound file again. Using .mp3 format is recommended as it is supported by most web browsers.

preloading audio

Audio files take some time to load, so they are not available immediately. That's why simply using this puzzle inside the play puzzle may not work and the audio may not start playing.

In order to be sure that audio in your application works properly it's recommended to load audio files beforehand, for example, in the init tab which is executed before a Verge3D application is initialized. You can also use the connector puzzle to organize a bunch of "load sound" puzzles in a bit more convenient way:

Preloading audio in the "init" tab.

After that using the preloaded audio files either in the main and user-created tabs shouldn't cause any issues, since the audio is already cached after the first use of the "load sound" puzzle, hence it doesn't need to be downloaded again:

Using the preloaded audio in the "main" tab.

autoplay restrictions

In general, audio playback initiated programmatically (as in the case of puzzles) will most likely be blocked by a browser. This happens due to autoplay policies that restrict how audio can be played automatically on a web page. The purpose of such restrictions is to stop web pages from making spontaneous noises or playing audio when it's not desired, thus improving overall user experience.

Although, such policies can be implemented differently in various browsers and also can have various conditions for allowing / not allowing autoplay, the general rule for playing audio is to wait for the user to interact with your web page.

In cases where such interaction is already implied by the application's logic, for example, playing a sound on click (be it either a 3d-object or an HTML button), those restrictions are not what you should worry about. But, let's say that you want your application to have some background music that starts playing when the app is loaded. Since that can not always be done in an automatic way, a good solution would be to make a "launch" button for starting the app when it's loaded and ready. Clicking it counts as a user interaction and allows to start audio playback.

"music" vs "sound" audio type

This puzzle allows you to choose which API to use for loading and playing audio files.

Web Audio API which is utilized by the sound type is supported in most modern browsers. However, if you need your audio to work in browsers with no Web Audio support (e.g. Internet Explorer 11) you have to use the music type.

If it's necessary to use the sound type in browsers where it is available and also support Internet Explorer 11 at the same time, then the recommended solution is to use the feature available puzzle with the Web Audio API option selected to check if the API is available or not and load audio with the music or the sound type depending on that. You can do that for both preloading and playing audio in a way shown below:

Preloading audio in the "init" tab with the check for Web Audio API availability. Using the preloaded audio in the "main" tab with the check for Web Audio API availability.

load video

Creates an HTML5 video element and loads a sound file using a specified URL. This puzzle also adds the created video element to a memory cache so that any subsequent uses of this puzzle with the same URL do not load the same sound file again. Using .mp4 format is recommended as it is supported by most web browsers.

The load video puzzle does not create any visible elements on your scene. To make it visible, assign video texture to your materials using the replace texture puzzle.

play

Starts audio or video playback. The loop checkbox repeats playback if enabled.

Due to browser restrictions (preventing malicious websites from playing noisy sounds and videos) you should not execute this puzzle to play your assets automatically (upon scene loading). Instead, you should do this in some user-generated event. Use when clicked or event to handle such events.

There is one exception to this rule. Browsers allow playing muted videos automatically. See the mute puzzle.

pause

Pauses audio or video playback.

stop

Stops audio or video playback. Using this puzzle is equivalent to using the pause puzzle, followed by the rewind puzzle.

rewind

Makes the audio or video asset to play from the start.

set playback rate

Set audio/video playback rate. Specify value <1 to slow down playback, 1 for normal speed, and >1 to increase playback speed.

set volume

Sets the sound volume. Input volume is clamped to the 0.0-1.0 range. This puzzle also works for videos with embedded audio track.

is playing

Checks if a sound or video is being played back.

mute

Mute a sound or video.

Apart from controlling audio volume, you can use this puzzle to start video playback automatically. This is possible, because web browsers allow playing muted videos without user interaction.

unmute

Unmute a sound or video.

Having Troubles with Puzzles?

Seek help on the forums!