はじめに
Vuforiaを使って動画を再生すると、必ず決まったサイズでしか再生できない。
これをなんとかしたい。
対処方法
スクリプトVideoPlaybackBehaviour.csで強制的にアスペクト比にあったサイズに変更されているようなので、これに修正を加える。
VideoPlaybackBehaviour.cs(230行前後)
if (videoWidth > 0 && videoHeight > 0)
{
// Scale the video plane to match the video aspect ratio
float aspect = videoHeight / (float) videoWidth;
// Flip the plane as the video texture is mirrored on the horizontal
transform.localScale = new Vector3 (-0.1f, 0.1f, 0.1f * aspect);
}
上記のようになっているのを下記のように変更する。
VideoPlaybackBehaviour.cs(230行前後)
if (videoWidth > 0 && videoHeight > 0)
{
// Scale the video plane to match the video aspect ratio
float aspect = videoHeight / (float) videoWidth;
if (KeepWidth) {
transform.localScale = new Vector3 (transform.localScale.x, 0.1f, -transform.localScale.x * aspect);
} else {
// Flip the plane as the video texture is mirrored on the horizontal
transform.localScale = new Vector3 (-0.1f, 0.1f, 0.1f * aspect);
}
}
また、50行目付近のパブリック変数を宣言しているあたりに、次の行を追加する。
VideoPlaybackBehaviour.cs
public bool KeepWidth = true;
以上で、スクリプトを貼り付けたオブジェクトの幅(Scaleのx)に合わせた動画サイズでビデオが再生されるようになる。
参考サイト
Modifying the scale of the video plane in the Video Playback Sample app