45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
//-
|
||
using System;
|
||
using System.Threading.Tasks;
|
||
using EventCubeMelt;
|
||
using UnityEngine;
|
||
using UnityEngine.AddressableAssets;
|
||
|
||
namespace EventBlocks.UI
|
||
{
|
||
public class EventBlockVideoPlayer : MonoBehaviour
|
||
{
|
||
//- 播放视频
|
||
public LeviathanVideoDecoder _videoDecoder;
|
||
|
||
public async Task PlayVideo(string fileName)
|
||
{
|
||
ELog($"LoadVideoFile -> {fileName}");
|
||
var videoBytes = await Addressables.LoadAssetAsync<TextAsset>(fileName).Task;
|
||
// _videoDecoder.bytesFile = videoBytes;
|
||
_videoDecoder.PlayVideo(videoBytes,
|
||
LeviathanVideoDecoderBase.PlayAlphaType.ChromaKey, // None / RightSide / BottomSide / ChromaKey
|
||
multithreadedDecode: true, // WebGL 下会被强制为 false(无 C# 线程)
|
||
beginFrameIndex: 1,
|
||
syncDecodeFirstFrame: true, // false:首帧异步,先隐藏 RawImage,首帧就绪后再显示(见 OnFirstFrameRendered)
|
||
fastDecode: true // true:跳过环路滤波,解码更快、画质略降
|
||
);
|
||
}
|
||
|
||
public void StopPlayVideo()
|
||
{
|
||
_videoDecoder.Stop();
|
||
}
|
||
|
||
|
||
private static void ELog(string message)
|
||
{
|
||
#if UNITY_EDITOR
|
||
if (!EventCubeMeltLogPolicy.EnableELog)
|
||
return;
|
||
Debug.Log($"<color=orange>{nameof(EventBlockVideoPlayer)} => {message}</color>");
|
||
#endif
|
||
}
|
||
|
||
}
|
||
} |