123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- 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<MediaPlayer>();
- }
- private MediaPlayer MediaPlayer
- {
- get
- {
- if(mediaPlayer == null)
- {
- mediaPlayer = GetComponent<MediaPlayer>();
- }
- 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();
- }
-
-
- }
|