using RenderHeads.Media.AVProVideo; using System.Collections; using System.Collections.Generic; using UnityEngine; public class AVProVideoPlayer : MonoBehaviour { private MediaPlayer mediaPlayer; private void Start() { mediaPlayer = GetComponent(); } private MediaPlayer MediaPlayer { get { if(mediaPlayer == null) { mediaPlayer = GetComponent(); } return mediaPlayer; } } public void Play() { MediaPlayer.Play(); } public void Stop() { MediaPlayer.Stop(); } public void Pause() { MediaPlayer.Pause(); } public void SetUrl(string url) { MediaPlayer.MediaPath = new MediaPath(url, MediaPathType.AbsolutePathOrURL); } public string GetUrl() { return MediaPlayer.MediaPath.Path; } public void SetVolue( float volume) { MediaPlayer.AudioVolume = volume; } public void SetSeek(float value) { long targetTimeMs = (long)(value * 1000f); MediaPlayer.Control.Seek(targetTimeMs); } public float GetMaxTimer() { // TimeRange timelineRange = GetTimelineRange(); // if(timelineRange.startTime==-1&&timelineRange.duration ==0) // return 0.0f; //return(float.Parse( Helper.GetTimeString(timelineRange.duration, false))); return (float)MediaPlayer.Info.GetDuration(); } public float GetNowTimer() { //TimeRange timelineRange = GetTimelineRange(); //if (timelineRange.startTime == -1 && timelineRange.duration == 0) // return 0.0f; //return (float.Parse( Helper.GetTimeString((mediaPlayer.Control.GetCurrentTime() - timelineRange.startTime), false))); return (float)MediaPlayer.Control.GetCurrentTime(); } public float GetVolue() { return MediaPlayer.AudioVolume; } public bool IsPlaying() { if(MediaPlayer.Control == null||MediaPlayer.MediaPath.Path==null) return false; try { return MediaPlayer.Control.IsPlaying(); } catch (System.Exception e) { Debug.LogError(e.Message); return false; } } public float GetVideoWidth() { return MediaPlayer.Info.GetVideoWidth(); } public float GetVideoHeight() { return mediaPlayer.Info.GetVideoHeight(); } public bool IsPaused() { return MediaPlayer.Control.IsPaused(); } public bool IsFinished() { return MediaPlayer.Control.IsFinished(); } }