2025-01-02 12:15:45 +08:00
|
|
|
|
using RenderHeads.Media.AVProVideo;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
using DG.Tweening;
|
|
|
|
|
|
using CG.UTility;
|
|
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
|
using ZXK.LouDiXvMuNiu;
|
2025-01-09 18:12:40 +08:00
|
|
|
|
using System;
|
2025-01-02 12:15:45 +08:00
|
|
|
|
/*******************************************************************************
|
|
|
|
|
|
*Create By CG
|
|
|
|
|
|
*Function <EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
public class VCRCustom : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
private MediaPlayer _playingPlayer;
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
private RectTransform _ctrlContainer;
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
private Slider _videoSeekSlider;
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
private Slider _audioVolumeSlider;
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
private Text _timeText;
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
private Button _playCtrlBtn;
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
private Image _playBigCtrlBtn;
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
private Button _playVideoCloseBtn;
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
private GameObject _volume;
|
|
|
|
|
|
[SerializeField]//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣС<CDA3><D0A1>ť
|
|
|
|
|
|
private Sprite[] _playSmallCtrlImgs;
|
|
|
|
|
|
[SerializeField]//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>ť
|
|
|
|
|
|
private Sprite[] _playBigCtrlImgs;
|
|
|
|
|
|
[SerializeField]//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
private Sprite[] _audioCtrlImgs;
|
|
|
|
|
|
|
|
|
|
|
|
private float _setVideoSeekSliderValue;
|
|
|
|
|
|
private bool _wasPlayingOnScrub;
|
|
|
|
|
|
//private float _setAudioVolumeSliderValue;
|
|
|
|
|
|
|
|
|
|
|
|
private GraphicRaycaster _mRaycaster;
|
|
|
|
|
|
private EventSystem _mEventSystem;
|
|
|
|
|
|
|
|
|
|
|
|
private float _mouseStopTime = 2.0f;//<2F><><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؿ<EFBFBD><D8BF>ư<EFBFBD><C6B0><EFBFBD>
|
|
|
|
|
|
private bool _downState = false;
|
|
|
|
|
|
private float _curMouseTime = 0.0f;
|
|
|
|
|
|
private Vector2 _previousPos = Vector2.zero;
|
|
|
|
|
|
|
2025-01-09 18:12:40 +08:00
|
|
|
|
private Action _finishHandle;
|
|
|
|
|
|
|
2025-01-02 12:15:45 +08:00
|
|
|
|
//private string _videoPath = Application.streamingAssetsPath + @"/AVProVideoSamples/BigBuckBunny_720p30.mp4";
|
|
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public void OnOpenVideoFile(string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
_audioVolumeSlider.onValueChanged.RemoveAllListeners();
|
|
|
|
|
|
_audioVolumeSlider.onValueChanged.AddListener((vul) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_playingPlayer && _audioVolumeSlider)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameManager.Instance._CurAppVoice = vul;
|
|
|
|
|
|
_playingPlayer.Control.SetVolume(vul);
|
|
|
|
|
|
if (GameManager.Instance._CurAppVoice <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
_volume.transform.Find("AudLogo").GetComponent<Image>().sprite = _audioCtrlImgs[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_volume.transform.Find("AudLogo").GetComponent<Image>().sprite = _audioCtrlImgs[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
_mRaycaster = GameObject.FindGameObjectWithTag("MainCanvas").GetComponent<GraphicRaycaster>();
|
|
|
|
|
|
_mEventSystem = GameManager.Instance.transform.GetChild(0).GetComponent<EventSystem>();
|
|
|
|
|
|
|
|
|
|
|
|
_playingPlayer.m_VideoPath = path;
|
|
|
|
|
|
if (string.IsNullOrEmpty(_playingPlayer.m_VideoPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
_playingPlayer.CloseVideo();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_playingPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.AbsolutePathOrURL, _playingPlayer.m_VideoPath, true);
|
|
|
|
|
|
_playCtrlBtn.GetComponent<Image>().sprite = _playSmallCtrlImgs[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_playingPlayer)
|
|
|
|
|
|
{
|
|
|
|
|
|
_playingPlayer.Events.AddListener(OnVideoEvent);
|
|
|
|
|
|
if (_audioVolumeSlider)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_playingPlayer.Control != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//float volume = _playingPlayer.Control.GetVolume();
|
|
|
|
|
|
//_setAudioVolumeSliderValue = volume;
|
|
|
|
|
|
WDebug.Log($"<22><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{GameManager.Instance._CurAppVoice}");
|
|
|
|
|
|
_audioVolumeSlider.value = GameManager.Instance._CurAppVoice;
|
|
|
|
|
|
_playingPlayer.Control.SetVolume(_audioVolumeSlider.value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-01-09 18:12:40 +08:00
|
|
|
|
public void SetFinishAction(Action finishAnm)
|
|
|
|
|
|
{
|
|
|
|
|
|
_finishHandle = finishAnm;
|
|
|
|
|
|
}
|
2025-01-02 12:15:45 +08:00
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_playingPlayer && _playingPlayer.Info != null && _playingPlayer.Info.GetDurationMs() > 0f)
|
|
|
|
|
|
{
|
|
|
|
|
|
float time = _playingPlayer.Control.GetCurrentTimeMs();
|
|
|
|
|
|
System.TimeSpan timeSpan = System.TimeSpan.FromMilliseconds(time);
|
|
|
|
|
|
float duration = _playingPlayer.Info.GetDurationMs();
|
|
|
|
|
|
System.TimeSpan durationSpan = System.TimeSpan.FromMilliseconds(duration);
|
|
|
|
|
|
_timeText.text = timeSpan.ToString("mm\\:ss") + "/" + durationSpan.ToString("mm\\:ss");//"hh\\:mm\\:ss"
|
|
|
|
|
|
float d = Mathf.Clamp(time / duration, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
|
|
_setVideoSeekSliderValue = d;
|
|
|
|
|
|
_videoSeekSlider.value = d;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Vector2 curPos = Input.mousePosition;
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
GraphicRaycaster(curPos);
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ƶ<EFBFBD>
|
|
|
|
|
|
if (Vector2.Distance(curPos, _previousPos) < 0.5f)
|
|
|
|
|
|
{
|
|
|
|
|
|
_curMouseTime += Time.deltaTime;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_curMouseTime = 0;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2))
|
|
|
|
|
|
{
|
|
|
|
|
|
CtrlContainerDownUp(false);
|
|
|
|
|
|
_curMouseTime = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_curMouseTime > _mouseStopTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
CtrlContainerDownUp(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
CtrlContainerDownUp(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
_previousPos = curPos;
|
|
|
|
|
|
}
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_playingPlayer)
|
|
|
|
|
|
{
|
|
|
|
|
|
_playingPlayer.Events.RemoveListener(OnVideoEvent);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnVideoEvent(MediaPlayer mp, MediaPlayerEvent.EventType et, ErrorCode errorCode)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (et)
|
|
|
|
|
|
{
|
|
|
|
|
|
case MediaPlayerEvent.EventType.ReadyToPlay:
|
|
|
|
|
|
break;
|
|
|
|
|
|
case MediaPlayerEvent.EventType.Started:
|
|
|
|
|
|
break;
|
|
|
|
|
|
case MediaPlayerEvent.EventType.FirstFrameReady:
|
|
|
|
|
|
break;
|
|
|
|
|
|
case MediaPlayerEvent.EventType.FinishedPlaying:
|
2025-01-09 18:12:40 +08:00
|
|
|
|
_finishHandle?.Invoke();
|
2025-01-02 12:15:45 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
WDebug.Log("Event: " + et.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnVideoSeekSlider()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_playingPlayer && _videoSeekSlider && _videoSeekSlider.value != _setVideoSeekSliderValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
_playingPlayer.Control.Seek(_videoSeekSlider.value * _playingPlayer.Info.GetDurationMs());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void OnVideoSliderDown()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_playingPlayer)
|
|
|
|
|
|
{
|
|
|
|
|
|
_wasPlayingOnScrub = _playingPlayer.Control.IsPlaying();
|
|
|
|
|
|
if (_wasPlayingOnScrub)
|
|
|
|
|
|
{
|
|
|
|
|
|
_playingPlayer.Control.Pause();
|
|
|
|
|
|
}
|
|
|
|
|
|
OnVideoSeekSlider();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void OnVideoSliderUp()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_playingPlayer && _wasPlayingOnScrub)
|
|
|
|
|
|
{
|
|
|
|
|
|
_playingPlayer.Control.Play();
|
|
|
|
|
|
_wasPlayingOnScrub = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void OnPlayPauseButton()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_playingPlayer.Control.IsPlaying())
|
|
|
|
|
|
{
|
|
|
|
|
|
_playingPlayer.Control.Pause();
|
|
|
|
|
|
_playCtrlBtn.GetComponent<Image>().sprite = _playSmallCtrlImgs[1];
|
|
|
|
|
|
_playBigCtrlBtn.GetComponent<Image>().sprite = _playBigCtrlImgs[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_playingPlayer.Control.Play();
|
|
|
|
|
|
_playCtrlBtn.GetComponent<Image>().sprite = _playSmallCtrlImgs[0];
|
|
|
|
|
|
_playBigCtrlBtn.GetComponent<Image>().sprite = _playBigCtrlImgs[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void CtrlContainerDownUp(bool isDown)
|
|
|
|
|
|
{
|
|
|
|
|
|
//WDebug.Log($"<22><><EFBFBD>ư<EFBFBD>ť״̬<D7B4><CCAC>{isDown}");
|
|
|
|
|
|
if (isDown)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!_downState)
|
|
|
|
|
|
{
|
|
|
|
|
|
WDebug.Log("ִ<><D6B4><EFBFBD>½<EFBFBD>");
|
|
|
|
|
|
_downState = true;
|
|
|
|
|
|
_ctrlContainer.GetComponent<CanvasGroup>().DOFade(0, 0.5f);
|
|
|
|
|
|
//_ctrlContainer.DOAnchorPosY(-200.0f, 0.5f);
|
|
|
|
|
|
//_playBigCtrlBtn.gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_downState)
|
|
|
|
|
|
{
|
|
|
|
|
|
WDebug.Log("ִ<><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
|
_downState = false;
|
|
|
|
|
|
_ctrlContainer.GetComponent<CanvasGroup>().DOFade(1, 0.5f);
|
|
|
|
|
|
//_ctrlContainer.DOAnchorPosY(-0, 0.5f);
|
|
|
|
|
|
//_playBigCtrlBtn.gameObject.SetActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<CDBC><C6AC><EFBFBD><EFBFBD>
|
|
|
|
|
|
private void GraphicRaycaster(Vector2 pos)
|
|
|
|
|
|
{
|
|
|
|
|
|
var mPointerEventData = new PointerEventData(_mEventSystem);
|
|
|
|
|
|
mPointerEventData.position = pos;
|
|
|
|
|
|
List<RaycastResult> results = new List<RaycastResult>();
|
|
|
|
|
|
_mRaycaster.Raycast(mPointerEventData, results);
|
|
|
|
|
|
if (results.Count > 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < results.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (results[i].gameObject == _volume.gameObject)
|
|
|
|
|
|
{
|
|
|
|
|
|
_volume.GetComponent<RectTransform>().sizeDelta = new Vector2(30, 180);
|
|
|
|
|
|
_audioVolumeSlider.gameObject.SetActive(true);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_volume.GetComponent<RectTransform>().sizeDelta = new Vector2(30, 30);
|
|
|
|
|
|
_audioVolumeSlider.gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|