AVProVideoPlayer.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using RenderHeads.Media.AVProVideo;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class AVProVideoPlayer : MonoBehaviour
  6. {
  7. private MediaPlayer mediaPlayer;
  8. private void Start()
  9. {
  10. mediaPlayer = GetComponent<MediaPlayer>();
  11. }
  12. private MediaPlayer MediaPlayer
  13. {
  14. get
  15. {
  16. if(mediaPlayer == null)
  17. {
  18. mediaPlayer = GetComponent<MediaPlayer>();
  19. }
  20. return mediaPlayer;
  21. }
  22. }
  23. public void Play()
  24. {
  25. MediaPlayer.Play();
  26. }
  27. public void Stop()
  28. {
  29. MediaPlayer.Stop();
  30. }
  31. public void Pause()
  32. {
  33. MediaPlayer.Pause();
  34. }
  35. public void SetUrl(string url)
  36. {
  37. MediaPlayer.MediaPath = new MediaPath(url, MediaPathType.AbsolutePathOrURL);
  38. }
  39. public string GetUrl()
  40. {
  41. return MediaPlayer.MediaPath.Path;
  42. }
  43. public void SetVolue( float volume)
  44. {
  45. MediaPlayer.AudioVolume = volume;
  46. }
  47. public void SetSeek(float value)
  48. {
  49. long targetTimeMs = (long)(value * 1000f);
  50. MediaPlayer.Control.Seek(targetTimeMs);
  51. }
  52. public float GetMaxTimer()
  53. {
  54. // TimeRange timelineRange = GetTimelineRange();
  55. // if(timelineRange.startTime==-1&&timelineRange.duration ==0)
  56. // return 0.0f;
  57. //return(float.Parse( Helper.GetTimeString(timelineRange.duration, false)));
  58. return (float)MediaPlayer.Info.GetDuration();
  59. }
  60. public float GetNowTimer()
  61. {
  62. //TimeRange timelineRange = GetTimelineRange();
  63. //if (timelineRange.startTime == -1 && timelineRange.duration == 0)
  64. // return 0.0f;
  65. //return (float.Parse( Helper.GetTimeString((mediaPlayer.Control.GetCurrentTime() - timelineRange.startTime), false)));
  66. return (float)MediaPlayer.Control.GetCurrentTime();
  67. }
  68. public float GetVolue()
  69. {
  70. return MediaPlayer.AudioVolume;
  71. }
  72. public bool IsPlaying()
  73. {
  74. if(MediaPlayer.Control == null||MediaPlayer.MediaPath.Path==null)
  75. return false;
  76. try
  77. {
  78. return MediaPlayer.Control.IsPlaying();
  79. }
  80. catch (System.Exception e)
  81. {
  82. Debug.LogError(e.Message);
  83. return false;
  84. }
  85. }
  86. public float GetVideoWidth()
  87. {
  88. return MediaPlayer.Info.GetVideoWidth();
  89. }
  90. public float GetVideoHeight()
  91. {
  92. return mediaPlayer.Info.GetVideoHeight();
  93. }
  94. public bool IsPaused()
  95. {
  96. return MediaPlayer.Control.IsPaused();
  97. }
  98. public bool IsFinished()
  99. {
  100. return MediaPlayer.Control.IsFinished();
  101. }
  102. }