CRIWARE Unity Plugin Manual  Last Updated: 2024-07-12
[CriMana] Playing from a CPK file

Description of the sample

Overview

cri4u_samples_crimana_scene03_screenshot.png

This sample plays a movie from a CPK file (a pack file from FileMajik PRO).
All the processes related to movie playback are implemented by a runtime script.

When the sample is executed, the movie playback does not start.
Use the steps below to start the playback.
  • (1) Click on the Bind CPK File button to bind the CPK file.
  • (2) When binding is complete, an asterisk (*) appears at the beginning of the string on the Bind CPK File button, and the Play button is displayed on the screen.
  • (3) Click on the Play button. The movie is started as a texture on the cube, and the Play button becomes the Stop button.
  • (4) If you click on the Stop button during playback, the movie is stopped.
  • (5) If you click on the Reset button, the sample returns to its initial status before the CPK file was bound.

Scene information


Middleware CRI Sofdec (CRI Mana)
Sample Basic samples
Location /CRIWARE/SDK/unity/samples/UnityProject/Assets/Scenes/crimana/basic/
Scene file Scene_03_PlaybackCpk.unity


Description of the program

This sample program uses a runtime script to play a movie from a CPK file.
Instead of configuring the CriManaMovieController component in Unity Editor, all the processes related to the movie playback are handled within the script.
The binding of a CPK file and how to start/stop movie playback are both described in the script of Scenes/Scene_03_PlaybackCpk.

Binding a CPK file

The binding of a CPK file is handled in exactly the same way than in the sample program of FileMajik PRO. Therefore, the description of the binding is omitted here. For details, please see the sample for FileMajik PRO ( " [CriFs] Loading a CPK file (packed file) ").
This sample uses a coroutine for the binding. You can also use status polling by FileMajik PRO if you don't want to use a coroutine. You can see both methods in the sample for FileMajik PRO ( " [CriFs] Loading a file ").

Adding a CriManaMovieController component

This sample adds a CriManaMovieController component to a game object in the script.

moviePlayer = movieObject.AddComponent<CriManaMovieController>();

Specifying a binder and a file name

You have to specify the binder to which the CPK file is bound and the name of the content file in the CPK file before starting to play a movie.
Please note that the content file is not the CPK file but a content file packed in the CPK file.

/* Set the binder and the file name. */
moviePlayer.player.SetFile(binder, movieFilename);
/* Start a playback. */
moviePlayer.player.Start();

Stopping playback

The playback stop function in the CriManaMovieController class only issues a playback stop request. Playback is actually stopped when the playback status of the CriManaMovieController class becomes "Stop".
To avoid a slowdown while waiting for the playback to stop, this sample monitors the playback status periodically instead of waiting in a local loop.
When the status becomes "Stop", the CriManaMovieController class is destroyed.

switch (this.moviePlayer.player.status) {
case CriMana.Player.Status.Playing:
/* The Stop button processing. */
if (Scene_00_GUI.Button("Stop")) {
moviePlayer.player.Stop();
}
break;
case CriMana.Player.Status.PlayEnd:
/* Call the Stop() even when the playback is finished. */
moviePlayer.player.Stop();
break;
case CriMana.Player.Status.Stop:
/* Destroy the CriManaMovieController. */
Destroy(moviePlayer);
break;
}