|
@@ -1,198 +0,0 @@
|
|
|
-
|
|
|
-using RenderHeads.Media.AVProVideo;
|
|
|
-using System.Collections;
|
|
|
-using System.Collections.Generic;
|
|
|
-using UnityEngine;
|
|
|
-using static MediaPlayerCtrl;
|
|
|
-
|
|
|
-public class AVProVideoPlayer : MonoBehaviour
|
|
|
-{
|
|
|
- private MediaPlayerCtrl mediaPlayer;
|
|
|
- private bool isVideoReady;
|
|
|
- private void Start()
|
|
|
- {
|
|
|
- MediaPlayer.m_eventOnReady = new UnityEngine.Events.UnityEvent();
|
|
|
- MediaPlayer.m_eventOnReady.AddListener(OnVideoReady);
|
|
|
-
|
|
|
- // SetUrl("D:\\2-3D.mp4");
|
|
|
- // Play();
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 当前视频状态
|
|
|
- /// </summary>
|
|
|
- /// <param name="mp"></param>
|
|
|
- /// <param name="et"></param>
|
|
|
- /// <param name="errorCode"></param>
|
|
|
- private void OnVideoReady()
|
|
|
- {
|
|
|
- isVideoReady = true;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public Texture getTexture()
|
|
|
- {
|
|
|
- return MediaPlayer.m_VideoTexture;
|
|
|
- }
|
|
|
- private MediaPlayerCtrl MediaPlayer
|
|
|
- {
|
|
|
- get
|
|
|
- {
|
|
|
- if(mediaPlayer == null)
|
|
|
- {
|
|
|
- mediaPlayer = GetComponent<MediaPlayerCtrl>();
|
|
|
- }
|
|
|
- if (mediaPlayer == null)
|
|
|
- {
|
|
|
- mediaPlayer = this.gameObject.AddComponent<MediaPlayerCtrl>();
|
|
|
-
|
|
|
- }
|
|
|
- return mediaPlayer;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void Play()
|
|
|
- {
|
|
|
- if (MediaPlayer.pathLoad != null)
|
|
|
- {
|
|
|
-
|
|
|
- if (IsFinished())
|
|
|
- {
|
|
|
- MediaPlayer.Load(MediaPlayer.pathLoad);
|
|
|
- Debug.Log("DGJ ===> Play Load " + MediaPlayer.pathLoad);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- MediaPlayer.Play();
|
|
|
- Debug.Log("DGJ ===> Play");
|
|
|
- }
|
|
|
- }else
|
|
|
- {
|
|
|
-
|
|
|
- Debug.LogError(" MediaPlayer.pathLoad == null");
|
|
|
- }
|
|
|
- Debug.Log("开始播放");
|
|
|
- }
|
|
|
-
|
|
|
- public void Stop()
|
|
|
- {
|
|
|
- MediaPlayer.Stop();
|
|
|
- }
|
|
|
-
|
|
|
- public void Pause()
|
|
|
- {
|
|
|
- MediaPlayer.Pause();
|
|
|
- }
|
|
|
-
|
|
|
- public void SetUrl(string url)
|
|
|
- {
|
|
|
-#if !UNITY_EDITOR
|
|
|
-
|
|
|
- if(!url.Contains("file://") && !url.Contains("//"))
|
|
|
- {
|
|
|
- url = "file://" + url;
|
|
|
- }
|
|
|
-#endif
|
|
|
-
|
|
|
- MediaPlayer.pathLoad= url;
|
|
|
- Debug.Log("DGJ ===> pathLoad" + MediaPlayer.pathLoad);
|
|
|
- }
|
|
|
-
|
|
|
- public string GetUrl()
|
|
|
- {
|
|
|
- return MediaPlayer.pathLoad;
|
|
|
- }
|
|
|
-
|
|
|
- public void SetVolue( float volume)
|
|
|
- {
|
|
|
- MediaPlayer.SetVolume( volume);
|
|
|
- }
|
|
|
-
|
|
|
- public void SetSeek(float value)
|
|
|
- {
|
|
|
- float targetTimeMs = value;
|
|
|
- if(targetTimeMs>=0&& targetTimeMs<=1)
|
|
|
- MediaPlayer.SetSeekBarValue(targetTimeMs);
|
|
|
- }
|
|
|
-
|
|
|
- public float GetMaxTimer()
|
|
|
- {
|
|
|
- return (float)MediaPlayer.GetDuration()/1000;
|
|
|
- }
|
|
|
-
|
|
|
- public float GetNowTimer()
|
|
|
- {
|
|
|
- return (float)MediaPlayer.GetSeekPosition() / 1000;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public bool IsVideoReady()
|
|
|
- {
|
|
|
- return isVideoReady;
|
|
|
- }
|
|
|
-
|
|
|
- public float GetVolue()
|
|
|
- {
|
|
|
- return MediaPlayer.m_fVolume;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public bool IsPlaying()
|
|
|
- {
|
|
|
- if(MediaPlayer == null||MediaPlayer.pathLoad==null)
|
|
|
- return false;
|
|
|
- try
|
|
|
- {
|
|
|
- if(MediaPlayer.m_CurrentState== MEDIAPLAYER_STATE.PLAYING&& MediaPlayer.m_CurrentState!= MEDIAPLAYER_STATE.END)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
- catch (System.Exception e)
|
|
|
- {
|
|
|
- Debug.LogError(e.Message);
|
|
|
- return false;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public float GetVideoWidth()
|
|
|
- {
|
|
|
- return MediaPlayer.GetVideoWidth();
|
|
|
- }
|
|
|
-
|
|
|
- public float GetVideoHeight()
|
|
|
- {
|
|
|
- return mediaPlayer.GetVideoHeight();
|
|
|
- }
|
|
|
-
|
|
|
- public bool IsPaused()
|
|
|
- {
|
|
|
- if (MediaPlayer.m_CurrentState == MEDIAPLAYER_STATE.PAUSED)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- public bool IsFinished()
|
|
|
- {
|
|
|
- if ( MediaPlayer.m_CurrentState == MEDIAPLAYER_STATE.END)
|
|
|
- {
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public MEDIAPLAYER_STATE GetVideoState()
|
|
|
- {
|
|
|
- return MediaPlayer.m_CurrentState;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|