Viro supports various components for displaying video. Video can be displayed in 360 degrees, surrounding the user, or on a flat plane, simulating a physical video screen. Partially transparent video (or "alpha" video) is also supported through chroma-key filtering.
The VideoTexture object is used to render video. Because this extends Texture, it can be assigned to any Material, and from any Material to any Geometry and Node. In the example below, a VideoTexture is loaded onto a Surface, simulating a video screen.
VideoTexture videoTexture = new VideoTexture(context, uri); Material material = new Material(); material.setDiffuseTexture(videoTexture); Quad quad = new Quad(10, 10); quad.setMaterials(Arrays.asList(material)); videoTexture.play();
Supported video formats are .mov, .mp4, .mpv, and .3gp. The video source may be a remote URL or a local file resource. To invoke with a remote URL, set the source to a URI. For example,
Uri.parse("http://example.org/myvideo.mp4"). To load an asset as video, use URI's of the form
Spherical videos that surround the user can be displayed via VideoTexture as well. To do this, simply assign the VideoTexture to the Scene's background, as shown below.
VideoTexture videoTexture = new VideoTexture(context, uri); scene.setBackgroundTexture(videoTexture);
Viro supports rendering partially transparent video over any VR, AR, or 3D scene. For AR scenes in particular, this enables "hologram" type experiences like Will.I.Am on CNN or Princess Leia in Star Wars.
Alpha video works via "chroma key filtering". Chroma key filtering removes (makes transparent) all colors from a video that are within an epsilon range of a target color. This technique is useful when rendering "green screen" or "blue screen" videos, as is commonly seen in newscasting and motion pictures. The videos in their raw form look something like the image below.
// Load the video VideoTexture videoTexture = new VideoTexture(mViroView.getViroContext(), Uri.parse("URL to Video")); // Place the video in a Material final Material material = new Material(); material.setDiffuseTexture(videoTexture); // Enable chroma-key filtering on the Material material.setChromaKeyFilteringColor(Color.GREEN); material.setChromaKeyFilteringEnabled(true); // Create a Quad on which the video will be displayed Quad surface = new Quad(4, 4, 0, 0, 1, 1); surface.setMaterials(Arrays.asList(material)); // Create a Node in which to house the Quad with the video Node node = new Node(); node.setPosition(new Vector(0, 0, -3)); node.setGeometry(surface); // Add the Node to the Scene scene.getRootNode().addChildNode(node); // Finally, play the video videoTexture.play();
VideoTexture also controls the playback of the video. You can:
- Adjust volume via the
- Mute the video via the
- Make the video loop by setting the
- Pause and play the video
- Seek the video to a specific time in seconds by invoking the
You can also respond to various playback events by implementing a PlaybackListener.