70 lines
1.6 KiB
C#
70 lines
1.6 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.Video;
|
||
|
||
/// <summary>
|
||
/// 360视频播放控制组件,用来读取外部视频文件
|
||
/// </summary>
|
||
public class Video360Controller : MonoBehaviour
|
||
{
|
||
private VideoPlayer mVideoPlayer;
|
||
public string VideoNameStr = "";
|
||
public double Time = 0;
|
||
|
||
private void Awake()
|
||
{
|
||
mVideoPlayer = gameObject.GetComponent<VideoPlayer>();
|
||
mVideoPlayer.started += MVideoPlayer_started;
|
||
mVideoPlayer.prepareCompleted += MVideoPlayer_prepareCompleted;
|
||
PrepareVide(VideoNameStr);
|
||
}
|
||
|
||
public bool isPlaying
|
||
{
|
||
get { return mVideoPlayer.isPlaying; }
|
||
}
|
||
|
||
private void MVideoPlayer_started(VideoPlayer source)
|
||
{
|
||
if (Time != 0)
|
||
{
|
||
MVideoPlayer_started(Time);
|
||
}
|
||
}
|
||
private void MVideoPlayer_prepareCompleted(VideoPlayer source)
|
||
{
|
||
mVideoPlayer.Play();
|
||
}
|
||
|
||
public void MVideoPlayer_started(double mtime)
|
||
{
|
||
if (Time >= mVideoPlayer.length)
|
||
{
|
||
mVideoPlayer.time = mVideoPlayer.length;
|
||
return;
|
||
}
|
||
mVideoPlayer.time = mtime;
|
||
}
|
||
|
||
public void PrepareVide(string name)
|
||
{
|
||
try
|
||
{
|
||
string videoPath = FileLoad.GetMoviesFolder() + name;
|
||
Debug.Log($"目录检测{videoPath}");
|
||
mVideoPlayer.url = videoPath;
|
||
mVideoPlayer.Prepare();
|
||
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
Debug.LogError(e.Message);
|
||
}
|
||
}
|
||
private void OnDisable()
|
||
{
|
||
Time = 0;
|
||
}
|
||
}
|