「Unity/VideoPlayer」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→GoogleDriveなどでmp4を上げてソースアクセスする方法) |
|||
| 行12: | 行12: | ||
#VideoPlayerのSourceをURLに変更、ネット上にあるmp4データなどを、追加する | #VideoPlayerのSourceをURLに変更、ネット上にあるmp4データなどを、追加する | ||
| + | ==動画操作サンプル== | ||
| + | <pre> | ||
| + | using UnityEngine; | ||
| + | using UnityEngine.Video; | ||
| + | public class SampleScene : MonoBehaviour | ||
| + | { | ||
| + | [SerializeField] VideoPlayer videoPlayer; | ||
| + | void Start() | ||
| + | { | ||
| + | videoPlayer.started += StartVideo; | ||
| + | videoPlayer.loopPointReached += FinishedVideo; | ||
| + | } | ||
| + | // 動画開始 | ||
| + | void StartVideo(VideoPlayer vp) | ||
| + | { | ||
| + | Debug.Log("StartVideo!!"); | ||
| + | } | ||
| + | // 動画終了 | ||
| + | void FinishedVideo(VideoPlayer vp) | ||
| + | { | ||
| + | Debug.Log("FinishedVideo!!"); | ||
| + | vp.Stop(); | ||
| + | } | ||
| + | } | ||
| + | </pre> | ||
==UniversalPRでのサンプル作成== | ==UniversalPRでのサンプル作成== | ||
#PlayerSettingsのgraphicsのAssetsにUniversalPRを入れる。 | #PlayerSettingsのgraphicsのAssetsにUniversalPRを入れる。 | ||
2022年2月16日 (水) 15:20時点における版
目次
サンプル作成
- ヒエラルキーから、Planeを作成する。
- Planeを見やすいように、Rotationを(90,180,0)へ
- PlaneのInspectorからAddCompornentして、Video Playerを追加
- MeshRendererがDefault-Materialであることを確認する
- mp4等のデータをAssetsのどこかに置く。
- VideoPlayerのSourceをVideoClipであることを確認して、mp4などをVideoClipに追加する
参考:https://xr-hub.com/archives/15798
videoをurlで表示できるように
- VideoPlayerのSourceをURLに変更、ネット上にあるmp4データなどを、追加する
動画操作サンプル
using UnityEngine;
using UnityEngine.Video;
public class SampleScene : MonoBehaviour
{
[SerializeField] VideoPlayer videoPlayer;
void Start()
{
videoPlayer.started += StartVideo;
videoPlayer.loopPointReached += FinishedVideo;
}
// 動画開始
void StartVideo(VideoPlayer vp)
{
Debug.Log("StartVideo!!");
}
// 動画終了
void FinishedVideo(VideoPlayer vp)
{
Debug.Log("FinishedVideo!!");
vp.Stop();
}
}
UniversalPRでのサンプル作成
- PlayerSettingsのgraphicsのAssetsにUniversalPRを入れる。
- 上と同じ手順で作成し直す。
- PlaneのMeshRendererが、Litになってることを確認
(確認できず・・)
GoogleDriveなどでmp4を上げてソースアクセスする方法
以下のような感じにurlを変更すれば良い。
ttps://drive.google.com/uc?export=view&id=[id]
unityからgoogle-driveにアクセスする方法は、googleのポリシー違反なので、使わないほうが良いかも。
