first commit
This commit is contained in:
132
Assets/Scripts/UI/VideoPlayer.cs
Normal file
132
Assets/Scripts/UI/VideoPlayer.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using FairyGUI;
|
||||
using NBC;
|
||||
using RenderHeads.Media.AVProVideo;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public partial class VideoPlayer : GComponent
|
||||
{
|
||||
private NTexture _texture;
|
||||
private float _defY;
|
||||
|
||||
private void OnInited()
|
||||
{
|
||||
VideoManager.Instance.OnPlayStart += OnPlayStart;
|
||||
VideoManager.Instance.OnHandleEvent += OnHandleEvent;
|
||||
BtnPause.onClick.Set(OnClickPause);
|
||||
|
||||
SwipeGesture gesture = new SwipeGesture(BtnPause);
|
||||
gesture.onBegin.Set(OnSwipeBegin);
|
||||
gesture.onMove.Set(OnSwipeMove);
|
||||
gesture.onEnd.Set(OnSwipeEnd);
|
||||
gesture.onAction.Add(OnSwipeGesture);
|
||||
_defY = VideoVer.y;
|
||||
// Video.texture = new NTexture(Game.Instance.RT);
|
||||
// Player.on
|
||||
// Player.OpenMedia()
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
VideoManager.Instance.OnPlayStart -= OnPlayStart;
|
||||
VideoManager.Instance.OnHandleEvent -= OnHandleEvent;
|
||||
if (_texture != null)
|
||||
{
|
||||
_texture.Dispose();
|
||||
}
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
#region 手势
|
||||
|
||||
private float _offsetValue;
|
||||
|
||||
private void OnSwipeBegin(EventContext context)
|
||||
{
|
||||
}
|
||||
|
||||
private void OnSwipeMove(EventContext context)
|
||||
{
|
||||
var gesture = context.sender as SwipeGesture;
|
||||
if (gesture == null) return;
|
||||
Log.Info($"gesture.delta.y={gesture.delta.y}");
|
||||
_offsetValue += gesture.delta.y;
|
||||
VideoVer.y = _defY + _offsetValue;
|
||||
}
|
||||
|
||||
private void OnSwipeEnd(EventContext context)
|
||||
{
|
||||
_offsetValue = 0;
|
||||
VideoVer.y = _defY;
|
||||
}
|
||||
|
||||
private void OnSwipeGesture(EventContext context)
|
||||
{
|
||||
SwipeGesture swipeGesture = (SwipeGesture)context.sender;
|
||||
var value = Math.Abs(swipeGesture.position.y);
|
||||
if (value < 200)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (swipeGesture.position.y < 0) //向上滑动
|
||||
{
|
||||
Log.Info($"向上滑动 y={swipeGesture.position.y}");
|
||||
VideoManager.Instance.Next();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Info($"向下滑动 y={swipeGesture.position.y}");
|
||||
VideoManager.Instance.Previous();
|
||||
}
|
||||
|
||||
VideoVer.alpha = 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
private void OnHandleEvent(MediaPlayerEvent.EventType eventType)
|
||||
{
|
||||
if (eventType == MediaPlayerEvent.EventType.Paused)
|
||||
{
|
||||
// pauseCtrl.selectedIndex = 1;
|
||||
}
|
||||
// else if (eventType == MediaPlayerEvent.EventType.Unpaused ||
|
||||
// eventType == MediaPlayerEvent.EventType.Started)
|
||||
// {
|
||||
// // pauseCtrl.selectedIndex = 0;
|
||||
// }
|
||||
else if (eventType == MediaPlayerEvent.EventType.Started)
|
||||
{
|
||||
StartedAnim.Play();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayStart(RenderTexture rt)
|
||||
{
|
||||
if (_texture != null)
|
||||
{
|
||||
_texture.Dispose();
|
||||
}
|
||||
|
||||
_texture = new NTexture(rt);
|
||||
VideoVer.texture = _texture;
|
||||
}
|
||||
|
||||
|
||||
#region 播放控制
|
||||
|
||||
private void OnClickPause()
|
||||
{
|
||||
VideoManager.Instance.TogglePlayPause();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user