CRIWARE Unity Plugin Manual  Last Updated: 2024-07-12
[CriMana] Dynamically switching between movies by using multiple players

Description of the sample

Overview

cri4u_samples_crimana_adv02_screenshot.png

This sample program quickly switches to another movie while a movie is already being played.
To switch as quickly and smoothly as possible (i.e., reduce the time during which movie playback is stopped), the following is done:
  • Multiple CriManaMovieController components are created to ensure that the next movie is ready for play ahead of time.
When the sample is executed, two CriManaMovieController components are created by the script.
One of the components starts playback, and the other is waiting, ready for playback. When the button is clicked, the waiting movie is started immediately.
Attention
If the next movie to play is not yet ready due to many successive requests, the switching may take time.

The materials that are rendered in the movie are added to multiple game objects. Thus, multiple game objects are rendered at the same time.

Scene information


Middleware CRI Sofdec (CRI Mana)
Sample Advanced samples
Location /CRIWARE/SDK/unity/samples/UnityProject/Assets/Scenes/crimana/advanced/
Scene file Scene_02_DynamicMovieSwitch.unity


Description of the program

In this scene, the playback of all the movies is controlled by the [Scene_02_DynamicMovieSwitch.cs] script.
The [Scene_02_DynamicMovieSwitch.mat] material is provided to render a movie. It is rendered by each CriManaMovieController component.

Difference from the usual case, where only one CriManaMovieControlle is used to switch movies

When a single CriManaMovieControlle is used to switch movies, playback is stopped, and then the next movie is started. Switching takes time and the movie is stopped during that time. To switch as quickly and as smoothly as possible (i.e., reduce the time during which a movie is stopped), it is recommended that you use multiple CriManaMovieControllers to switch movies as in this sample.
[Note]
When you use multiple CriManaMovieControllers, be careful about memory usage.
Although CriManaMovieController does not require any work memory while a movie is stopped, a waiting movie uses as much work memory as a playing one.

Sharing the drawing surface between multiple CriManaMovieController components

To share the drawing surface between multiple CriManaMovieController components, use the movieMaterial property (CriManaMovieMaterial.material).
moviePlayers[i] = this.gameObject.AddComponent<CriManaMovieMaterial>();
moviePlayers[i].player.SetFile(null, moviePathes[i]);
/* Set materials. */
moviePlayers[i].material = movieMaterial;
In this sample, a material is specified in the script. You can also specify the material in the Inspector for the CriManaMovieController component.

[Note]
By default, there is no material specified. Create a material in the player and replace the material of the game object at playback.

Controlling when to start a movie

When starting to play a stopped movie (with CriManaMovieMaterial.player.Start), a delay (of dozens of milliseconds) can occur until the screen is actually refreshed.
To start the playback, call the CriManaMovieMaterial.player.PrepareForRendering function, and wait until the playback status becomes Status.Ready.
if (i == 0) {
/* Start player #0 only. */
moviePlayers[0].player.Start();
} else {
/* Prepare other players for playback. */
moviePlayers[i].player.PrepareForRendering();
}
In this sample, when the button is clicked, a movie that is being played is stopped, and the player that has been waiting is started. Thus, movies are switched without delay.
To simplify the process, this sample uses the player stopped in the Update function again. Making it ready for playback again make it possible to switch players instantly.
In an actual application, you should take into account the time needed for the preparation for playback.
void Update () {
/* Search all the players. */
for (int i=0; i<moviePlayers.Length; i++) {
/* Separete the processing by the player status. */
switch(moviePlayers[i].player.status) {
case CriMana.Player.Status.Stop:
/* Return to the preparation status after the playback is finished. */
moviePlayers[i].player.PrepareForRendering();
break;
default:
break;
}
}
}

Drawing multiple game objects at the same time

If you want to draw multiple game objects with one player component at the same time, provide the material to render the movie.
Add that material to each game object, and assign it to the movieMaterial property of the player component. Thus, you can draw multiple objects at the same time.

It is possible to draw on other materials such as the textures when using NGUI.

Difference with seamless concatenated playback

The purpose of this sample is to switch movies quickly "during playback".
To play multiple movies successively, see the Seamless concatenated playback in the Basic samples.